mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can check the validity of a password reset token
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use crate::constants::{PASSWORD_RESET_TOKEN_LENGTH, PASSWORD_RESET_TOKEN_LIFETIME};
|
||||
use crate::constants::database_tables_names::{USER_ACCESS_TOKENS_TABLE, USERS_TABLE};
|
||||
use crate::data::api_client::APIClient;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
@ -116,7 +117,7 @@ pub fn destroy_all_user_tokens(id: &UserID) -> ResultBoxError {
|
||||
|
||||
/// Generate a new password reset token
|
||||
pub fn generate_password_reset_token(user_id: &UserID) -> ResultBoxError<String> {
|
||||
let token = rand_str(255);
|
||||
let token = rand_str(PASSWORD_RESET_TOKEN_LENGTH);
|
||||
|
||||
database::UpdateInfo::new(USERS_TABLE)
|
||||
.cond_user_id("ID", user_id)
|
||||
@ -127,6 +128,15 @@ pub fn generate_password_reset_token(user_id: &UserID) -> ResultBoxError<String>
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
.cond("password_reset_token", token)
|
||||
.set_custom_where("password_reset_token_time_create > ?")
|
||||
.add_custom_where_argument_u64(time() - PASSWORD_RESET_TOKEN_LIFETIME)
|
||||
.query_row(|r| r.get_user_id("ID"))
|
||||
}
|
||||
|
||||
/// 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);
|
||||
|
Reference in New Issue
Block a user