]> Untitled Git - lemmy.git/blobdiff - crates/api/src/local_user/get_captcha.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / api / src / local_user / get_captcha.rs
index b63550362a6b58461f18d5adbfbcf9a24a279dab..1d2511f56f9b79a55648e4b88f00438ee8a11d09 100644 (file)
@@ -2,8 +2,11 @@ use crate::{captcha_as_wav_base64, Perform};
 use actix_web::web::Data;
 use captcha::{gen, Difficulty};
 use chrono::Duration;
-use lemmy_api_common::person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse};
-use lemmy_db_schema::utils::naive_now;
+use lemmy_api_common::{
+  person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
+  utils::blocking,
+};
+use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
 use lemmy_utils::{error::LemmyError, ConnectionId};
 use lemmy_websocket::{messages::CaptchaItem, LemmyContext};
 
@@ -17,13 +20,13 @@ impl Perform for GetCaptcha {
     context: &Data<LemmyContext>,
     _websocket_id: Option<ConnectionId>,
   ) -> Result<Self::Response, LemmyError> {
-    let captcha_settings = &context.settings().captcha;
+    let local_site = blocking(context.pool(), LocalSite::read).await??;
 
-    if !captcha_settings.enabled {
+    if !local_site.captcha_enabled {
       return Ok(GetCaptchaResponse { ok: None });
     }
 
-    let captcha = gen(match captcha_settings.difficulty.as_str() {
+    let captcha = gen(match local_site.captcha_difficulty.as_str() {
       "easy" => Difficulty::Easy,
       "hard" => Difficulty::Hard,
       _ => Difficulty::Medium,