mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	server: use the new into_tuple from sea_orm
This commit is contained in:
		
							parent
							
								
									a1ad8dd324
								
							
						
					
					
						commit
						c1662f0218
					
				@ -8,7 +8,7 @@ use super::{
 | 
			
		||||
};
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
use lldap_auth::opaque;
 | 
			
		||||
use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, FromQueryResult, QuerySelect};
 | 
			
		||||
use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, QuerySelect};
 | 
			
		||||
use secstr::SecUtf8;
 | 
			
		||||
use tracing::{debug, instrument};
 | 
			
		||||
 | 
			
		||||
@ -50,18 +50,14 @@ impl SqlBackendHandler {
 | 
			
		||||
 | 
			
		||||
    #[instrument(skip_all, level = "debug", err)]
 | 
			
		||||
    async fn get_password_file_for_user(&self, user_id: UserId) -> Result<Option<Vec<u8>>> {
 | 
			
		||||
        #[derive(FromQueryResult)]
 | 
			
		||||
        struct OnlyPasswordHash {
 | 
			
		||||
            password_hash: Option<Vec<u8>>,
 | 
			
		||||
        }
 | 
			
		||||
        // Fetch the previously registered password file from the DB.
 | 
			
		||||
        Ok(model::User::find_by_id(user_id)
 | 
			
		||||
            .select_only()
 | 
			
		||||
            .column(UserColumn::PasswordHash)
 | 
			
		||||
            .into_model::<OnlyPasswordHash>()
 | 
			
		||||
            .into_tuple::<(Option<Vec<u8>>,)>()
 | 
			
		||||
            .one(&self.sql_pool)
 | 
			
		||||
            .await?
 | 
			
		||||
            .and_then(|u| u.password_hash))
 | 
			
		||||
            .and_then(|u| u.0))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,7 @@ use crate::domain::{
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
use sea_orm::{
 | 
			
		||||
    sea_query::{Cond, Expr},
 | 
			
		||||
    ActiveModelTrait, ColumnTrait, EntityTrait, FromQueryResult, IntoActiveModel, QueryFilter,
 | 
			
		||||
    QuerySelect,
 | 
			
		||||
    ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect,
 | 
			
		||||
};
 | 
			
		||||
use std::collections::HashSet;
 | 
			
		||||
use tracing::{debug, instrument};
 | 
			
		||||
@ -24,11 +23,6 @@ fn gen_random_string(len: usize) -> String {
 | 
			
		||||
        .collect()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(FromQueryResult)]
 | 
			
		||||
struct OnlyJwtHash {
 | 
			
		||||
    jwt_hash: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[async_trait]
 | 
			
		||||
impl TcpBackendHandler for SqlBackendHandler {
 | 
			
		||||
    #[instrument(skip_all, level = "debug")]
 | 
			
		||||
@ -37,11 +31,11 @@ impl TcpBackendHandler for SqlBackendHandler {
 | 
			
		||||
            .select_only()
 | 
			
		||||
            .column(JwtStorageColumn::JwtHash)
 | 
			
		||||
            .filter(JwtStorageColumn::Blacklisted.eq(true))
 | 
			
		||||
            .into_model::<OnlyJwtHash>()
 | 
			
		||||
            .into_tuple::<(i64,)>()
 | 
			
		||||
            .all(&self.sql_pool)
 | 
			
		||||
            .await?
 | 
			
		||||
            .into_iter()
 | 
			
		||||
            .map(|m| m.jwt_hash as u64)
 | 
			
		||||
            .map(|m| m.0 as u64)
 | 
			
		||||
            .collect::<HashSet<u64>>())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -91,11 +85,11 @@ impl TcpBackendHandler for SqlBackendHandler {
 | 
			
		||||
                    .add(JwtStorageColumn::UserId.eq(user))
 | 
			
		||||
                    .add(JwtStorageColumn::Blacklisted.eq(false)),
 | 
			
		||||
            )
 | 
			
		||||
            .into_model::<OnlyJwtHash>()
 | 
			
		||||
            .into_tuple::<(i64,)>()
 | 
			
		||||
            .all(&self.sql_pool)
 | 
			
		||||
            .await?
 | 
			
		||||
            .into_iter()
 | 
			
		||||
            .map(|t| t.jwt_hash as u64)
 | 
			
		||||
            .map(|t| t.0 as u64)
 | 
			
		||||
            .collect::<HashSet<u64>>();
 | 
			
		||||
        model::JwtStorage::update_many()
 | 
			
		||||
            .col_expr(JwtStorageColumn::Blacklisted, Expr::value(true))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user