Browse Source
Merge pull request #666 from vverst/fix-2fa-email
Fix 2FA email not sending
pull/671/head
Daniel García
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
2 deletions
-
src/api/core/two_factor/email.rs
-
src/api/identity.rs
|
|
@ -55,10 +55,18 @@ fn send_email_login(data: JsonUpcase<SendEmailLoginData>, conn: DbConn) -> Empty |
|
|
|
err!("Email 2FA is disabled") |
|
|
|
} |
|
|
|
|
|
|
|
send_token(&user.uuid, &conn)?; |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
/// Generate the token, save the data for later verification and send email to user
|
|
|
|
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 mut twofactor = TwoFactor::find_by_user_and_type(user_uuid, type_, &conn)?; |
|
|
|
|
|
|
|
let generated_token = generate_token(CONFIG.email_token_size())?; |
|
|
|
|
|
|
|
let mut twofactor_data = EmailTokenData::from_json(&twofactor.data)?; |
|
|
|
twofactor_data.set_token(generated_token); |
|
|
|
twofactor.data = twofactor_data.to_json(); |
|
|
|
|
|
@ -293,13 +293,19 @@ fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> Api |
|
|
|
} |
|
|
|
|
|
|
|
Some(tf_type @ TwoFactorType::Email) => { |
|
|
|
use crate::api::core::two_factor as _tf; |
|
|
|
|
|
|
|
let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, &conn) { |
|
|
|
Some(tf) => tf, |
|
|
|
None => err!("No twofactor email registered"), |
|
|
|
}; |
|
|
|
|
|
|
|
let email_data = EmailTokenData::from_json(&twofactor.data)?; |
|
|
|
// Send email immediately if email is the only 2FA option
|
|
|
|
if providers.len() == 1 { |
|
|
|
_tf::email::send_token(&user_uuid, &conn)? |
|
|
|
} |
|
|
|
|
|
|
|
let email_data = EmailTokenData::from_json(&twofactor.data)?; |
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = json!({ |
|
|
|
"Email": email::obscure_email(&email_data.email), |
|
|
|
}) |
|
|
|