支持多端登录

This commit is contained in:
hanhh
2021-09-24 22:24:39 +08:00
parent c8393604d1
commit c7ba304c6a
5 changed files with 86 additions and 17 deletions
+15 -3
View File
@@ -1,6 +1,6 @@
import { Service, Inject } from 'typedi';
import winston from 'winston';
import { createRandomString, getNetIp } from '../config/util';
import { createRandomString, getNetIp, getPlatform } from '../config/util';
import config from '../config';
import * as fs from 'fs';
import _ from 'lodash';
@@ -29,7 +29,7 @@ export default class AuthService {
username: string;
password: string;
},
req: any,
req: Request,
needTwoFactor = true,
): Promise<any> {
if (!fs.existsSync(config.authConfigFile)) {
@@ -49,6 +49,7 @@ export default class AuthService {
lastaddr,
twoFactorActivated,
twoFactorActived,
tokens = {},
} = content;
// patch old field
twoFactorActivated = twoFactorActivated || twoFactorActived;
@@ -94,6 +95,10 @@ export default class AuthService {
this.updateAuthInfo(content, {
token,
tokens: {
...tokens,
[req.platform]: token,
},
lastlogon: timestamp,
retries: 0,
lastip: ip,
@@ -214,7 +219,14 @@ export default class AuthService {
return isValid;
}
public async twoFactorLogin({ username, password, code }, req) {
public async twoFactorLogin(
{
username,
password,
code,
}: { username: string; password: string; code: string },
req: any,
) {
const authInfo = this.getAuthInfo();
const { isTwoFactorChecking, twoFactorSecret } = authInfo;
if (!isTwoFactorChecking) {