- 비밀번호 초기화 로직 1차 구현(테스트 필요)
This commit is contained in:
@@ -18,12 +18,12 @@ export class AccountService {
|
||||
|
||||
async checkDuplication(data: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
|
||||
const { type, value } = data;
|
||||
const count = await this.accountRepo.checkDuplication(type, value);
|
||||
const count = await this.accountRepo.checkIdExists(type, value);
|
||||
|
||||
return { isDuplicated: count > 0 };
|
||||
return { isDuplicated: count > 0, success: true };
|
||||
}
|
||||
|
||||
async sendVerificationCode(data: DTO.SendVerificationCodeRequest): Promise<DTO.SendVerificationCodeResponse> {
|
||||
async sendVerificationCode(data: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
|
||||
const { email } = data;
|
||||
const code = Generator.getVerificationCode();
|
||||
const html = `<p>Your verification code is: <strong style="font-size:16px;">${code}</strong></p>`;
|
||||
@@ -38,20 +38,20 @@ export class AccountService {
|
||||
}
|
||||
}
|
||||
|
||||
async verifyCode(data: DTO.VerifyCodeRequest): Promise<DTO.VerifyCodeResponse> {
|
||||
async verifyCode(data: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
|
||||
const { email, code } = data;
|
||||
|
||||
const storedCode = await this.redis.get(`verify:${email}`);
|
||||
|
||||
if (!storedCode) {
|
||||
return { verified: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
|
||||
return { verified: false, success: true, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
|
||||
}
|
||||
if (storedCode !== code) {
|
||||
return { verified: false, error: "잘못된 코드입니다." };
|
||||
return { verified: false, success: true, error: "잘못된 코드입니다." };
|
||||
}
|
||||
|
||||
await this.redis.del(`verify:${email}`);
|
||||
return { verified: true, message: "이메일 인증이 완료되었습니다." };
|
||||
return { verified: true, success: true, message: "이메일 인증이 완료되었습니다." };
|
||||
}
|
||||
|
||||
async signup(data: DTO.SignupRequest): Promise<DTO.SignupResponse> {
|
||||
@@ -77,7 +77,7 @@ export class AccountService {
|
||||
const { type, id, password } = data;
|
||||
const queryResult = await this.accountRepo.login(type, id);
|
||||
const typeValue = type === 'email' ? '이메일' : '아이디';
|
||||
console.log(queryResult);
|
||||
|
||||
if (!queryResult || (queryResult.length < 1)) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -114,7 +114,87 @@ export class AccountService {
|
||||
const { accessToken, refreshToken } = this.authService.refreshTokens(id);
|
||||
return {
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
refreshToken: refreshToken,
|
||||
success: true
|
||||
};
|
||||
}
|
||||
|
||||
async sendResetPasswordCode(data: DTO.SendResetPasswordCodeRequest): Promise<DTO.SendResetPasswordCodeResponse> {
|
||||
const { email } = data;
|
||||
|
||||
const count = await this.accountRepo.checkIdExists('email', email);
|
||||
|
||||
if (count === 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: "찾을 수 없는 사용자"
|
||||
};
|
||||
}
|
||||
|
||||
const code = Generator.getResetPasswordCode();
|
||||
|
||||
const html =
|
||||
`<p>Your Password Reset Code is: <strong>${code}</strong></p>`
|
||||
+ `<p>Please Enter this code in 5 minutes.</p>`;
|
||||
const result = await this.mailerService.sendMail(email, "<Scheduler> 비밀번호 초기화 코드", html);
|
||||
|
||||
if (result.rejected.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: result.response
|
||||
};
|
||||
}
|
||||
|
||||
await this.redis.set(`resetPassword:${email}`, code, 'EX', 300);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "비밀번호 초기화 코드 발송 완료"
|
||||
};
|
||||
}
|
||||
|
||||
async verifyResetPasswordCode(data: DTO.VerifyResetPasswordCodeRequest): Promise<DTO.VerifyResetPasswordCodeResponse> {
|
||||
const { email, code } = data;
|
||||
|
||||
const storedCode = await this.redis.get(`resetPassword:${email}`);
|
||||
|
||||
if (!storedCode) {
|
||||
return {
|
||||
success: false,
|
||||
message: "잘못된 이메일이거나 코드가 만료되었습니다."
|
||||
};
|
||||
}
|
||||
|
||||
if (storedCode !== code) {
|
||||
return {
|
||||
success: false,
|
||||
message: "잘못된 코드입니다."
|
||||
};
|
||||
}
|
||||
|
||||
await this.redis.del(`resetPassword:${email}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "비밀번호 초기화 코드 인증 완료"
|
||||
};
|
||||
}
|
||||
|
||||
async resetPassword(data: DTO.ResetPasswordRequest): Promise<DTO.ResetPasswordResponse> {
|
||||
const { email, password } = data;
|
||||
const hashedPassword = Converter.getHashedPassword(password);
|
||||
const result = await this.accountRepo.updatePassword('email', email, hashedPassword);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: "비밀번호 초기화 실패"
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "비밀번호 초기화 성공"
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user