1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Can reset password

This commit is contained in:
2020-07-13 15:33:18 +02:00
parent 8a2f482bbd
commit ded88474d5
3 changed files with 30 additions and 0 deletions

View File

@ -128,6 +128,15 @@ pub fn generate_password_reset_token(user_id: &UserID) -> ResultBoxError<String>
Ok(token)
}
/// Remove password reset token for a given user
pub fn destroy_password_reset_token_for_user(user_id: &UserID) -> ResultBoxError {
database::UpdateInfo::new(USERS_TABLE)
.cond_user_id("ID", user_id)
.set_str("password_reset_token", "")
.set_u64("password_reset_token_time_create", 0)
.exec()
}
/// Get the ID of a user based on a password reset token
pub fn get_user_id_from_password_reset_token(token: &str) -> ResultBoxError<UserID> {
database::QueryInfo::new(USERS_TABLE)
@ -137,6 +146,14 @@ pub fn get_user_id_from_password_reset_token(token: &str) -> ResultBoxError<User
.query_row(|r| r.get_user_id("ID"))
}
/// Change the password of a user
pub fn change_password(user_id: &UserID, new_password: &String) -> ResultBoxError {
database::UpdateInfo::new(USERS_TABLE)
.cond_user_id("ID", user_id)
.set_str("password", &crypt_pass(new_password)?)
.exec()
}
/// Check out whether a virtual directory is taken by a user or not
pub fn check_user_directory_availability(dir: &str, user_id: Option<UserID>) -> ResultBoxError<bool> {
let found_user = user_helper::find_user_by_virtual_directory(dir);