|
|
@ -55,17 +55,18 @@ fn send_email_login(data: JsonUpcase<SendEmailLoginData>, conn: DbConn) -> Empty
|
|
|
|
err!("Email 2FA is disabled")
|
|
|
|
err!("Email 2FA is disabled")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let type_ = TwoFactorType::Email as i32;
|
|
|
|
send_token(&user.uuid, &conn)?;
|
|
|
|
let mut twofactor = TwoFactor::find_by_user_and_type(&user.uuid, type_, &conn)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepare_send_token(&mut twofactor, &conn)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Generate the token, save the data for later verification and send email to user
|
|
|
|
/// Generate the token, save the data for later verification and send email to user
|
|
|
|
pub fn prepare_send_token(twofactor: &mut TwoFactor, conn: &DbConn) -> EmptyResult {
|
|
|
|
pub fn send_token(user_uuid: &str, conn: &DbConn) -> EmptyResult {
|
|
|
|
|
|
|
|
let type_ = TwoFactorType::Email as i32;
|
|
|
|
|
|
|
|
let mut twofactor = TwoFactor::find_by_user_and_type(user_uuid, type_, &conn)?;
|
|
|
|
|
|
|
|
|
|
|
|
let generated_token = generate_token(CONFIG.email_token_size())?;
|
|
|
|
let generated_token = generate_token(CONFIG.email_token_size())?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut twofactor_data = EmailTokenData::from_json(&twofactor.data)?;
|
|
|
|
let mut twofactor_data = EmailTokenData::from_json(&twofactor.data)?;
|
|
|
|
twofactor_data.set_token(generated_token);
|
|
|
|
twofactor_data.set_token(generated_token);
|
|
|
|
twofactor.data = twofactor_data.to_json();
|
|
|
|
twofactor.data = twofactor_data.to_json();
|
|
|
|