记录邮箱验证码发送
This commit is contained in:
parent
faf34c241b
commit
ba71e011f0
@ -1,9 +1,11 @@
|
||||
import {
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
ConflictException,
|
||||
NotFoundException,
|
||||
ForbiddenException,
|
||||
InternalServerErrorException,
|
||||
} from '@nestjs/common'
|
||||
import { securityConfig, SecurityConfig } from 'src/common/configs'
|
||||
import { MailerService } from '@nestjs-modules/mailer'
|
||||
@ -25,12 +27,13 @@ export class EmailService {
|
||||
[EmailScene.changeEmail]: '修改邮箱',
|
||||
[EmailScene.deleteUser]: '删除用户',
|
||||
}
|
||||
private readonly logger = new Logger('Email')
|
||||
|
||||
constructor(
|
||||
private prismaService: PrismaService,
|
||||
private mailerService: MailerService,
|
||||
private jwtService: JwtService,
|
||||
@Inject(securityConfig.KEY)
|
||||
private secureConfig: SecurityConfig,
|
||||
@Inject(securityConfig.KEY) private secureConfig: SecurityConfig,
|
||||
) {}
|
||||
|
||||
async sendEmailToken(
|
||||
@ -60,11 +63,20 @@ export class EmailService {
|
||||
{ email, scene },
|
||||
{ secret: this.getEmailJwtSecret(verifyCode, scene) },
|
||||
)
|
||||
await this.mailerService.sendMail({
|
||||
const sendEmailConfig = {
|
||||
to: email,
|
||||
subject: `【qiuxu.site】${this.subjectMap[scene]}`,
|
||||
html: `您正在qiuxu.site${this.subjectMap[scene]},验证码为 <strong>${verifyCode}</strong>,30分钟内有效`,
|
||||
})
|
||||
}
|
||||
await this.mailerService
|
||||
.sendMail(sendEmailConfig)
|
||||
.then(() => {
|
||||
this.logger.log(JSON.stringify(sendEmailConfig))
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err)
|
||||
throw new InternalServerErrorException(err.message)
|
||||
})
|
||||
return { token, userId: user?.id }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user