Better 2fa verification support (#6782)

* Better 2fa verification support

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* 2FA login verification, add request filed 'tfa_code'

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* 2fa dialog

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* msgbox, title

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* Feat, oidc login, 2fa

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-01-03 16:43:39 +08:00
committed by GitHub
parent 89150317e1
commit 7e3a0c4ded
43 changed files with 176 additions and 54 deletions

View File

@@ -1223,7 +1223,7 @@ function login() {
if (data.type == 'email_check') {
abLoading = false;
show_progress(-1);
on_email_check(data);
on_2fa_check(data);
return;
}
handler.set_local_option("access_token", data.access_token);
@@ -1241,12 +1241,14 @@ function login() {
});
}
function on_email_check(last_msg) {
function on_2fa_check(last_msg) {
var isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
var emailHint = last_msg.user.email;
msgbox("custom-email-verification-code", translate('Verification code'), <div .form .set-password>
<div><span>{translate('Email')}:</span><span>{emailHint}</span></div>
<div><span>{translate('Verification code')}:</span><input|text name="verification_code" .outline-focus /></div>
<div style="font-size:0.9em; margin-bottom:1em;">{translate('verification_tip')}</div>
msgbox("custom-2fa-verification-code", translate('Verification code'), <div .form .set-password>
{ isEmailCheck && <div><span>{translate('Email')}:</span><span>{emailHint}</span></div> }
<div><span>{translate(isEmailCheck ? 'Verification code' : '2FA code')}:</span><input|text name="verification_code" .outline-focus /></div>
<div style="font-size:0.9em; margin-bottom:1em;">{translate(isEmailCheck ? 'verification_tip' : '2fa_tip')}</div>
</div>, "",
function(res=null, show_progress) {
if (!res) return;
@@ -1258,7 +1260,8 @@ function on_email_check(last_msg) {
}
abLoading = true;
var url = handler.get_api_server();
httpRequest(url + "/api/login", #post, {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', autoLogin: true, verificationCode: code, deviceInfo: getDeviceInfo()},
const loginData = {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', verificationCode: code, tfaCode: isEmailCheck ? '' : code, deviceInfo: getDeviceInfo()};
httpRequest(url + "/api/login", #post, loginData,
function(data) {
if (data.error) {
abLoading = false;