Can check if password is set aith auth/info route
This commit is contained in:
		@@ -3,13 +3,28 @@
 | 
			
		||||
//! The actions of the user on his account when he is authenticated.
 | 
			
		||||
 | 
			
		||||
use crate::controllers::HttpResult;
 | 
			
		||||
use crate::models::User;
 | 
			
		||||
use crate::services::login_token_service::LoginToken;
 | 
			
		||||
use crate::services::users_service;
 | 
			
		||||
use actix_web::HttpResponse;
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize)]
 | 
			
		||||
struct UserAPI<'a> {
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
    user: &'a User,
 | 
			
		||||
    has_password: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get account information
 | 
			
		||||
pub async fn auth_info(token: LoginToken) -> HttpResult {
 | 
			
		||||
    let user = users_service::get_by_id(token.user_id).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Ok().json(user))
 | 
			
		||||
    Ok(HttpResponse::Ok().json(UserAPI {
 | 
			
		||||
        user: &user,
 | 
			
		||||
        has_password: user
 | 
			
		||||
            .password
 | 
			
		||||
            .as_deref()
 | 
			
		||||
            .map(|p| !p.is_empty())
 | 
			
		||||
            .unwrap_or_default(),
 | 
			
		||||
    }))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user