Can request password reset
This commit is contained in:
@ -7,6 +7,7 @@ use std::time::Duration;
|
||||
pub enum RatedAction {
|
||||
CreateAccount,
|
||||
CheckResetPasswordTokenFailed,
|
||||
RequestNewPasswordResetLink,
|
||||
}
|
||||
|
||||
impl RatedAction {
|
||||
@ -14,6 +15,7 @@ impl RatedAction {
|
||||
match self {
|
||||
RatedAction::CreateAccount => "create-account",
|
||||
RatedAction::CheckResetPasswordTokenFailed => "check-reset-password-token",
|
||||
RatedAction::RequestNewPasswordResetLink => "req-pwd-reset-lnk",
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,14 +23,12 @@ impl RatedAction {
|
||||
match self {
|
||||
RatedAction::CreateAccount => 5,
|
||||
RatedAction::CheckResetPasswordTokenFailed => 100,
|
||||
RatedAction::RequestNewPasswordResetLink => 5,
|
||||
}
|
||||
}
|
||||
|
||||
fn keep_seconds(&self) -> u64 {
|
||||
match self {
|
||||
RatedAction::CreateAccount => 3600,
|
||||
RatedAction::CheckResetPasswordTokenFailed => 3600,
|
||||
}
|
||||
3600
|
||||
}
|
||||
|
||||
fn key(&self, ip: IpAddr) -> String {
|
||||
|
@ -12,12 +12,21 @@ use bcrypt::DEFAULT_COST;
|
||||
use diesel::prelude::*;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
/// Get the information of the user, by its id
|
||||
/// Get the information of a 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
|
||||
/// Get the information of a user, by its mail
|
||||
pub async fn get_by_mail(mail: &str) -> anyhow::Result<User> {
|
||||
db_connection::execute(|conn| {
|
||||
Ok(users::table
|
||||
.filter(users::dsl::email.eq(mail))
|
||||
.first(conn)?)
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the information of a user, by its password reset token
|
||||
pub async fn get_by_pwd_reset_token(token: &str) -> anyhow::Result<User> {
|
||||
if token.is_empty() {
|
||||
return Err(anyhow::Error::from(std::io::Error::new(
|
||||
|
Reference in New Issue
Block a user