Refact, verification login with secret (#6943)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
48102e9c53
commit
a42df9a27b
@ -121,6 +121,7 @@ class LoginRequest {
|
|||||||
String? type;
|
String? type;
|
||||||
String? verificationCode;
|
String? verificationCode;
|
||||||
String? tfaCode;
|
String? tfaCode;
|
||||||
|
String? secret;
|
||||||
|
|
||||||
LoginRequest(
|
LoginRequest(
|
||||||
{this.username,
|
{this.username,
|
||||||
@ -130,7 +131,8 @@ class LoginRequest {
|
|||||||
this.autoLogin,
|
this.autoLogin,
|
||||||
this.type,
|
this.type,
|
||||||
this.verificationCode,
|
this.verificationCode,
|
||||||
this.tfaCode});
|
this.tfaCode,
|
||||||
|
this.secret});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
@ -144,6 +146,7 @@ class LoginRequest {
|
|||||||
data['verificationCode'] = verificationCode;
|
data['verificationCode'] = verificationCode;
|
||||||
}
|
}
|
||||||
if (tfaCode != null) data['tfaCode'] = tfaCode;
|
if (tfaCode != null) data['tfaCode'] = tfaCode;
|
||||||
|
if (secret != null) data['secret'] = secret;
|
||||||
|
|
||||||
Map<String, dynamic> deviceInfo = {};
|
Map<String, dynamic> deviceInfo = {};
|
||||||
try {
|
try {
|
||||||
@ -160,14 +163,17 @@ class LoginResponse {
|
|||||||
String? access_token;
|
String? access_token;
|
||||||
String? type;
|
String? type;
|
||||||
String? tfa_type;
|
String? tfa_type;
|
||||||
|
String? secret;
|
||||||
UserPayload? user;
|
UserPayload? user;
|
||||||
|
|
||||||
LoginResponse({this.access_token, this.type, this.tfa_type, this.user});
|
LoginResponse(
|
||||||
|
{this.access_token, this.type, this.tfa_type, this.secret, this.user});
|
||||||
|
|
||||||
LoginResponse.fromJson(Map<String, dynamic> json) {
|
LoginResponse.fromJson(Map<String, dynamic> json) {
|
||||||
access_token = json['access_token'];
|
access_token = json['access_token'];
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
tfa_type = json['tfa_type'];
|
tfa_type = json['tfa_type'];
|
||||||
|
secret = json['secret'];
|
||||||
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
|
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,8 +390,7 @@ class LoginWidgetUserPass extends StatelessWidget {
|
|||||||
|
|
||||||
const kAuthReqTypeOidc = 'oidc/';
|
const kAuthReqTypeOidc = 'oidc/';
|
||||||
|
|
||||||
/// common login dialog for desktop
|
// call this directly
|
||||||
/// call this directly
|
|
||||||
Future<bool?> loginDialog() async {
|
Future<bool?> loginDialog() async {
|
||||||
var username =
|
var username =
|
||||||
TextEditingController(text: UserModel.getLocalUserInfo()?['name'] ?? '');
|
TextEditingController(text: UserModel.getLocalUserInfo()?['name'] ?? '');
|
||||||
@ -457,11 +456,12 @@ Future<bool?> loginDialog() async {
|
|||||||
if (isEmailVerification != null) {
|
if (isEmailVerification != null) {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
if (close != null) close(false);
|
if (close != null) close(false);
|
||||||
verificationCodeDialog(resp.user, isEmailVerification);
|
verificationCodeDialog(
|
||||||
|
resp.user, resp.secret, isEmailVerification);
|
||||||
} else {
|
} else {
|
||||||
setState(() => isInProgress = false);
|
setState(() => isInProgress = false);
|
||||||
final res =
|
final res = await verificationCodeDialog(
|
||||||
await verificationCodeDialog(resp.user, isEmailVerification);
|
resp.user, resp.secret, isEmailVerification);
|
||||||
if (res == true) {
|
if (res == true) {
|
||||||
if (close != null) close(false);
|
if (close != null) close(false);
|
||||||
return;
|
return;
|
||||||
@ -611,7 +611,7 @@ Future<bool?> loginDialog() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool?> verificationCodeDialog(
|
Future<bool?> verificationCodeDialog(
|
||||||
UserPayload? user, bool isEmailVerification) async {
|
UserPayload? user, String? secret, bool isEmailVerification) async {
|
||||||
var autoLogin = true;
|
var autoLogin = true;
|
||||||
var isInProgress = false;
|
var isInProgress = false;
|
||||||
String? errorText;
|
String? errorText;
|
||||||
@ -626,6 +626,7 @@ Future<bool?> verificationCodeDialog(
|
|||||||
final resp = await gFFI.userModel.login(LoginRequest(
|
final resp = await gFFI.userModel.login(LoginRequest(
|
||||||
verificationCode: code.text,
|
verificationCode: code.text,
|
||||||
tfaCode: isEmailVerification ? null : code.text,
|
tfaCode: isEmailVerification ? null : code.text,
|
||||||
|
secret: secret,
|
||||||
username: user?.name,
|
username: user?.name,
|
||||||
id: await bind.mainGetMyId(),
|
id: await bind.mainGetMyId(),
|
||||||
uuid: await bind.mainGetUuid(),
|
uuid: await bind.mainGetUuid(),
|
||||||
|
@ -97,6 +97,8 @@ pub struct AuthBody {
|
|||||||
pub r#type: String,
|
pub r#type: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub tfa_type: String,
|
pub tfa_type: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub secret: String,
|
||||||
pub user: UserPayload,
|
pub user: UserPayload,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,9 +1242,10 @@ function login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function on_2fa_check(last_msg) {
|
function on_2fa_check(last_msg) {
|
||||||
var isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
|
const isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
|
||||||
|
const secret = last_msg.secret;
|
||||||
|
const emailHint = last_msg.user.email;
|
||||||
|
|
||||||
var emailHint = last_msg.user.email;
|
|
||||||
msgbox("custom-2fa-verification-code", translate('Verification code'), <div .form .set-password>
|
msgbox("custom-2fa-verification-code", translate('Verification code'), <div .form .set-password>
|
||||||
{ isEmailCheck && <div><span>{translate('Email')}:</span><span>{emailHint}</span></div> }
|
{ 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><span>{translate(isEmailCheck ? 'Verification code' : '2FA code')}:</span><input|text name="verification_code" .outline-focus /></div>
|
||||||
@ -1260,7 +1261,16 @@ function on_2fa_check(last_msg) {
|
|||||||
}
|
}
|
||||||
abLoading = true;
|
abLoading = true;
|
||||||
var url = handler.get_api_server();
|
var url = handler.get_api_server();
|
||||||
const loginData = {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', verificationCode: code, tfaCode: isEmailCheck ? '' : 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,
|
||||||
|
secret: secret,
|
||||||
|
deviceInfo: getDeviceInfo()
|
||||||
|
};
|
||||||
httpRequest(url + "/api/login", #post, loginData,
|
httpRequest(url + "/api/login", #post, loginData,
|
||||||
function(data) {
|
function(data) {
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user