|
@@ -32,9 +32,9 @@ class Register extends API {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async onRequest(req, res) {
|
|
async onRequest(req, res) {
|
|
|
- let { username, password, captcha, id } = req.body
|
|
|
|
|
|
|
+ let { username, password, code, email } = req.body
|
|
|
|
|
|
|
|
- if ([username, password, captcha, id].some(value => value === '' || value === null || value === undefined))
|
|
|
|
|
|
|
+ if ([username, password, code, email].some(value => value === '' || value === null || value === undefined))
|
|
|
return res.json({
|
|
return res.json({
|
|
|
...BaseStdResponse.MISSING_PARAMETER
|
|
...BaseStdResponse.MISSING_PARAMETER
|
|
|
})
|
|
})
|
|
@@ -53,33 +53,16 @@ class Register extends API {
|
|
|
msg: '密码需在8到16位之间,且包含字母和数字'
|
|
msg: '密码需在8到16位之间,且包含字母和数字'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // try {
|
|
|
|
|
- // const VerifyCode = await Redis.get(`email:${email}`);
|
|
|
|
|
- // if (!VerifyCode || VerifyCode != code)
|
|
|
|
|
- // return res.json({
|
|
|
|
|
- // ...BaseStdResponse.SMS_CHECK_FAIL,
|
|
|
|
|
- // msg: '邮箱验证码输入错误或已过期'
|
|
|
|
|
- // })
|
|
|
|
|
-
|
|
|
|
|
- // } catch (err) {
|
|
|
|
|
- // this.logger.error(`验证邮箱验证码失败!${err.stack}`);
|
|
|
|
|
- // return res.json({
|
|
|
|
|
- // ...BaseStdResponse.DATABASE_ERR,
|
|
|
|
|
- // msg: '验证失败!'
|
|
|
|
|
- // })
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
- const code = await Redis.get(`captcha:${id}`)
|
|
|
|
|
- if (!code || code != captcha.toLowerCase())
|
|
|
|
|
|
|
+ const VerifyCode = await Redis.get(`email:${email}`);
|
|
|
|
|
+ if (!VerifyCode || VerifyCode != code)
|
|
|
return res.json({
|
|
return res.json({
|
|
|
...BaseStdResponse.SMS_CHECK_FAIL,
|
|
...BaseStdResponse.SMS_CHECK_FAIL,
|
|
|
- msg: '验证码输入错误或已过期'
|
|
|
|
|
|
|
+ msg: '邮箱验证码输入错误或已过期'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- await Redis.del(`captcha:${id}`)
|
|
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
- this.logger.error(`验证图片验证码失败!${err.stack}`)
|
|
|
|
|
|
|
+ this.logger.error(`验证邮箱验证码失败!${err.stack}`);
|
|
|
return res.json({
|
|
return res.json({
|
|
|
...BaseStdResponse.DATABASE_ERR,
|
|
...BaseStdResponse.DATABASE_ERR,
|
|
|
msg: '验证失败!'
|
|
msg: '验证失败!'
|
|
@@ -94,13 +77,13 @@ class Register extends API {
|
|
|
msg: '用户名已被占用!'
|
|
msg: '用户名已被占用!'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // sql = 'SELECT email FROM users WHERE email = ?';
|
|
|
|
|
- // let EmailRows = await db.query(sql, [email]);
|
|
|
|
|
- // if (EmailRows.length > 0)
|
|
|
|
|
- // return res.json({
|
|
|
|
|
- // ...BaseStdResponse.USER_ALREADY_EXISTS,
|
|
|
|
|
- // msg: '该邮箱已被注册!'
|
|
|
|
|
- // })
|
|
|
|
|
|
|
+ sql = 'SELECT email FROM users WHERE email = ?';
|
|
|
|
|
+ let EmailRows = await db.query(sql, [email]);
|
|
|
|
|
+ if (EmailRows.length > 0)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.USER_ALREADY_EXISTS,
|
|
|
|
|
+ msg: '该邮箱已被注册!'
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
const uuid = uuidv4()
|
|
const uuid = uuidv4()
|
|
|
const hashPassword = bcryptjs.hashSync(password, 10);
|
|
const hashPassword = bcryptjs.hashSync(password, 10);
|
|
@@ -111,12 +94,12 @@ class Register extends API {
|
|
|
|
|
|
|
|
if (result && result.affectedRows > 0) {
|
|
if (result && result.affectedRows > 0) {
|
|
|
// 注册成功后删除邮箱对应的验证码 避免注册失败后重复获取
|
|
// 注册成功后删除邮箱对应的验证码 避免注册失败后重复获取
|
|
|
- // await Redis.del(`email:${email}`);
|
|
|
|
|
|
|
+ await Redis.del(`email:${email}`);
|
|
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
|
...BaseStdResponse.OK
|
|
...BaseStdResponse.OK
|
|
|
})
|
|
})
|
|
|
- // await EmailTemplate.registerSuccess(email, username)
|
|
|
|
|
|
|
+ await EmailTemplate.registerSuccess(email, username)
|
|
|
} else {
|
|
} else {
|
|
|
res.json({ ...BaseStdResponse.ERR, msg: '注册失败!' });
|
|
res.json({ ...BaseStdResponse.ERR, msg: '注册失败!' });
|
|
|
}
|
|
}
|