2 use actix_web::web::Data;
4 use lemmy_api_common::{
6 check_registration_application,
7 person::{Login, LoginResponse},
9 use lemmy_db_schema::source::site::Site;
10 use lemmy_db_views::local_user_view::LocalUserView;
11 use lemmy_utils::{claims::Claims, ConnectionId, LemmyError};
12 use lemmy_websocket::LemmyContext;
14 #[async_trait::async_trait(?Send)]
15 impl Perform for Login {
16 type Response = LoginResponse;
18 #[tracing::instrument(skip(context, _websocket_id))]
21 context: &Data<LemmyContext>,
22 _websocket_id: Option<ConnectionId>,
23 ) -> Result<LoginResponse, LemmyError> {
24 let data: &Login = self;
26 // Fetch that username / email
27 let username_or_email = data.username_or_email.clone();
28 let local_user_view = blocking(context.pool(), move |conn| {
29 LocalUserView::find_by_email_or_name(conn, &username_or_email)
32 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
34 // Verify the password
35 let valid: bool = verify(
37 &local_user_view.local_user.password_encrypted,
41 return Err(LemmyError::from_message("password_incorrect"));
44 let site = blocking(context.pool(), Site::read_local_site).await??;
45 if site.require_email_verification && !local_user_view.local_user.email_verified {
46 return Err(LemmyError::from_message("email_not_verified"));
49 check_registration_application(&site, &local_user_view, context.pool()).await?;
55 local_user_view.local_user.id.0,
56 &context.secret().jwt_secret,
57 &context.settings().hostname,
61 verify_email_sent: false,
62 registration_created: false,