修复重置登录错误次数和 tfa

This commit is contained in:
whyour
2025-01-02 23:50:20 +08:00
parent cecc5aeb15
commit 7d43b14f81
7 changed files with 81 additions and 59 deletions
+10 -10
View File
@@ -20,6 +20,8 @@ export default class OpenService {
tab.client_id = createRandomString(12, 12);
tab.client_secret = createRandomString(24, 24);
const doc = await this.insert(tab);
const apps = await this.find({});
await shareStore.updateApps(apps);
return { ...doc, tokens: [] };
}
@@ -54,6 +56,8 @@ export default class OpenService {
public async remove(ids: number[]) {
await AppModel.destroy({ where: { id: ids } });
const apps = await this.find({});
await shareStore.updateApps(apps);
}
public async resetSecret(id: number): Promise<App> {
@@ -136,6 +140,8 @@ export default class OpenService {
{ tokens },
{ where: { client_id, client_secret } },
);
const apps = await this.find({});
await shareStore.updateApps(apps);
return {
code: 200,
data: {
@@ -145,7 +151,7 @@ export default class OpenService {
},
};
} else {
return { code: 400, message: 'client_idclient_seret有误' };
return { code: 400, message: 'client_idclient_seret 有误' };
}
}
@@ -153,15 +159,9 @@ export default class OpenService {
value: string;
expiration: number;
}> {
let systemApp = (await AppModel.findOne({
where: { name: 'system' },
})) as App;
if (!systemApp) {
systemApp = await this.create({
name: 'system',
scopes: ['crons', 'system'],
} as App);
}
const [systemApp] = await AppModel.findOrCreate({
where: { name: 'system', scopes: ['crons', 'system'] },
});
const { data } = await this.authToken({
client_id: systemApp.client_id,
client_secret: systemApp.client_secret,
+10 -20
View File
@@ -61,13 +61,9 @@ export default class UserService {
lastip,
lastaddr,
twoFactorActivated,
twoFactorActived,
tokens = {},
platform,
} = content;
// patch old field
twoFactorActivated = twoFactorActivated || twoFactorActived;
const retriesTime = Math.pow(3, retries) * 1000;
if (retries > 2 && timestamp - lastlogon < retriesTime) {
const waitTime = Math.ceil(
@@ -215,20 +211,6 @@ export default class UserService {
return doc;
}
private async initAuthInfo() {
await fs.writeFile(
config.authConfigFile,
JSON.stringify({
username: 'admin',
password: 'admin',
}),
);
return {
code: 100,
message: '未找到认证文件,重新初始化',
};
}
public async updateUsernameAndPassword({
username,
password,
@@ -304,7 +286,6 @@ export default class UserService {
const authInfo = await this.getAuthInfo();
await this.updateAuthInfo(authInfo, {
twoFactorActivated: false,
twoFactorActived: false,
twoFactorSecret: '',
});
return true;
@@ -319,7 +300,7 @@ export default class UserService {
return (doc.info || {}) as AuthInfo;
}
private async updateAuthInfo(authInfo: any, info: any) {
private async updateAuthInfo(authInfo: AuthInfo, info: Partial<AuthInfo>) {
const result = { ...authInfo, ...info };
await shareStore.updateAuthInfo(result);
await this.updateAuthDb({
@@ -372,4 +353,13 @@ export default class UserService {
return { code: 400, message: '通知发送失败,请检查参数' };
}
}
public async resetAuthInfo(info: Partial<AuthInfo>) {
const { retries, twoFactorActivated } = info;
const authInfo = await this.getAuthInfo();
await this.updateAuthInfo(authInfo, {
retries,
twoFactorActivated,
});
}
}