2 use actix_web::web::Data;
4 use lemmy_api_common::{
6 person::{Login, LoginResponse},
7 utils::{check_registration_application, check_user_valid},
9 use lemmy_db_views::structs::{LocalUserView, SiteView};
12 error::{LemmyError, LemmyErrorExt, LemmyErrorType},
13 utils::validation::check_totp_2fa_valid,
16 #[async_trait::async_trait(?Send)]
17 impl Perform for Login {
18 type Response = LoginResponse;
20 #[tracing::instrument(skip(context))]
21 async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
22 let data: &Login = self;
24 let site_view = SiteView::read_local(&mut context.pool()).await?;
26 // Fetch that username / email
27 let username_or_email = data.username_or_email.clone();
29 LocalUserView::find_by_email_or_name(&mut context.pool(), &username_or_email)
31 .with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
33 // Verify the password
34 let valid: bool = verify(
36 &local_user_view.local_user.password_encrypted,
40 return Err(LemmyErrorType::IncorrectLogin)?;
43 local_user_view.person.banned,
44 local_user_view.person.ban_expires,
45 local_user_view.person.deleted,
48 // Check if the user's email is verified if email verification is turned on
49 // However, skip checking verification if the user is an admin
50 if !local_user_view.person.admin
51 && site_view.local_site.require_email_verification
52 && !local_user_view.local_user.email_verified
54 return Err(LemmyErrorType::EmailNotVerified)?;
57 check_registration_application(&local_user_view, &site_view.local_site, &mut context.pool())
62 &local_user_view.local_user.totp_2fa_secret,
65 &local_user_view.person.name,
72 local_user_view.local_user.id.0,
73 &context.secret().jwt_secret,
74 &context.settings().hostname,
78 verify_email_sent: false,
79 registration_created: false,