mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 07:16:08 +08:00
修复两步验证逻辑
This commit is contained in:
parent
a285efdd85
commit
8f195b964f
|
@ -27,6 +27,7 @@ export default class AuthService {
|
||||||
password: string;
|
password: string;
|
||||||
},
|
},
|
||||||
req: any,
|
req: any,
|
||||||
|
needTwoFactor = true,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (!fs.existsSync(config.authConfigFile)) {
|
if (!fs.existsSync(config.authConfigFile)) {
|
||||||
return this.initAuthInfo();
|
return this.initAuthInfo();
|
||||||
|
@ -44,7 +45,6 @@ export default class AuthService {
|
||||||
lastip,
|
lastip,
|
||||||
lastaddr,
|
lastaddr,
|
||||||
twoFactorActived,
|
twoFactorActived,
|
||||||
isTwoFactorChecking,
|
|
||||||
} = content;
|
} = content;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -69,7 +69,7 @@ export default class AuthService {
|
||||||
|
|
||||||
const { ip, address } = await getNetIp(req);
|
const { ip, address } = await getNetIp(req);
|
||||||
if (username === cUsername && password === cPassword) {
|
if (username === cUsername && password === cPassword) {
|
||||||
if (twoFactorActived && !isTwoFactorChecking) {
|
if (twoFactorActived && needTwoFactor) {
|
||||||
this.updateAuthInfo(content, {
|
this.updateAuthInfo(content, {
|
||||||
isTwoFactorChecking: true,
|
isTwoFactorChecking: true,
|
||||||
});
|
});
|
||||||
|
@ -95,9 +95,9 @@ export default class AuthService {
|
||||||
isTwoFactorChecking: false,
|
isTwoFactorChecking: false,
|
||||||
});
|
});
|
||||||
exec(
|
exec(
|
||||||
`notify 登陆通知 你于${new Date(
|
`notify "登陆通知" "你于${new Date(
|
||||||
timestamp,
|
timestamp,
|
||||||
).toLocaleString()}在${address}登陆成功,ip地址${ip}`,
|
).toLocaleString()}在${address}登陆成功,ip地址${ip}"`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
await this.insertDb({
|
await this.insertDb({
|
||||||
|
@ -116,9 +116,9 @@ export default class AuthService {
|
||||||
lastaddr: address,
|
lastaddr: address,
|
||||||
});
|
});
|
||||||
exec(
|
exec(
|
||||||
`notify 登陆通知 你于${new Date(
|
`notify "登陆通知" "你于${new Date(
|
||||||
timestamp,
|
timestamp,
|
||||||
).toLocaleString()}在${address}登陆失败,ip地址${ip}`,
|
).toLocaleString()}在${address}登陆失败,ip地址${ip}"`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
await this.insertDb({
|
await this.insertDb({
|
||||||
|
@ -208,7 +208,7 @@ export default class AuthService {
|
||||||
|
|
||||||
public async twoFactorLogin({ username, password, code }, req) {
|
public async twoFactorLogin({ username, password, code }, req) {
|
||||||
const authInfo = this.getAuthInfo();
|
const authInfo = this.getAuthInfo();
|
||||||
const { isTwoFactorChecking, retries, twoFactorSecret } = authInfo;
|
const { isTwoFactorChecking, twoFactorSecret } = authInfo;
|
||||||
if (!isTwoFactorChecking) {
|
if (!isTwoFactorChecking) {
|
||||||
return { code: 450, message: '未知错误' };
|
return { code: 450, message: '未知错误' };
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ export default class AuthService {
|
||||||
secret: twoFactorSecret,
|
secret: twoFactorSecret,
|
||||||
});
|
});
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
return this.login({ username, password }, req);
|
return this.login({ username, password }, req, false);
|
||||||
} else {
|
} else {
|
||||||
const { ip, address } = await getNetIp(req);
|
const { ip, address } = await getNetIp(req);
|
||||||
this.updateAuthInfo(authInfo, {
|
this.updateAuthInfo(authInfo, {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user