2 use actix_web::web::Data;
4 use lemmy_api_common::{
5 person::{Login, LoginResponse},
6 utils::{blocking, check_registration_application, check_user_valid},
8 use lemmy_db_schema::source::local_site::LocalSite;
9 use lemmy_db_views::structs::LocalUserView;
10 use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
11 use lemmy_websocket::LemmyContext;
13 #[async_trait::async_trait(?Send)]
14 impl Perform for Login {
15 type Response = LoginResponse;
17 #[tracing::instrument(skip(context, _websocket_id))]
20 context: &Data<LemmyContext>,
21 _websocket_id: Option<ConnectionId>,
22 ) -> Result<LoginResponse, LemmyError> {
23 let data: &Login = self;
25 let local_site = blocking(context.pool(), LocalSite::read).await??;
27 // Fetch that username / email
28 let username_or_email = data.username_or_email.clone();
29 let local_user_view = blocking(context.pool(), move |conn| {
30 LocalUserView::find_by_email_or_name(conn, &username_or_email)
33 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
35 // Verify the password
36 let valid: bool = verify(
38 &local_user_view.local_user.password_encrypted,
42 return Err(LemmyError::from_message("password_incorrect"));
45 local_user_view.person.banned,
46 local_user_view.person.ban_expires,
47 local_user_view.person.deleted,
50 if local_site.require_email_verification && !local_user_view.local_user.email_verified {
51 return Err(LemmyError::from_message("email_not_verified"));
54 check_registration_application(&local_user_view, &local_site, context.pool()).await?;
60 local_user_view.local_user.id.0,
61 &context.secret().jwt_secret,
62 &context.settings().hostname,
66 verify_email_sent: false,
67 registration_created: false,