pub fn record_failed_login(
        user_uuid: UserUuid,
        current_failed_attempts: i32,
        conn: &PgConnection,
    ) -> BackendResult<NaiveDateTime> {
        use crate::schema::users::{
            self,
            dsl::*,
        };

        info!("record_failed_login: setting the expire time and failure count");
        let current_date = Utc::now().naive_utc();
        let delay_seconds: i64 = (current_failed_attempts * 2).into(); // Todo: come up with a better function than this
        let expire_datetime = current_date + Duration::seconds(delay_seconds);
        let new_failed_attempts = current_failed_attempts + 1; // Increment the failed count

        let target = users.filter(users::uuid.eq(user_uuid.0));
        let _ = diesel::update(target)
            .set((locked.eq(expire_datetime), failed_login_count.eq(new_failed_attempts)))
            .execute(conn)
            .map_err(handle_err::<User>)?;

        return Ok(expire_datetime);
    }
/// This method is to be called after a user has failed to log in.
/// Based on the number of current failed login attempts in a row, it will calculate the locked period.
/// It will then store the datetime of unlock, along with an incremented failure count, so that next time it will take longer.
This method is to be called after a user has failed to log in.
Based on the number of current failed login attempts in a row, it will calculate the locked period.
It will then store the datetime of unlock, along with an incremented failure count, so that next time it will take longer.
This method is to be called after a user has failed to log in . Based on the number of current failed login attempts in a row it will calculate the locked period . It will then store the datetime of unlock along with an incremented failure count so that next time it will take longer .
pub fn record_failed_login(
        user_uuid: UserUuid,
        current_failed_attempts: i32,
        conn: &PgConnection,
    ) -> BackendResult<NaiveDateTime> {
        use crate::schema::users::{
            self,
            dsl::*,
        };
        info!("record_failed_login: setting the expire time and failure count");
        let current_date = Utc::now().naive_utc();
        let delay_seconds: i64 = (current_failed_attempts * 2).into(); // Todo: come up with a better function than this
        let expire_datetime = current_date + Duration::seconds(delay_seconds);
        let new_failed_attempts = current_failed_attempts + 1; // Increment the failed count
        let target = users.filter(users::uuid.eq(user_uuid.0));
        let _ = diesel::update(target)
            .set((locked.eq(expire_datetime), failed_login_count.eq(new_failed_attempts)))
            .execute(conn)
            .map_err(handle_err::<User>)?;
        return Ok(expire_datetime);
    }
pub fn record_failed_login ( user_uuid : UserUuid , current_failed_attempts : i32 , conn : & PgConnection , ) -> BackendResult < NaiveDateTime > { use crate :: schema :: users :: { self , dsl :: * , } ; info ! ( " " ) ; let current_date = Utc :: now ( ) . naive_utc ( ) ; let delay_seconds : i64 = ( current_failed_attempts * 2 ) . into ( ) ; // Todo: come up with a better function than this let expire_datetime = current_date + Duration :: seconds ( delay_seconds ) ; let new_failed_attempts = current_failed_attempts + 1 ; // Increment the failed count let target = users . filter ( users :: uuid . eq ( user_uuid . 0 ) ) ; let _ = diesel :: update ( target ) . set ( ( locked . eq ( expire_datetime ) , failed_login_count . eq ( new_failed_attempts ) ) ) . execute ( conn ) . map_err ( handle_err :: < User > ) ? ; return Ok ( expire_datetime ) ; }
This method is to be called after a user has failed to log in.
This method is to be called after a user has failed to log in .
user_uuid
UserUuid
current_failed_attempts
i32
conn
&PgConnection
user_uuid
UserUuid
current_failed_attempts
i32
conn
&PgConnection