|
|
@ -2,15 +2,11 @@ use actix_web::{http::header::Header, HttpRequest};
|
|
|
|
use actix_web_httpauth::headers::authorization::{Authorization, Bearer};
|
|
|
|
use actix_web_httpauth::headers::authorization::{Authorization, Bearer};
|
|
|
|
use base64::{engine::general_purpose::STANDARD_NO_PAD as base64, Engine};
|
|
|
|
use base64::{engine::general_purpose::STANDARD_NO_PAD as base64, Engine};
|
|
|
|
use captcha::Captcha;
|
|
|
|
use captcha::Captcha;
|
|
|
|
use lemmy_api_common::{
|
|
|
|
use lemmy_api_common::utils::{local_site_to_slur_regex, AUTH_COOKIE_NAME};
|
|
|
|
claims::Claims,
|
|
|
|
|
|
|
|
context::LemmyContext,
|
|
|
|
|
|
|
|
utils::{check_user_valid, local_site_to_slur_regex, AUTH_COOKIE_NAME},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use lemmy_db_schema::source::local_site::LocalSite;
|
|
|
|
use lemmy_db_schema::source::local_site::LocalSite;
|
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
|
|
use lemmy_utils::{
|
|
|
|
use lemmy_utils::{
|
|
|
|
error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult},
|
|
|
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
|
|
|
|
utils::slurs::check_slurs,
|
|
|
|
utils::slurs::check_slurs,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use std::io::Cursor;
|
|
|
|
use std::io::Cursor;
|
|
|
@ -141,20 +137,6 @@ pub(crate) fn build_totp_2fa(
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntGenerateTotp)
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntGenerateTotp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
|
|
|
|
pub async fn local_user_view_from_jwt(
|
|
|
|
|
|
|
|
jwt: &str,
|
|
|
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
|
|
|
) -> Result<LocalUserView, LemmyError> {
|
|
|
|
|
|
|
|
let local_user_id = Claims::validate(jwt, context)
|
|
|
|
|
|
|
|
.await
|
|
|
|
|
|
|
|
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
|
|
|
|
|
|
|
|
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
|
|
|
|
|
|
|
check_user_valid(&local_user_view.person)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(local_user_view)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
mod tests {
|
|
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|