feat: 解除锁屏api
This commit is contained in:
parent
fab8618bb2
commit
24309f47d2
|
@ -12,6 +12,8 @@ import { LoginDto, RegisterDto } from './dto/auth.dto';
|
||||||
import { LocalGuard } from './guards/local.guard';
|
import { LocalGuard } from './guards/local.guard';
|
||||||
import { LoginToken } from './models/auth.model';
|
import { LoginToken } from './models/auth.model';
|
||||||
import { CaptchaService } from './services/captcha.service';
|
import { CaptchaService } from './services/captcha.service';
|
||||||
|
import { AuthUser } from './decorators/auth-user.decorator';
|
||||||
|
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator';
|
||||||
|
|
||||||
@ApiTags('Auth - 认证模块')
|
@ApiTags('Auth - 认证模块')
|
||||||
@UseGuards(LocalGuard)
|
@UseGuards(LocalGuard)
|
||||||
|
@ -37,6 +39,15 @@ export class AuthController {
|
||||||
return { token };
|
return { token };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('unlock')
|
||||||
|
@ApiSecurityAuth()
|
||||||
|
@ApiOperation({ summary: '屏幕解锁,使用密码和token' })
|
||||||
|
@ApiResult({ type: LoginToken })
|
||||||
|
async unlock(@Body() dto: LoginDto, @AuthUser() user: IAuthUser): Promise<Boolean> {
|
||||||
|
await this.authService.unlock(user.uid, dto.password);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Post('register')
|
@Post('register')
|
||||||
@ApiOperation({ summary: '注册' })
|
@ApiOperation({ summary: '注册' })
|
||||||
async register(@Body() dto: RegisterDto): Promise<void> {
|
async register(@Body() dto: RegisterDto): Promise<void> {
|
||||||
|
|
|
@ -80,6 +80,19 @@ export class AuthService {
|
||||||
return token.accessToken;
|
return token.accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解锁屏幕
|
||||||
|
* 返回null则账号密码有误,不存在该用户
|
||||||
|
*/
|
||||||
|
async unlock(uid: number, password: string): Promise<void> {
|
||||||
|
const user = await this.userService.findUserById(uid);
|
||||||
|
if (isEmpty(user)) throw new BusinessException(ErrorEnum.INVALID_USERNAME_PASSWORD);
|
||||||
|
|
||||||
|
const comparePassword = md5(`${password}${user.psalt}`);
|
||||||
|
if (user.password !== comparePassword)
|
||||||
|
throw new BusinessException(ErrorEnum.INVALID_USERNAME_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 效验账号密码
|
* 效验账号密码
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
import { IsString, Matches, MaxLength, MinLength } from 'class-validator';
|
import { IsOptional, IsString, Matches, MaxLength, MinLength } from 'class-validator';
|
||||||
|
|
||||||
export class LoginDto {
|
export class LoginDto {
|
||||||
@ApiProperty({ description: '手机号/邮箱' })
|
@ApiProperty({ description: '手机号/邮箱' })
|
||||||
@IsString()
|
@IsOptional()
|
||||||
@MinLength(4)
|
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '密码', example: 'a123456' })
|
@ApiProperty({ description: '密码', example: 'a123456' })
|
||||||
|
@ -15,11 +14,11 @@ export class LoginDto {
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '验证码标识' })
|
@ApiProperty({ description: '验证码标识' })
|
||||||
@IsString()
|
@IsOptional()
|
||||||
captchaId: string;
|
captchaId: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '用户输入的验证码' })
|
@ApiProperty({ description: '用户输入的验证码' })
|
||||||
@IsString()
|
@IsOptional()
|
||||||
@MinLength(4)
|
@MinLength(4)
|
||||||
@MaxLength(4)
|
@MaxLength(4)
|
||||||
verifyCode: string;
|
verifyCode: string;
|
||||||
|
|
Loading…
Reference in New Issue