|
@@ -32,6 +32,8 @@ export class LoginService {
|
|
loginSmsSign;
|
|
loginSmsSign;
|
|
@Config('pwdSmsSign')
|
|
@Config('pwdSmsSign')
|
|
pwdSmsSign;
|
|
pwdSmsSign;
|
|
|
|
+ @Config('regSmsSign')
|
|
|
|
+ regSmsSign;
|
|
|
|
|
|
@Inject()
|
|
@Inject()
|
|
redisService: RedisService;
|
|
redisService: RedisService;
|
|
@@ -46,6 +48,32 @@ export class LoginService {
|
|
@InjectEntityModel(User)
|
|
@InjectEntityModel(User)
|
|
userModel: Repository<User>;
|
|
userModel: Repository<User>;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 注册验证 验证码
|
|
|
|
+ * @param phone 电话号码
|
|
|
|
+ * @param code 验证码
|
|
|
|
+ * @returns
|
|
|
|
+ */
|
|
|
|
+ async checkRegCode(phone,code) {
|
|
|
|
+ const redisKey = `${this.regSmsSign}:${phone}`
|
|
|
|
+ const redisCode = await this.redisService.get(redisKey);
|
|
|
|
+ if (!redisCode) throw new ServiceError(ErrorCode.REG_VALICODE_EXPIRES); // 验证码已过期
|
|
|
|
+ if (`${redisCode}` !== `${code}`) throw new ServiceError(ErrorCode.REG_VALICODE_ERROR); // 验证码错误
|
|
|
|
+ await this.redisService.del(redisKey);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发送注册验证码
|
|
|
|
+ * @param phone 电话号码
|
|
|
|
+ */
|
|
|
|
+ async sendRegCode(phone) {
|
|
|
|
+ const redisKey = `${this.regSmsSign}:${phone}`
|
|
|
|
+ const code = random(1000, 999999);
|
|
|
|
+ await this.redisService.set(redisKey, code, 'EX', this.timeLimit);
|
|
|
|
+ await this.smsService.send(phone, code);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 验证:找回密码的验证是否正确
|
|
* 验证:找回密码的验证是否正确
|
|
* @param type 验证方式
|
|
* @param type 验证方式
|
|
@@ -71,7 +99,7 @@ export class LoginService {
|
|
const code = random(1000, 999999);
|
|
const code = random(1000, 999999);
|
|
await this.redisService.set(redisKey, code, 'EX', this.timeLimit);
|
|
await this.redisService.set(redisKey, code, 'EX', this.timeLimit);
|
|
if (type === 'email') {
|
|
if (type === 'email') {
|
|
- // TODO: 发邮箱
|
|
|
|
|
|
+ // 发邮箱
|
|
await this.emailService.sendPwdCode(to, code);
|
|
await this.emailService.sendPwdCode(to, code);
|
|
} else if (type === 'phone') {
|
|
} else if (type === 'phone') {
|
|
// 发短信
|
|
// 发短信
|