pub async fn login(login: LoginDTO, db: PostgresDbConn) -> ResponseWithStatus {
    db.run(|conn| {
        if let Some(result) = User::login(login, &conn) {
            ResponseWithStatus {
                status_code: Status::Ok.code,
                response: Response {
                    message: String::from(constants::MESSAGE_LOGIN_SUCCESS),
                    data: serde_json::to_value(json!({
                        "token": auth::generate_token(result),
                        "type": "Bearer"
                    })).unwrap(),
                },
            }
        } else {
            ResponseWithStatus::with(Status::BadRequest.code, constants::MESSAGE_LOGIN_FAILED)
        }
    }).await
}
/// Attempts to login the user with the specified login information.
/// If successful, returns that user's authentication token in the body of the response.
/// If unsuccessful, returns a failed response informing the user.
Attempts to login the user with the specified login information.
If successful, returns that user's authentication token in the body of the response.
If unsuccessful, returns a failed response informing the user.
Attempts to login the user with the specified login information . If successful returns that user ' s authentication token in the body of the response . If unsuccessful returns a failed response informing the user .
pub async fn login(login: LoginDTO, db: PostgresDbConn) -> ResponseWithStatus {
    db.run(|conn| {
        if let Some(result) = User::login(login, &conn) {
            ResponseWithStatus {
                status_code: Status::Ok.code,
                response: Response {
                    message: String::from(constants::MESSAGE_LOGIN_SUCCESS),
                    data: serde_json::to_value(json!({
                        "token": auth::generate_token(result),
                        "type": "Bearer"
                    })).unwrap(),
                },
            }
        } else {
            ResponseWithStatus::with(Status::BadRequest.code, constants::MESSAGE_LOGIN_FAILED)
        }
    }).await
}
pub async fn login ( login : LoginDTO , db : PostgresDbConn ) -> ResponseWithStatus { db . run ( | conn | { if let Some ( result ) = User :: login ( login , & conn ) { ResponseWithStatus { status_code : Status :: Ok . code , response : Response { message : String :: from ( constants :: MESSAGE_LOGIN_SUCCESS ) , data : serde_json :: to_value ( json ! ( { " " auth generate_token ( result ) " " " " } ) ) . unwrap ( ) , } , } } else { ResponseWithStatus :: with ( Status :: BadRequest . code , constants :: MESSAGE_LOGIN_FAILED ) } } ) . await }
Attempts to login the user with the specified login information.
Attempts to login the user with the specified login information .
login
LoginDTO
db
PostgresDbConn
login
LoginDTO
db
PostgresDbConn