mirror of
https://github.com/certd/certd.git
synced 2026-04-16 05:50:50 +08:00
chore: 2FA
This commit is contained in:
@@ -23,13 +23,16 @@ export class LoginController extends BaseController {
|
||||
user: any
|
||||
) {
|
||||
const token = await this.loginService.loginByPassword(user);
|
||||
this.ctx.cookies.set('token', token.token, {
|
||||
maxAge: 1000 * token.expire,
|
||||
});
|
||||
|
||||
this.writeTokenCookie(token);
|
||||
return this.ok(token);
|
||||
}
|
||||
|
||||
private writeTokenCookie(token: { expire: any; token: any }) {
|
||||
this.ctx.cookies.set("token", token.token, {
|
||||
maxAge: 1000 * token.expire
|
||||
});
|
||||
}
|
||||
|
||||
@Post('/loginBySms', { summary: Constants.per.guest })
|
||||
public async loginBySms(
|
||||
@Body(ALL)
|
||||
@@ -48,10 +51,23 @@ export class LoginController extends BaseController {
|
||||
randomStr: body.randomStr,
|
||||
});
|
||||
|
||||
this.ctx.cookies.set('token', token.token, {
|
||||
maxAge: 1000 * token.expire,
|
||||
this.writeTokenCookie(token);
|
||||
|
||||
return this.ok(token);
|
||||
}
|
||||
|
||||
@Post('/loginByTwoFactor', { summary: Constants.per.guest })
|
||||
public async loginByTwoFactor(
|
||||
@Body(ALL)
|
||||
body: any
|
||||
) {
|
||||
|
||||
const token = await this.loginService.loginByTwoFactor({
|
||||
loginCode: body.loginCode,
|
||||
verifyCode: body.verifyCode,
|
||||
});
|
||||
|
||||
this.writeTokenCookie(token);
|
||||
return this.ok(token);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,4 +58,11 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post("/authenticator/off", { summary: Constants.per.authOnly })
|
||||
async authenticatorOff() {
|
||||
const userId = this.getUserId();
|
||||
await this.twoFactorService.offAuthenticator(userId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user