perf: 支持短信验证码登录

This commit is contained in:
xiaojunnuo
2024-11-28 17:36:45 +08:00
parent 5a20242111
commit 387bcc5fa4
28 changed files with 950 additions and 309 deletions
@@ -1,7 +1,7 @@
import { Body, Controller, Inject, Post, Provide, ALL } from '@midwayjs/core';
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { LoginService } from '../../modules/login/service/login-service.js';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { BaseController, Constants, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
import { CodeService } from '../../modules/basic/service/code-service.js';
/**
*/
@@ -10,13 +10,23 @@ import { Constants } from '@certd/lib-server';
export class LoginController extends BaseController {
@Inject()
loginService: LoginService;
@Inject()
codeService: CodeService;
@Inject()
sysSettingsService: SysSettingsService;
@Post('/login', { summary: Constants.per.guest })
public async login(
@Body(ALL)
user: any
) {
const token = await this.loginService.login(user);
const settings = await this.sysSettingsService.getSetting<SysPublicSettings>(SysPublicSettings);
if (settings.passwordLoginEnabled === false) {
throw new Error('当前站点已禁止密码登录');
}
const token = await this.loginService.loginByPassword(user);
this.ctx.cookies.set('token', token.token, {
maxAge: 1000 * token.expire,
});
@@ -29,7 +39,17 @@ export class LoginController extends BaseController {
@Body(ALL)
body: any
) {
const token = await this.loginService.loginBySmsCode(body);
const settings = await this.sysSettingsService.getSetting<SysPublicSettings>(SysPublicSettings);
if (settings.smsLoginEnabled !== true) {
throw new Error('当前站点禁止短信验证码登录');
}
const token = await this.loginService.loginBySmsCode({
phoneCode: body.phoneCode,
mobile: body.mobile,
smsCode: body.smsCode,
randomStr: body.randomStr,
});
this.ctx.cookies.set('token', token.token, {
maxAge: 1000 * token.expire,