user role
This commit is contained in:
parent
e3a0d4075f
commit
74b32003d0
2 changed files with 5 additions and 4 deletions
|
@ -60,14 +60,14 @@ impl User {
|
|||
Some(u)
|
||||
}
|
||||
|
||||
pub async fn login(username: &str, password: &str) -> Option<Session> {
|
||||
pub async fn login(username: &str, password: &str) -> Option<(Session, UserRole)> {
|
||||
let u = User::find_one(doc! { "username": username }).await?;
|
||||
|
||||
if !u.verify_pw(password) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(u.session().await)
|
||||
Some((u.session().await, u.role))
|
||||
}
|
||||
|
||||
/// Change the password of a `User`
|
||||
|
|
|
@ -52,12 +52,13 @@ pub struct LoginData {
|
|||
|
||||
#[post("/login", data = "<login>")]
|
||||
pub async fn login_route(login: Json<LoginData>) -> FallibleApiResponse {
|
||||
let ses = User::login(&login.username, &login.password)
|
||||
let (ses, role) = User::login(&login.username, &login.password)
|
||||
.await
|
||||
.ok_or_else(|| api_error("Login failed"))?;
|
||||
|
||||
Ok(json!({
|
||||
"token": ses.token
|
||||
"token": ses.token,
|
||||
"role": role
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue