add: changInfo crypto

This commit is contained in:
손승우
2023-02-17 18:12:01 +09:00
parent 39aac2dea5
commit 053b8ed28f
2 changed files with 8 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ export class UpdateUserDto extends PartialType(CreateUserDto) {
@IsString()
@IsNotEmpty()
newPassword: string;
new_password: string;
}

View File

@@ -5,6 +5,7 @@ import { Repository } from 'typeorm';
import { UpdateUserDto } from './dto/update-user.dto';
import { User } from './entities/user.entity';
import { UserMapping } from './entities/user-mapping.entity.js';
const crypto = require('crypto');
@Injectable()
export class UserService {
@@ -27,12 +28,16 @@ export class UserService {
}
async updateUserInfo(userId: string, updateUserDto: UpdateUserDto) {
const findUser = await this.authService.checkAccess(userId, updateUserDto.password);
const hashPassword = crypto.createHash('sha512').update(String(updateUserDto.password)).digest('hex');
const findUser = await this.authService.checkAccess(userId, hashPassword);
if (!findUser) {
throw new HttpException('not exist user', HttpStatus.CONFLICT);
} else {
const newHashPassword = crypto.createHash('sha512').update(String(updateUserDto.new_password)).digest('hex');
findUser.email = String(updateUserDto.email);
findUser.password = String(updateUserDto.newPassword);
findUser.password = newHashPassword;
await this.userRepository.save(findUser);
return `success`;
}