Browse Source

✨ feat: 用户注册减少邮箱验证

Pchen. 3 months ago
parent
commit
f72302637d
3 changed files with 53 additions and 19 deletions
  1. 1 1
      apis/Kefu/Order/GetOrderList.js
  2. 35 18
      apis/User/Register.js
  3. 17 0
      lib/Lepao/cg_lepao.js

+ 1 - 1
apis/Kefu/Order/GetOrderList.js

@@ -20,7 +20,7 @@ class GetOrderList extends API {
             })
             })
 
 
         // 校验分页参数
         // 校验分页参数
-        if (isNaN(pagesize) || pagesize <= 0 || pagesize > 50) {
+        if (isNaN(pagesize) || pagesize <= 0) {
             return res.json({
             return res.json({
                 ...BaseStdResponse.ERR,
                 ...BaseStdResponse.ERR,
                 msg: '参数错误'
                 msg: '参数错误'

+ 35 - 18
apis/User/Register.js

@@ -32,14 +32,14 @@ class Register extends API {
     }
     }
 
 
     async onRequest(req, res) {
     async onRequest(req, res) {
-        let { username, email, code, password } = req.body
+        let { username, password, captcha, id } = req.body
 
 
-        if ([username, email, code, password].some(value => value === '' || value === null || value === undefined))
+        if ([username, password, captcha, id].some(value => value === '' || value === null || value === undefined))
             return res.json({
             return res.json({
                 ...BaseStdResponse.MISSING_PARAMETER
                 ...BaseStdResponse.MISSING_PARAMETER
             })
             })
 
 
-        if(!this.checkUsername(username))
+        if (!this.checkUsername(username))
             return res.json({
             return res.json({
                 ...BaseStdResponse.ERR,
                 ...BaseStdResponse.ERR,
                 msg: '用户名需在3到12位之间,且不能含有特殊字符'
                 msg: '用户名需在3到12位之间,且不能含有特殊字符'
@@ -53,16 +53,33 @@ 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 VerifyCode = await Redis.get(`email:${email}`);
-            if (!VerifyCode || VerifyCode != code)
+            const code = await Redis.get(`captcha:${id}`)
+            if (!code || code != captcha.toLowerCase())
                 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: '验证失败!'
@@ -77,31 +94,31 @@ 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);
         const time = new Date().getTime()
         const time = new Date().getTime()
 
 
         sql = 'INSERT INTO users (uuid, username, email, password, registTime) VALUES (?, ?, ?, ?, ?)';
         sql = 'INSERT INTO users (uuid, username, email, password, registTime) VALUES (?, ?, ?, ?, ?)';
-        let result = await db.query(sql, [uuid, username, email, hashPassword, time]);
+        let result = await db.query(sql, [uuid, username, '未设置', hashPassword, time]);
 
 
         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, endpoint: 7894378, msg: '注册失败!'});
+            res.json({ ...BaseStdResponse.ERR, msg: '注册失败!' });
         }
         }
     }
     }
 }
 }

+ 17 - 0
lib/Lepao/cg_lepao.js

@@ -0,0 +1,17 @@
+const axios = require('axios')
+const Redis = require('../../plugin/DataBase/Redis')
+const db = require('../../plugin/DataBase/db')
+const Logger = require('../Logger')
+const path = require('path')
+const EmailTemplate = require('../../plugin/Email/emailTemplate')
+
+class cgLepao {
+    constructor() {
+        this.logger = new Logger(path.join(__dirname, '../logs/cgLepao.log'), 'INFO')
+    }
+
+    async 
+}
+
+const cgLepao = new cgLepao()
+module.exports.cgLepao = cgLepao