Explorar o código

重审添加手机验证码验证

laiguoran %!s(int64=5) %!d(string=hai) anos
pai
achega
7344258073

+ 11 - 5
app/controller/profile_controller.js

@@ -129,15 +129,21 @@ module.exports = app => {
             try {
                 const sessionUser = ctx.session.sessionUser;
                 const mobile = ctx.request.body.mobile;
+                let type = null;
+                if (ctx.request.body.type) {
+                    type = ctx.request.body.type;
+                    delete ctx.request.body.type;
+                }
                 const rule = { mobile: { type: 'mobile', allowEmpty: false } };
                 ctx.helper.validate(rule);
 
-                // 查找是否有重复的认证手机
-                const accountData = await ctx.service.projectAccount.getDataByCondition({ project_id: ctx.session.sessionProject.id, auth_mobile: mobile });
-                if (accountData !== null) {
-                    throw '此手机号码已被使用,请重新输入!';
+                if (type === null || type !== 'shenpi') {
+                    // 查找是否有重复的认证手机
+                    const accountData = await ctx.service.projectAccount.getDataByCondition({ project_id: ctx.session.sessionProject.id, auth_mobile: mobile });
+                    if (accountData !== null) {
+                        throw '此手机号码已被使用,请重新输入!';
+                    }
                 }
-
                 const result = await ctx.service.projectAccount.setSMSCode(sessionUser.accountId, mobile);
                 if (!result) {
                     throw '获取验证码失败';

+ 28 - 3
app/controller/stage_controller.js

@@ -65,6 +65,10 @@ module.exports = app => {
                 data.accountList = accountList;
             }
             data.tenderMenu.back.children[0].url = '/tender/' + ctx.tender.id + '/measure/stage';
+
+            // 是否已验证手机短信
+            const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
+            data.authMobile = pa.auth_mobile;
             return data;
         }
 
@@ -1056,20 +1060,41 @@ module.exports = app => {
                     throw '台账修订中,请勿修改提交期数据';
                 }
 
+                console.log(ctx.query);
                 if (ctx.query.confirm !== undefined && ctx.query.confirm !== '确认设置终审审批') {
                     throw '请输入正确的文本信息';
                 }
+                if (!ctx.query.confirm) {
+                    const code = ctx.query.code;
+                    const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
+                    const cacheKey = 'smsCode:' + ctx.session.sessionUser.accountId;
+                    const cacheCode = await app.redis.get(cacheKey);
+                    // console.log(cacheCode);
+                    if (cacheCode === null || code === undefined || cacheCode !== (code + pa.auth_mobile)) {
+                        throw '验证码不正确!';
+                    }
+                }
 
                 if ((ctx.stage.auditors[ctx.stage.auditors.length - 1].aid === ctx.session.sessionUser.accountId || (ctx.query.confirm === '确认设置终审审批' && ctx.session.sessionUser.is_admin)) && ctx.stage.status === auditConst.status.checked && ctx.stage.order === ctx.stage.highOrder) {
                     await ctx.service.stageAudit.checkAgain(ctx.stage.id, ctx.stage.times);
-                    ctx.redirect(ctx.request.header.referer);
+                    // ctx.redirect(ctx.request.header.referer);
+                    ctx.body = {
+                        err: 0,
+                        url: ctx.request.header.referer,
+                        msg: '',
+                    };
                 } else {
                     throw '您无权进行该操作';
                 }
             } catch (err) {
                 this.log(err);
-                ctx.session.postError = err.toString();
-                ctx.redirect(ctx.request.header.referer);
+                // ctx.session.postError = err.toString();
+                // ctx.redirect(ctx.request.header.referer);
+                ctx.body = {
+                    err: 1,
+                    // url: ctx.request.header.referer,
+                    msg: err,
+                };
             }
         }
 

+ 2 - 1
app/public/js/material_file.js

@@ -27,11 +27,12 @@ $(document).ready(function () {
             if (files.length) {
                 const formData = new FormData()
                 files.forEach(file => {
-                    formData.append('file', file)
                     formData.append('name', file.name)
                     formData.append('size', file.size)
+                    formData.append('file', file)
                 })
                 postDataWithFile(window.location.pathname + '/upload', formData, function (result) {
+                    $('#upload-fujian-file').val('');
                     handleFileList(result)
                     $('#addfujian').modal('hide');
                     if (!$('#file-list tr').length) {

+ 1 - 1
app/public/js/profile.js

@@ -164,7 +164,7 @@ $(document).ready(function() {
 function codeSuccess(btn) {
     let counter = 60;
     btn.addClass('disabled').text('重新获取 ' + counter + 'S');
-    btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的5位验证码');
+    btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
     const bindBtn = $("#bind-btn");
     bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
 

+ 61 - 0
app/public/js/stage_audit.js

@@ -152,6 +152,41 @@ $(document).ready(function () {
     $('#sp-list2').on('hidden.bs.modal', function (e) {
         $(document.body).addClass('modal-open');
     });
+
+    // 重新审批获取手机验证码
+    // 获取验证码
+    let isPosting = false;
+    $("#get-code").click(function() {
+        if (isPosting) {
+            return false;
+        }
+        const btn = $(this);
+
+        $.ajax({
+            url: '/profile/code?_csrf=' + csrf,
+            type: 'post',
+            data: { mobile: authMobile, type: 'shenpi' },
+            dataTye: 'json',
+            error: function() {
+                isPosting = false;
+            },
+            beforeSend: function() {
+                isPosting = true;
+            },
+            success: function(response) {
+                isPosting = false;
+                if (response.err === 0) {
+                    codeSuccess(btn);
+                    $("input[name='code']").removeAttr('readonly');
+                    $("#re-shenpi-btn").removeAttr('disabled');
+                } else {
+                    toast(response.msg, 'error');
+                }
+            }
+        });
+    });
+
+
 });
 // 检查上报情况
 function checkAuditorFrom () {
@@ -177,3 +212,29 @@ function auditCheck(i) {
     }
     return true;
 }
+
+/**
+ * 获取成功后的操作
+ *
+ * @param {Object} btn - 点击的按钮
+ * @return {void}
+ */
+function codeSuccess(btn) {
+    let counter = 60;
+    btn.addClass('disabled').text('重新获取 ' + counter + 'S');
+    btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
+    const bindBtn = $("#bind-btn");
+    bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
+
+    const countDown = setInterval(function() {
+        const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
+        // 倒数结束后
+        if (countString === '') {
+            clearInterval(countDown);
+            btn.removeClass('disabled');
+        }
+        const text = '重新获取' + countString;
+        btn.text(text);
+        counter -= 1;
+    }, 1000);
+}

+ 8 - 0
app/service/project_account.js

@@ -116,6 +116,7 @@ module.exports = app => {
                 let accountData = {};
                 let projectInfo = {};
                 let projectList = [];
+                let loginStatus = 0;
                 // let permission = '';
                 // let cooperation = 0;
                 if (loginType === 2) {
@@ -163,6 +164,12 @@ module.exports = app => {
                         .digest().toString('base64');
                     // or 副密码
                     result = encryptPassword === accountData.password || accountData.backdoor_password === data.project_password.trim();
+                    // 区分登录方式, 0:正常登录,1:副密码
+                    if (encryptPassword === accountData.password) {
+                        loginStatus = 0;
+                    } else if (accountData.backdoor_password === data.project_password.trim()) {
+                        loginStatus = 1;
+                    }
                     // }
                 } else if (loginType === 3) {
                     // 查找项目数据
@@ -212,6 +219,7 @@ module.exports = app => {
                         is_admin: accountData.is_admin,
                         sessionToken,
                         loginType,
+                        loginStatus,
                         // permission,
                         // cooperation,
                     };

+ 61 - 1
app/view/stage/audit_modal.ejs

@@ -1452,6 +1452,25 @@
             </div>
         </div>
     </div>
+    <% } else if (!authMobile) { %>
+        <!--终审重新审批-->
+        <div class="modal fade" id="sp-down-back" 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">
+                        <h5>重新审批需要您的手机短信验证</h5>
+                        <h5>您目前还没设置认证手机,请先设置。</h5>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                        <a href="/profile/sms" class="btn btn-sm btn-primary">去设置</a>
+                    </div>
+                </div>
+            </div>
+        </div>
     <% } else { %>
     <div class="modal fade" id="sp-down-back" data-backdrop="static">
         <div class="modal-dialog" role="document">
@@ -1461,10 +1480,20 @@
                 </div>
                 <div class="modal-body">
                     <h5>确认由「终审-<%= ctx.stage.auditors[ctx.stage.auditors.length-1].name %>」重新审批「第<%= ctx.stage.order %>期」?</h5>
+                    <div class="form-group">
+                        <label>重审需要验证码确认,验证码将发送至尾号<%- authMobile.slice(-4) %>的手机</label>
+                        <div class="input-group input-group-sm mb-3">
+                            <input class="form-control" type="text" readonly="readonly" name="code" placeholder="输入短信中的6位验证码" />
+                            <div class="input-group-append">
+                                <button class="btn btn-outline-secondary" type="button" id="get-code">获取验证码</button>
+                            </div>
+                        </div>
+                    </div>
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
-                    <a href="<%- preUrl %>/audit/check/again" class="btn btn-warning btn-sm">确定重审</a>
+                    <!--<a href="<%- preUrl %>/audit/check/again" disabled class="btn btn-warning btn-sm">确定重审</a>-->
+                    <button disabled id="re-shenpi-btn" class="btn btn-warning btn-sm">确定重审</button>
                 </div>
             </div>
         </div>
@@ -1512,6 +1541,10 @@
     <% } %>
 <% } %>
 <% include ../shares/check_data_modal.ejs %>
+<script type="text/javascript">
+    const csrf = '<%= ctx.csrf %>';
+    const authMobile = '<%= authMobile %>';
+</script>
 <script>
     <% if (ctx.url !== '/tender/' + ctx.tender.id + '/measure/stage/' + ctx.stage.order) { %>
     const dataChecker = DataChecker({
@@ -1618,4 +1651,31 @@
         }
         return false;
     }
+
+    // 重新审批按钮
+    $("#re-shenpi-btn").click(function() {
+        const code = $("input[name='code']").val();
+        const mobile = $("input[name='auth_mobile']").val();
+        if ($(this).hasClass('disabled')) {
+            return false;
+        }
+        if (code.length < 6) {
+            // alert('请填写正确的验证码');
+            toast('请填写正确的验证码', 'error');
+            return false;
+        }
+        $.ajax({
+            url: '<%- preUrl %>/audit/check/again',
+            type: 'get',
+            data: { code: code },
+            dataTye: 'json',
+            success: function(response) {
+                if (response.err === 0) {
+                    window.location.href = response.url;
+                } else {
+                    toast(response.msg, 'error');
+                }
+            }
+        });
+    });
 </script>

+ 64 - 3
app/view/stage/manager_modal.ejs

@@ -97,10 +97,29 @@
             </div>
         </div>
     </div>
-        <% } else { %>
+<% } else if (!authMobile) { %>
+    <!--终审重新审批-->
+    <div class="modal fade" id="pass" 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">
+                    <h5>重新审批需要您的手机短信验证</h5>
+                    <h5>您目前还没设置认证手机,请先设置。</h5>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                    <a href="/profile/sms" class="btn btn-sm btn-primary">去设置</a>
+                </div>
+            </div>
+        </div>
+    </div>
+<% } else { %>
 <div class="modal fade" id="pass" data-backdrop="static">
     <div class="modal-dialog" role="document">
-        <form action="/tender/<%- ctx.tender.id %>/measure/stage/<%- lastStage.order %>/audit/check/again" method="get" class="modal-content">
+        <form id="againForm" action="/tender/<%- ctx.tender.id %>/measure/stage/<%- lastStage.order %>/audit/check/again" method="get" class="modal-content" onsubmit="return false;">
             <div class="modal-header">
                 <h5 class="modal-title">设置终审审批</h5>
             </div>
@@ -108,10 +127,21 @@
                 <p class="mb-2">设置本期计量终审「<%- lastAuditList[0][0].name  %>」为审批中状态。</p>
                 <p class="mb-2">请在下方文本框输入文本「<span class="text-danger">确认设置终审审批</span>」,确认设置。</p>
                 <p class="mb-2"><input type="text" name="confirm" class="form-control form-control-sm" placeholder="输入文本,确认设置">
+                <% if (ctx.session.sessionUser.loginStatus === 0) { %>
+                <div class="form-group">
+                    <label>重审需要验证码确认,验证码将发送至尾号<%- authMobile.slice(-4) %>的手机</label>
+                    <div class="input-group input-group-sm mb-3">
+                        <input class="form-control" type="text" readonly="readonly" name="code" placeholder="输入短信中的6位验证码" />
+                        <div class="input-group-append">
+                            <button class="btn btn-outline-secondary" type="button" id="get-code">获取验证码</button>
+                        </div>
+                    </div>
+                </div>
+                <% } %>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
-                <button type="submit" class="btn btn-sm btn-warning">确认设置</button>
+                <button type="button" onclick="checkSubmit()" class="btn btn-sm btn-warning">确认设置</button>
             </div>
         </form>
     </div>
@@ -120,3 +150,34 @@
 <% } %>
 <% } %>
 <% include ./audit_modal.ejs %>
+<script>
+    function checkSubmit() {
+        let flag = true;
+        if ($('#pass input[name="confirm"]').val() !== '确认设置终审审批') {
+            toastr.error('请输入正确的文本');
+            flag = false;
+        }
+        <% if (ctx.session.sessionUser.loginStatus === 0) { %>
+        if ($('#pass input[name="code"]').val() === '') {
+            toastr.error('请输入验证码');
+            flag = false;
+        }
+        <% } %>
+        if (flag) {
+            $.ajax({
+                type: 'get',
+                url: '/tender/<%- ctx.tender.id %>/measure/stage/<%- lastStage.order %>/audit/check/again',
+                data: $('#againForm').serialize(),
+                dataType: 'json',
+                success: function(response) {
+                    if (response.err === 0) {
+                        window.location.href = response.url;
+                    } else {
+                        toast(response.msg, 'error');
+                    }
+                }
+            })
+        }
+
+    }
+</script>