Can check the validity of a password reset token
This commit is contained in:
geneit_backend/src
@ -10,11 +10,25 @@ use crate::utils::string_utils::rand_str;
|
||||
use crate::utils::time_utils::time;
|
||||
use diesel::prelude::*;
|
||||
|
||||
/// Get the information of the user
|
||||
/// Get the information of the user, by its id
|
||||
pub async fn get_by_id(id: UserID) -> anyhow::Result<User> {
|
||||
db_connection::execute(|conn| Ok(users::table.filter(users::dsl::id.eq(id.0)).first(conn)?))
|
||||
}
|
||||
|
||||
/// Get the information of the user, by its password reset token
|
||||
pub async fn get_by_pwd_reset_token(token: &str) -> anyhow::Result<User> {
|
||||
db_connection::execute(|conn| {
|
||||
Ok(users::table
|
||||
.filter(
|
||||
users::dsl::reset_password_token.eq(token.to_string()).and(
|
||||
users::dsl::time_gen_reset_token
|
||||
.ge(time() as i64 - PASSWORD_RESET_TOKEN_DURATION.as_secs() as i64),
|
||||
),
|
||||
)
|
||||
.first(conn)?)
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new account
|
||||
pub async fn create_account(name: &str, email: &str) -> anyhow::Result<User> {
|
||||
db_connection::execute(|conn| {
|
||||
|
Reference in New Issue
Block a user