Skip to content

Commit 573f97c

Browse files
committed
feat: 修改验证码
1 parent a46c72b commit 573f97c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/api/login/dto/login.dto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export class LoginDto {
1212

1313
@IsNotEmpty({ message: '验证码不能空' })
1414
readonly captcha!: string;
15+
16+
@IsNotEmpty({ message: '验证码不能为空' })
17+
readonly codeText!: string;
1518
}

src/api/login/login.controller.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Post, Query, Res, Session } from '@nestjs/common';
1+
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
22
import { LoginDto } from './dto/login.dto';
33
import { LoginService } from './login.service';
44
import { LoginVo } from './vo/login.vo';
@@ -10,9 +10,8 @@ export class LoginController {
1010
constructor(private readonly loginService: LoginService) {}
1111

1212
@Post('login')
13-
async loginApi(@Body() req: LoginDto, @Session() session: any): Promise<LoginVo> {
14-
const storedCaptcha = session.code;
15-
if (req.captcha && storedCaptcha && req.captcha.toLowerCase() === storedCaptcha.toLowerCase()) {
13+
async loginApi(@Body() req: LoginDto): Promise<LoginVo> {
14+
if (req.captcha.toLowerCase() === req.codeText.toLowerCase()) {
1615
return await this.loginService.loginApi(req);
1716
} else {
1817
throw new HttpException('验证码错误', HttpStatus.OK);
@@ -25,16 +24,17 @@ export class LoginController {
2524
}
2625

2726
@Get('captcha')
28-
getCaptchaApi(@Res() res: any, @Session() session: any) {
27+
getCaptchaApi() {
2928
const captcha = svgCaptcha.create({
3029
size: 4, //生成几个验证码
3130
fontSize: 50, //文字大小
3231
width: 100, //宽度
3332
height: 34, //高度
3433
background: '#fff', //背景颜色
3534
});
36-
session['code'] = captcha['text']; //存储验证码记录到session
37-
res.set('Content-Type', 'image/svg+xml');
38-
res.send(captcha['data']);
35+
// session['code'] = captcha['text']; //存储验证码记录到session
36+
// res.set('Content-Type', 'image/svg+xml');
37+
// res.send(captcha['data']);
38+
return captcha;
3939
}
4040
}

src/api/login/login.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class LoginService {
6464
return await this.generateToken(redisDataObj.userInfo);
6565
} else {
6666
throw new HttpException(
67-
JSON.stringify({ code: 10024, message: '你还没登录,请先登录' }),
67+
JSON.stringify({ code: 10025, message: '你还没登录,请先登录' }),
6868
HttpStatus.OK
6969
);
7070
}

0 commit comments

Comments
 (0)