1- import { Body , Controller , Get , Post , Query , Res , Session } from '@nestjs/common' ;
1+ import { Body , Controller , Get , Post , Query } from '@nestjs/common' ;
22import { LoginDto } from './dto/login.dto' ;
33import { LoginService } from './login.service' ;
44import { 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}
0 commit comments