user
This commit is contained in:
parent
4193b37b6b
commit
95c5592170
4 changed files with 54 additions and 1 deletions
|
@ -49,3 +49,37 @@ pub async fn login_route(login: Json<LoginData>) -> FallibleApiResponse {
|
|||
"token": ses.token
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PasswdData {
|
||||
pub old: String,
|
||||
pub new: String,
|
||||
}
|
||||
|
||||
#[post("/passwd", data = "<passwd>")]
|
||||
pub async fn passwd_route(passwd: Json<PasswdData>, mut u: User) -> FallibleApiResponse {
|
||||
u.passwd(&passwd.old, &passwd.new)
|
||||
.await
|
||||
.map_err(|_| api_error("Password change failed"))?;
|
||||
|
||||
Ok(json!({
|
||||
"ok": 1
|
||||
}))
|
||||
}
|
||||
|
||||
#[post("/userCreate", data = "<user>")]
|
||||
pub async fn user_create_route(user: Json<LoginData>, u: User) -> FallibleApiResponse {
|
||||
if !u.is_admin() {
|
||||
return Err(api_error("Forbidden"));
|
||||
}
|
||||
|
||||
let new_user = User::create(
|
||||
&user.username,
|
||||
&user.password,
|
||||
crate::library::user::UserRole::Regular,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(json!({"created": new_user._id}))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue