dependencies update
This commit is contained in:
@@ -40,43 +40,52 @@ pub struct Credentials {
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AuthnBackend for AuthBackend {
|
||||
type User = user::Model;
|
||||
type Credentials = Credentials;
|
||||
type Error = Error;
|
||||
|
||||
async fn authenticate(
|
||||
fn authenticate(
|
||||
&self,
|
||||
creds: Self::Credentials,
|
||||
) -> Result<Option<Self::User>, Self::Error> {
|
||||
let user = User::find()
|
||||
.filter(user::Column::Username.eq(&creds.username))
|
||||
.one(&self.db)
|
||||
.await?;
|
||||
) -> impl Future<Output = Result<Option<Self::User>, Self::Error>> + Send {
|
||||
let db = self.db.clone();
|
||||
async move {
|
||||
let user = User::find()
|
||||
.filter(user::Column::Username.eq(&creds.username))
|
||||
.one(&db)
|
||||
.await?;
|
||||
|
||||
if let Some(user) = user {
|
||||
let password_hash = user.password_hash.as_ref().ok_or(Error::InvalidCredentials)?;
|
||||
let parsed_hash = PasswordHash::new(password_hash)
|
||||
.map_err(|_| Error::PasswordHash)?;
|
||||
if let Some(user) = user {
|
||||
let password_hash = user.password_hash.as_ref().ok_or(Error::InvalidCredentials)?;
|
||||
let parsed_hash = PasswordHash::new(password_hash)
|
||||
.map_err(|_| Error::PasswordHash)?;
|
||||
|
||||
let is_valid = Argon2::default()
|
||||
.verify_password(creds.password.as_bytes(), &parsed_hash)
|
||||
.is_ok();
|
||||
let is_valid = Argon2::default()
|
||||
.verify_password(creds.password.as_bytes(), &parsed_hash)
|
||||
.is_ok();
|
||||
|
||||
if is_valid {
|
||||
Ok(Some(user))
|
||||
if is_valid {
|
||||
Ok(Some(user))
|
||||
} else {
|
||||
Err(Error::InvalidCredentials)
|
||||
}
|
||||
} else {
|
||||
Err(Error::InvalidCredentials)
|
||||
}
|
||||
} else {
|
||||
Err(Error::InvalidCredentials)
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_user(&self, user_id: &UserId<Self>) -> Result<Option<Self::User>, Self::Error> {
|
||||
let user = User::find_by_id(*user_id).one(&self.db).await?;
|
||||
Ok(user)
|
||||
fn get_user(
|
||||
&self,
|
||||
user_id: &UserId<Self>,
|
||||
) -> impl Future<Output = Result<Option<Self::User>, Self::Error>> + Send {
|
||||
let db = self.db.clone();
|
||||
let user_id = *user_id;
|
||||
async move {
|
||||
let user = User::find_by_id(user_id).one(&db).await?;
|
||||
Ok(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use sea_orm::*;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::distr::Alphanumeric;
|
||||
use rand::Rng;
|
||||
use crate::models::invite_link::{self, Entity as InviteLink, Model as InviteLinkModel};
|
||||
use crate::models::{user, User};
|
||||
@@ -8,7 +8,7 @@ pub struct InviteLinkService;
|
||||
|
||||
impl InviteLinkService {
|
||||
pub fn generate_token() -> String {
|
||||
rand::thread_rng()
|
||||
rand::rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(32)
|
||||
.map(char::from)
|
||||
|
||||
Reference in New Issue
Block a user