Jelajahi Sumber

登录去除手机验证码验证

laiguoran 6 tahun lalu
induk
melakukan
36ed089907

+ 77 - 77
modules/users/controllers/login_controller.js

@@ -63,7 +63,7 @@ class LoginController {
             }
 
             //还要判断account是否是专业版用户
-            let isPro = true;
+            // let isPro = true;
             // const userInfo = await userModel.findDataByAccount(account);
             //
             // if (userInfo && userInfo.upgrade_list !== undefined) {
@@ -75,22 +75,22 @@ class LoginController {
             //     }
             // }
             // 专业版短信验证码验证
-            if (isPro) {
-                const codeMsg = request.session.code;
-                if (codeMsg !== undefined && request.body.code !== '') {
-                    const code = codeMsg.split('_')[0];
-                    const time = codeMsg.split('_')[1];
-                    console.log(code);
-                    console.log(request.body.code);
-                    if (Date.parse(new Date())/1000 > time+60*5 || request.body.code !== code) {
-                        return response.json({error: 3, msg: '验证码错误。'});
-                    } else {
-                        delete request.session.code;
-                    }
-                } else {
-                    return response.json({error: 3, msg: '验证码错误。'});
-                }
-            }
+            // if (isPro) {
+            //     const codeMsg = request.session.code;
+            //     if (codeMsg !== undefined && request.body.code !== '') {
+            //         const code = codeMsg.split('_')[0];
+            //         const time = codeMsg.split('_')[1];
+            //         console.log(code);
+            //         console.log(request.body.code);
+            //         if (Date.parse(new Date())/1000 > time+60*5 || request.body.code !== code) {
+            //             return response.json({error: 3, msg: '验证码错误。'});
+            //         } else {
+            //             delete request.session.code;
+            //         }
+            //     } else {
+            //         return response.json({error: 3, msg: '验证码错误。'});
+            //     }
+            // }
 
             // 判断极验验证码是否通过
             const captcha = new Captcha();
@@ -170,66 +170,66 @@ class LoginController {
      * @param response
      * @returns {Promise<void>}
      */
-    async accountIsPro(request, response) {
-        let res = {
-            error: 0,
-            msg: '',
-            result: false,
-        };
-        try{
-            const account = request.body.account;
-            const password = request.body.pw;
-
-            // 根据邮箱或手机号获取账号信息
-            let userModel = new UserModel();
-            // 调用接口验证登录信息
-            let responseData = await userModel.getInfoFromSSO(account, password);
-            console.log(responseData);
-            // 先判断返回值是否为未激活状态
-            if ( responseData === '-3') {
-                throw '因邮箱未完成认证,账号未激活;去<a href="https://sso.smartcost.com.cn" target="_blank">激活</a>。';
-            }
-            responseData = JSON.parse(responseData);
-            if (typeof responseData !== 'object') {
-                throw '邮箱/手机 或 密码错误';
-            }
-
-            if (responseData.length <= 0) {
-                throw '接口返回数据错误';
-            }
-
-            // 正确登录后 存入session
-            let userData = responseData[0];
-
-            if (userData.mobile === '') {
-                return response.json({error: 2,ssoId: userData.id});
-            }
-
-            // const userInfo = await userModel.findDataByAccount(account);
-            // if (userInfo && userInfo.upgrade_list !== undefined) {
-            //     for (const ul of userInfo.upgrade_list) {
-            //         if (ul.isUpgrade === true) {
-            //             res.result = true;
-            //             res.data = userInfo.mobile;
-            //             break;
-            //         }
-            //     }
-            // } else {
-            //     res.msg = '当前未存在此用户';
-            // }
-            res.result = true;
-            // if (userInfo) {
-            //     res.data = userInfo.mobile;
-            // } else {
-                res.data = userData.mobile;
-            // }
-        } catch (err) {
-            res.error = 1;
-            res.msg = err;
-        }
-
-        response.json(res);
-    }
+    // async accountIsPro(request, response) {
+    //     let res = {
+    //         error: 0,
+    //         msg: '',
+    //         result: false,
+    //     };
+    //     try{
+    //         const account = request.body.account;
+    //         const password = request.body.pw;
+    //
+    //         // 根据邮箱或手机号获取账号信息
+    //         let userModel = new UserModel();
+    //         // 调用接口验证登录信息
+    //         let responseData = await userModel.getInfoFromSSO(account, password);
+    //         console.log(responseData);
+    //         // 先判断返回值是否为未激活状态
+    //         if ( responseData === '-3') {
+    //             throw '因邮箱未完成认证,账号未激活;去<a href="https://sso.smartcost.com.cn" target="_blank">激活</a>。';
+    //         }
+    //         responseData = JSON.parse(responseData);
+    //         if (typeof responseData !== 'object') {
+    //             throw '邮箱/手机 或 密码错误';
+    //         }
+    //
+    //         if (responseData.length <= 0) {
+    //             throw '接口返回数据错误';
+    //         }
+    //
+    //         // 正确登录后 存入session
+    //         let userData = responseData[0];
+    //
+    //         if (userData.mobile === '') {
+    //             return response.json({error: 2,ssoId: userData.id});
+    //         }
+    //
+    //         // const userInfo = await userModel.findDataByAccount(account);
+    //         // if (userInfo && userInfo.upgrade_list !== undefined) {
+    //         //     for (const ul of userInfo.upgrade_list) {
+    //         //         if (ul.isUpgrade === true) {
+    //         //             res.result = true;
+    //         //             res.data = userInfo.mobile;
+    //         //             break;
+    //         //         }
+    //         //     }
+    //         // } else {
+    //         //     res.msg = '当前未存在此用户';
+    //         // }
+    //         res.result = true;
+    //         // if (userInfo) {
+    //         //     res.data = userInfo.mobile;
+    //         // } else {
+    //             res.data = userData.mobile;
+    //         // }
+    //     } catch (err) {
+    //         res.error = 1;
+    //         res.msg = err;
+    //     }
+    //
+    //     response.json(res);
+    // }
 
 }
 

+ 1 - 1
modules/users/routes/login_route.js

@@ -19,7 +19,7 @@ module.exports = function (app) {
 // 登录操作
     router.post('/login', loginController.login);
 
-    router.post('/accountIsPro', loginController.accountIsPro);
+    // router.post('/accountIsPro', loginController.accountIsPro);
 
     // 验证码相关
     router.get('/captcha', loginController.captcha);

+ 2 - 1
server.js

@@ -56,7 +56,8 @@ app.use(session({
 // 登录状态全局判断
 app.use(function (req, res, next) {
     let url = req.originalUrl;
-    if (/^\/login/.test(url) || /\.map|\.ico$/.test(url) || /^\/sms/.test(url) || /^\/cld/.test(url) || /^\/captcha/.test(url)  || /^\/accountIsPro/.test(url)) {
+    // if (/^\/login/.test(url) || /\.map|\.ico$/.test(url) || /^\/sms/.test(url) || /^\/cld/.test(url) || /^\/captcha/.test(url)  || /^\/accountIsPro/.test(url)) {
+    if (/^\/login/.test(url) || /\.map|\.ico$/.test(url) || /^\/sms/.test(url) || /^\/cld/.test(url) || /^\/captcha/.test(url)) {
         // 如果是登录页面或短信接口或cld接口则忽略判断数据
         next();
     } else {

+ 28 - 28
web/users/html/login.html

@@ -111,34 +111,34 @@
         </div>
     </div>
     <!--弹出手机验证码-->
-    <div class="modal fade" id="phonepass" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h5 class="modal-title">验证码安全登录</h5>
-                </div>
-                <div class="modal-body">
-                    <p class="">请您提供手机验证码进行安全登录。</p>
-                    <p class="">请点击“获取验证码”,验证码将发送至手机<span id="pro_mobile"></span>,注意查收。</p>
-                    <div class="form-row">
-                        <div class="form-group col-md-8">
-                            <input type="text" class="form-control" id="smsCode" placeholder="输入验证码">
-                            <div class="invalid-feedback">
-                            </div>
-                            <input type="hidden" class="form-control" id="proMobile">
-                        </div>
-                        <div class="form-group col-md-4">
-                            <button class="btn btn-primary" id="get-code2">获取验证码</button>
-                        </div>
-                    </div>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <button class="btn btn-primary" id="loginPro">登录</button>
-                </div>
-            </div>
-        </div>
-    </div>
+    <!--<div class="modal fade" id="phonepass" data-backdrop="static">-->
+        <!--<div class="modal-dialog" role="document">-->
+            <!--<div class="modal-content">-->
+                <!--<div class="modal-header">-->
+                    <!--<h5 class="modal-title">验证码安全登录</h5>-->
+                <!--</div>-->
+                <!--<div class="modal-body">-->
+                    <!--<p class="">请您提供手机验证码进行安全登录。</p>-->
+                    <!--<p class="">请点击“获取验证码”,验证码将发送至手机<span id="pro_mobile"></span>,注意查收。</p>-->
+                    <!--<div class="form-row">-->
+                        <!--<div class="form-group col-md-8">-->
+                            <!--<input type="text" class="form-control" id="smsCode" placeholder="输入验证码">-->
+                            <!--<div class="invalid-feedback">-->
+                            <!--</div>-->
+                            <!--<input type="hidden" class="form-control" id="proMobile">-->
+                        <!--</div>-->
+                        <!--<div class="form-group col-md-4">-->
+                            <!--<button class="btn btn-primary" id="get-code2">获取验证码</button>-->
+                        <!--</div>-->
+                    <!--</div>-->
+                <!--</div>-->
+                <!--<div class="modal-footer">-->
+                    <!--<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>-->
+                    <!--<button class="btn btn-primary" id="loginPro">登录</button>-->
+                <!--</div>-->
+            <!--</div>-->
+        <!--</div>-->
+    <!--</div>-->
     <!-- JS. -->
     <!-- inject:js -->
     <script type="text/javascript" src="/public/web/scMathUtil.js"></script>

+ 65 - 65
web/users/js/login.js

@@ -51,47 +51,47 @@ $(document).ready(function () {
                 return false;
             }
             let account = $("#inputEmail").val();
-            let pw = $("#inputPassword").val();
+            // let pw = $("#inputPassword").val();
 
             // 判断输入的邮箱/手机是否格式正确
             if(/^1[3456789]\d{9}$/.test(account) || /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(account)) {
                 // 先判断是否是专业版用户,是的话弹出短信验证
-                $.ajax({
-                    url: '/accountIsPro',
-                    type: 'post',
-                    async: true,
-                    data: {"account": account, "pw": pw},
-                    success: function (response) {
-                        if (response.error === 0) {
-                            const ispro = response.result;
-                            if (!ispro) {
+                // $.ajax({
+                //     url: '/accountIsPro',
+                //     type: 'post',
+                //     async: true,
+                //     data: {"account": account, "pw": pw},
+                //     success: function (response) {
+                //         if (response.error === 0) {
+                //             const ispro = response.result;
+                //             if (!ispro) {
                                 login(captchaObj);
-                            } else {
-                                $('#phonepass').modal('show');
-                                $('#proMobile').val(response.data);
-                                $('#pro_mobile').text(response.data.substr(0, 3) + '****' + response.data.substr(7, 11));
-                            }
-                        } else if(response.error === 2) {
-                            $('#check_ssoId').val(response.ssoId);
-                            $('#phone').modal('show');
-                        } else {
-                            let msg = response.msg !== undefined ? response.msg : '未知错误';
-                            showError(msg, $("input"));
-                        }
-                    }
-                });
+                //             } else {
+                //                 $('#phonepass').modal('show');
+                //                 $('#proMobile').val(response.data);
+                //                 $('#pro_mobile').text(response.data.substr(0, 3) + '****' + response.data.substr(7, 11));
+                //             }
+                //         } else if(response.error === 2) {
+                //             $('#check_ssoId').val(response.ssoId);
+                //             $('#phone').modal('show');
+                //         } else {
+                //             let msg = response.msg !== undefined ? response.msg : '未知错误';
+                //             showError(msg, $("input"));
+                //         }
+                //     }
+                // });
             } else {
                 $('#emailHelp').text('您输入的 邮箱/手机 格式不对');
             }
         });
 
-        $('#loginPro').click(function () {
-            if ($('#smsCode').val() === '') {
-                showValidError('请输入验证码',$('#smsCode'));
-            } else {
-                login(captchaObj);
-            }
-        });
+        // $('#loginPro').click(function () {
+        //     if ($('#smsCode').val() === '') {
+        //         showValidError('请输入验证码',$('#smsCode'));
+        //     } else {
+        //         login(captchaObj);
+        //     }
+        // });
 
         $('#check-code').click(function () {
             const mobile = $("#mobile").val();
@@ -172,32 +172,32 @@ $(document).ready(function () {
         }
     });
 
-    $("#get-code2").click(function() {
-        const mobile = $("#proMobile").val();
-        if(!validMobile(mobile)){
-            return false;
-        }
-        const btn = $(this);
-        if(!btn.hasClass('disabled')){
-            $.ajax({
-                url: '/sms/code',
-                type: 'post',
-                data: { mobile: mobile, type: 3},
-                error: function() {
-                    showValidError('短信接口出错!',$('#smsCode'));
-                },
-                beforeSend: function() {
-                },
-                success: function(response) {
-                    if (response.err === 0) {
-                        codeSuccess(btn);
-                    } else {
-                        showValidError(response.msg,$('#smsCode'));
-                    }
-                }
-            });
-        }
-    });
+    // $("#get-code2").click(function() {
+    //     const mobile = $("#proMobile").val();
+    //     if(!validMobile(mobile)){
+    //         return false;
+    //     }
+    //     const btn = $(this);
+    //     if(!btn.hasClass('disabled')){
+    //         $.ajax({
+    //             url: '/sms/code',
+    //             type: 'post',
+    //             data: { mobile: mobile, type: 3},
+    //             error: function() {
+    //                 showValidError('短信接口出错!',$('#smsCode'));
+    //             },
+    //             beforeSend: function() {
+    //             },
+    //             success: function(response) {
+    //                 if (response.err === 0) {
+    //                     codeSuccess(btn);
+    //                 } else {
+    //                     showValidError(response.msg,$('#smsCode'));
+    //                 }
+    //             }
+    //         });
+    //     }
+    // });
 });
 
 function login(captchaObj) {
@@ -206,7 +206,7 @@ function login(captchaObj) {
     let geetest_challenge = $('input[name="geetest_challenge"]').val();
     let geetest_validate = $('input[name="geetest_validate"]').val();
     let geetest_seccode = $('input[name="geetest_seccode"]').val();
-    let code = $("#smsCode").val();
+    // let code = $("#smsCode").val();
 
     $.ajax({
         url: '/login',
@@ -217,11 +217,11 @@ function login(captchaObj) {
             "geetest_challenge": geetest_challenge,
             "geetest_validate": geetest_validate,
             "geetest_seccode": geetest_seccode,
-            "code": code,
+            // "code": code,
         },
         success: function (response) {
             if (response.error === 0) {
-                $('#phonepass').modal('hide');
+                // $('#phonepass').modal('hide');
                 const url = response.last_page !== null && response.last_page !== undefined && response.last_page !== '' ?
                     response.last_page : '/pm';
                 if (response.login_ask === 0) {
@@ -238,14 +238,14 @@ function login(captchaObj) {
                     $('#ver').modal('show');
                 }
             } else if(response.error === 2) {
-                $('#phonepass').modal('hide');
+                // $('#phonepass').modal('hide');
                 captchaObj.reset();
                 $('#check_ssoId').val(response.ssoId);
                 $('#phone').modal('show');
-            } else if(response.error === 3) {
-                showValidError(response.msg,$('#smsCode'));
+            // } else if(response.error === 3) {
+            //     showValidError(response.msg,$('#smsCode'));
             } else {
-                $('#phonepass').modal('hide');
+                // $('#phonepass').modal('hide');
                 let msg = response.msg !== undefined ? response.msg : '未知错误';
                 showError(msg, $("input"));
                 captchaObj.reset();
@@ -292,7 +292,7 @@ function validMobile(mobile) {
         showValidError('手机号不能为空!',$('#mobile'));
         return false;
     }
-    let mobileValid =  /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;
+    let mobileValid =  /^1[3456789]\d{9}$/;
     if(!mobileValid.test(mobile)){
         showValidError('手机号码格式有误!',$('#mobile'));
         return false;