Can check delete account token
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::connections::db_connection;
|
||||
use crate::constants::PASSWORD_RESET_TOKEN_DURATION;
|
||||
use crate::constants::{ACCOUNT_DELETE_TOKEN_DURATION, PASSWORD_RESET_TOKEN_DURATION};
|
||||
use crate::models::{NewUser, User, UserID};
|
||||
use crate::schema::users;
|
||||
use crate::services::mail_service;
|
||||
@ -47,6 +47,27 @@ pub async fn get_by_pwd_reset_token(token: &str) -> anyhow::Result<User> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the information of a user, by its account deletion token
|
||||
pub async fn get_by_account_delete_token(token: &str) -> anyhow::Result<User> {
|
||||
if token.is_empty() {
|
||||
return Err(anyhow::Error::from(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
"Token is empty!",
|
||||
)));
|
||||
}
|
||||
|
||||
db_connection::execute(|conn| {
|
||||
Ok(users::table
|
||||
.filter(
|
||||
users::dsl::delete_account_token.eq(token.to_string()).and(
|
||||
users::dsl::time_gen_delete_account_token
|
||||
.ge(time() as i64 - ACCOUNT_DELETE_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| {
|
||||
@ -122,7 +143,7 @@ pub async fn request_delete_account(user: &mut User) -> anyhow::Result<()> {
|
||||
format!(
|
||||
"Bonjour, \n\n\
|
||||
Vous avez demandé la suppression de votre compte GeneIT. Cette opération peut être effectuée via le lien suivant : {} \n\n\
|
||||
Ce lien est valide durant 24 heures.\n\n\
|
||||
Ce lien est valide durant 12 heures.\n\n\
|
||||
Cordialement,\n\n\
|
||||
L'équipe de GeneIT",
|
||||
AppConfig::get()
|
||||
|
Reference in New Issue
Block a user