浏览代码

短信和签名和bug

laiguoran 6 年之前
父节点
当前提交
c64faf1644

+ 1 - 1
app/controller/profile_controller.js

@@ -152,7 +152,7 @@ module.exports = app => {
                 ctx.helper.validate(rule);
                 ctx.helper.validate(rule);
 
 
                 const sessionUser = ctx.session.sessionUser;
                 const sessionUser = ctx.session.sessionUser;
-                const result = await ctx.service.projectAccount.bindMobile(sessionUser.accountId, ctx.request.body);
+                const result = await ctx.service.projectAccount.bindMobile(sessionUser.accountId, ctx.request.body, ctx.session.sessionProject.id);
 
 
                 if (!result) {
                 if (!result) {
                     throw '绑定手机失败!';
                     throw '绑定手机失败!';

+ 1 - 1
app/extend/helper.js

@@ -241,7 +241,7 @@ module.exports = {
                 throw '请求失败';
                 throw '请求失败';
             }
             }
             return response.data;
             return response.data;
-        } catch(err) {
+        } catch (err) {
             throw '请求失败';
             throw '请求失败';
         }
         }
     },
     },

+ 15 - 9
app/lib/sms.js

@@ -19,7 +19,8 @@ class SMS {
      */
      */
     constructor(ctx) {
     constructor(ctx) {
         this.ctx = ctx;
         this.ctx = ctx;
-        this.url = 'http://101.132.42.40:7862/sms';
+        this.url = 'http://sms.haotingyun.com/v2/sms/single_send.json';
+        // this.url = 'http://101.132.42.40:7862/sms';
     }
     }
 
 
     /**
     /**
@@ -36,21 +37,26 @@ class SMS {
         let result = false;
         let result = false;
         const config = this.ctx.app.config.sms;
         const config = this.ctx.app.config.sms;
         const postData = {
         const postData = {
-            action: 'send',
-            account: config.account,
-            password: config.password,
+            // action: 'send',
+            // account: config.account,
+            // password: config.password,
+            apikey: config.authKey,
             mobile,
             mobile,
-            content,
-            extno: config.extno,
+            text: content,
+            // extno: config.extno,
         };
         };
         try {
         try {
-            const response = await this.ctx.helper.sendRequest(this.url, postData, 'POST', 'text');
-            const xmlData = await this.xmlParse(response);
-            if (xmlData === undefined || xmlData.returnstatus.text() !== 'Success') {
+            const response = await this.ctx.helper.sendRequest(this.url, postData, 'POST');
+            // const xmlData = await this.xmlParse(response);
+            // if (xmlData === undefined || xmlData.returnstatus.text() !== 'Success') {
+            //     throw '短信发送失败!';
+            // }
+            if (response === undefined && response.code !== 0) {
                 throw '短信发送失败!';
                 throw '短信发送失败!';
             }
             }
             result = true;
             result = true;
         } catch (error) {
         } catch (error) {
+            console.log(error);
             result = false;
             result = false;
         }
         }
 
 

+ 23 - 6
app/public/js/profile.js

@@ -10,26 +10,30 @@ $(document).ready(function() {
         if (user !== '') {
         if (user !== '') {
             $(".title-bar h2").text(user);
             $(".title-bar h2").text(user);
         }
         }
-
+        $.validator.addMethod("isMobile", function(value, element) {
+            var length = value.length;
+            var mobile = /^1[3456789]\d{9}$/;
+            return this.optional(element) || (length == 11 && mobile.test(value));
+        }, "请正确填写您的手机号码");
         const options = {
         const options = {
             rules: '',
             rules: '',
             errorPlacement: function(error, element) {
             errorPlacement: function(error, element) {
                 $(element).addClass('is-invalid');
                 $(element).addClass('is-invalid');
-                $(element).after(error);
+                $('.input-group-append').after(error);
             },
             },
             errorClass: "invalid-feedback",
             errorClass: "invalid-feedback",
             errorElement: "div",
             errorElement: "div",
             highlight: false,
             highlight: false,
             success: function(element) {
             success: function(element) {
-                $(element).prev('input').removeClass('is-invalid');
+                $(element).siblings('input').removeClass('is-invalid');
                 $(element).remove();
                 $(element).remove();
             },
             },
         };
         };
 
 
         options.rules = {
         options.rules = {
             auth_mobile: {
             auth_mobile: {
-                mobile: true,
                 required: true,
                 required: true,
+                isMobile: true,
             },
             },
         };
         };
         $("#mobile-form").validate(options);
         $("#mobile-form").validate(options);
@@ -61,8 +65,10 @@ $(document).ready(function() {
                     isPosting = false;
                     isPosting = false;
                     if (response.err === 0) {
                     if (response.err === 0) {
                         codeSuccess(btn);
                         codeSuccess(btn);
+                        $("input[name='code']").removeAttr('readonly');
+                        $("#bind-btn").removeClass('disabled').removeClass('btn-secondary').addClass('btn-primary');
                     } else {
                     } else {
-                        alert(response.msg);
+                        toast(response.msg, 'error');
                     }
                     }
                 }
                 }
             });
             });
@@ -71,11 +77,22 @@ $(document).ready(function() {
         // 绑定按钮
         // 绑定按钮
         $("#bind-btn").click(function() {
         $("#bind-btn").click(function() {
             const code = $("input[name='code']").val();
             const code = $("input[name='code']").val();
+            const mobile = $("input[name='auth_mobile']").val();
+            if (!(/^1[3456789]\d{9}$/.test(mobile))) {
+                toast('请填写正确的手机号码', 'error');
+                return false;
+            }
             if (code.length < 6) {
             if (code.length < 6) {
-                alert('请填写正确的验证码');
+                // alert('请填写正确的验证码');
+                toast('请填写正确的验证码', 'error');
                 return false;
                 return false;
             }
             }
         });
         });
+
+        $('#change-mobile').click(function () {
+            $(this).parents('.form-group').hide();
+            $('#mobile-form').show();
+        });
     } catch (error) {
     } catch (error) {
         console.log(error);
         console.log(error);
     }
     }

+ 14 - 7
app/service/project_account.js

@@ -364,9 +364,11 @@ module.exports = app => {
             // 通过密码验证后修改数据
             // 通过密码验证后修改数据
             const encryptNewPassword = crypto.createHmac('sha1', accountData.account).update(newPassword)
             const encryptNewPassword = crypto.createHmac('sha1', accountData.account).update(newPassword)
                 .digest().toString('base64');
                 .digest().toString('base64');
-            const updateData = { password: encryptNewPassword };
-            const result = await this.save(updateData, accountId);
+            const updateData = { id: accountId, password: encryptNewPassword };
+            // const result = await this.save(updateData, accountId);
+            const operate = await this.db.update(this.tableName, updateData);
 
 
+            const result = operate.affectedRows > 0;
             return result;
             return result;
         }
         }
 
 
@@ -387,7 +389,7 @@ module.exports = app => {
             // 发送短信
             // 发送短信
             try {
             try {
                 const sms = new SMS(this.ctx);
                 const sms = new SMS(this.ctx);
-                const content = '【纵横计量支付】验证码:' + randString + ',15分钟有效。';
+                const content = '【纵横计量支付】验证码:' + randString + ',15分钟有效。';
                 result = await sms.send(mobile, content);
                 result = await sms.send(mobile, content);
             } catch (error) {
             } catch (error) {
                 result = false;
                 result = false;
@@ -401,9 +403,10 @@ module.exports = app => {
          *
          *
          * @param {Number} accountId - 账号id
          * @param {Number} accountId - 账号id
          * @param {Object} data - post过来的数据
          * @param {Object} data - post过来的数据
+         * @param {Object} pid - 项目id
          * @return {Boolean} - 绑定结果
          * @return {Boolean} - 绑定结果
          */
          */
-        async bindMobile(accountId, data) {
+        async bindMobile(accountId, data, pid) {
             const cacheKey = 'smsCode:' + accountId;
             const cacheKey = 'smsCode:' + accountId;
             const cacheCode = await this.cache.get(cacheKey);
             const cacheCode = await this.cache.get(cacheKey);
             if (cacheCode === null || data.code === undefined || cacheCode !== (data.code + data.auth_mobile)) {
             if (cacheCode === null || data.code === undefined || cacheCode !== (data.code + data.auth_mobile)) {
@@ -411,14 +414,18 @@ module.exports = app => {
             }
             }
 
 
             // 查找是否有重复的认证手机
             // 查找是否有重复的认证手机
-            const accountData = await this.getDataByCondition({ auth_mobile: data.auth_mobile });
+            const accountData = await this.getDataByCondition({ project_id: pid, auth_mobile: data.auth_mobile });
             if (accountData !== null) {
             if (accountData !== null) {
                 throw '已存在对应的手机';
                 throw '已存在对应的手机';
             }
             }
 
 
-            const updateData = { auth_mobile: data.auth_mobile };
+            const updateData = { id: accountId, auth_mobile: data.auth_mobile };
+
+            // return this.save(updateData, accountId);
+            const operate = await this.db.update(this.tableName, updateData);
 
 
-            return this.save(updateData, accountId);
+            const result = operate.affectedRows > 0;
+            return result;
         }
         }
 
 
         /**
         /**

+ 119 - 13
app/view/profile/sms.ejs

@@ -9,36 +9,142 @@
         <div class="c-body">
         <div class="c-body">
             <div class="row m-0">
             <div class="row m-0">
                 <div class="col-5 my-3">
                 <div class="col-5 my-3">
+                    <% if (accountData.auth_mobile !== '') { %>
+                    <!--已绑定手机-->
+                    <div class="form-group">
+                        <label>已认证手机(用于 找回密码、接收通知)</label>
+                        <div class="input-group mb-3">
+                            <input class="form-control" readonly="" value="<%= accountData.auth_mobile %>">
+                            <div class="input-group-append">
+                                <button class="btn btn-outline-secondary" id="change-mobile">修改手机</button>
+                            </div>
+                        </div>
+                    </div>
+                    <% } %>
                     <!--绑定手机-->
                     <!--绑定手机-->
-                    <form id="mobile-form" method="post" action="/profile/bind">
+                    <form id="mobile-form" method="post" action="/profile/bind" <% if (accountData.auth_mobile !== '') { %>style="display: none" <% } %>>
                         <div class="form-group">
                         <div class="form-group">
                             <label>认证手机(用于 找回密码、接收通知)</label>
                             <label>认证手机(用于 找回密码、接收通知)</label>
-                            <input class="form-control" placeholder="输入11位手机号码" value="<%= accountData.auth_mobile %>"
-                                   <% if(accountData.auth_mobile !== '') { %>disabled="disabled"<% } %> name="auth_mobile"
-                                    maxlength="11"/>
-                        </div>
-                        <% if (accountData.auth_mobile === '') { %>
-                        <div class="form-group">
                             <div class="input-group mb-3">
                             <div class="input-group mb-3">
-                                <input class="form-control" readonly="readonly" name="code"/>
-                                <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
+                                <input class="form-control" placeholder="输入11位手机号码" value="" name="auth_mobile" maxlength="11"/>
                                 <div class="input-group-append">
                                 <div class="input-group-append">
                                     <button class="btn btn-outline-secondary" type="button" id="get-code">获取验证码</button>
                                     <button class="btn btn-outline-secondary" type="button" id="get-code">获取验证码</button>
                                 </div>
                                 </div>
                             </div>
                             </div>
                         </div>
                         </div>
+                        <div class="form-group">
+                            <div class="input-group mb-3">
+                                <input class="form-control" type="text" readonly="readonly" name="code" placeholder="输入短信中的6位验证码" />
+                                <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
+                            </div>
+                        </div>
                         <button type="submit" class="btn btn-secondary disabled" id="bind-btn">确认绑定</button>
                         <button type="submit" class="btn btn-secondary disabled" id="bind-btn">确认绑定</button>
-                        <% } %>
                     </form>
                     </form>
+                    <% if (accountData.auth_mobile !== '') { %>
+                    <!--短信通知开关(已有认证手机后显示)-->
+                    <div class="mt-5">
+                        <h4>通知类型</h4>
+                        <p class="text-muted">勾选您需要接收的短信类型。</p>
+                        <div class="form-group row">
+                            <label class="col-sm-2 col-form-label">台帐审批</label>
+                            <div class="col-sm-10">
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype1" value="option1">
+                                    <label class="form-check-label" for="smstype1">需要我审批</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype2" value="option2">
+                                    <label class="form-check-label" for="smstype2">审批通过(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype3" value="option3">
+                                    <label class="form-check-label" for="smstype3">审批通过(上报人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype4" value="option4">
+                                    <label class="form-check-label" for="smstype4">审批退回(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype5" value="option5">
+                                    <label class="form-check-label" for="smstype5">审批退回(上报人)</label>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group row">
+                            <label class="col-sm-2 col-form-label">计量审批</label>
+                            <div class="col-sm-10">
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype6" value="option6">
+                                    <label class="form-check-label" for="smstype6">需要我审批</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype7" value="option7">
+                                    <label class="form-check-label" for="smstype7">审批通过(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype8" value="option8">
+                                    <label class="form-check-label" for="smstype8">审批通过(上报人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype9" value="option9">
+                                    <label class="form-check-label" for="smstype9">审批退回(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype10" value="option10">
+                                    <label class="form-check-label" for="smstype10">审批退回(上报人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype11" value="option11">
+                                    <label class="form-check-label" for="smstype11">审批退回(接收人)</label>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group row">
+                            <label class="col-sm-2 col-form-label">变更管理</label>
+                            <div class="col-sm-10">
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype12" value="option12">
+                                    <label class="form-check-label" for="smstype12">需要我审批</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype13" value="option13">
+                                    <label class="form-check-label" for="smstype13">审批通过(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype14" value="option14">
+                                    <label class="form-check-label" for="smstype14">审批通过(上报人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype15" value="option15">
+                                    <label class="form-check-label" for="smstype15">审批退回(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype16" value="option16">
+                                    <label class="form-check-label" for="smstype16">审批退回(上报人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype17" value="option17">
+                                    <label class="form-check-label" for="smstype17">审批退回(接收人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype18" value="option18">
+                                    <label class="form-check-label" for="smstype18">审批终止(审批人)</label>
+                                </div>
+                                <div class="form-check ">
+                                    <input class="form-check-input" type="checkbox" id="smstype19" value="option19">
+                                    <label class="form-check-label" for="smstype19">审批终止(上报人)</label>
+                                </div>
+                            </div>
+                        </div>
+                        <button type="submit" class="btn btn-primary">确认修改</button>
+                    </div>
+                    <% } %>
                 </div>
                 </div>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>
 </div>
 </div>
 <script type="text/javascript">
 <script type="text/javascript">
-    new Vue({
-        el: '#app',
-    });
     const csrf = '<%= ctx.csrf %>';
     const csrf = '<%= ctx.csrf %>';
 </script>
 </script>
 <script type="text/javascript" src="/public/js/profile.js"></script>
 <script type="text/javascript" src="/public/js/profile.js"></script>

+ 2 - 2
app/view/stage/gather.ejs

@@ -1,4 +1,4 @@
-<% include ../tender/tender_sub_menu.ejs %>
+<% include ./stage_sub_menu.ejs %>
 <div class="panel-content">
 <div class="panel-content">
     <div class="panel-title">
     <div class="panel-title">
         <div class="title-main d-flex justify-content-between">
         <div class="title-main d-flex justify-content-between">
@@ -87,4 +87,4 @@
     const pos = JSON.parse('<%- JSON.stringify(pos) %>');
     const pos = JSON.parse('<%- JSON.stringify(pos) %>');
     const curPosData = JSON.parse('<%- JSON.stringify(curPosData) %>');
     const curPosData = JSON.parse('<%- JSON.stringify(curPosData) %>');
     const dealBills = JSON.parse('<%- JSON.stringify(dealBills) %>');
     const dealBills = JSON.parse('<%- JSON.stringify(dealBills) %>');
-</script>
+</script>

+ 3 - 3
config/config.default.js

@@ -82,9 +82,9 @@ module.exports = appInfo => {
 
 
     // 发送短信相关
     // 发送短信相关
     config.sms = {
     config.sms = {
-        account: '710030',
-        password: 'w7pRhJ',
-        extno: '10690587',
+        // account: '710030',
+        // password: 'w7pRhJ',
+        // extno: '10690587',
         authKey: 'fb5ef483e44b9556512a9febef376051',
         authKey: 'fb5ef483e44b9556512a9febef376051',
     };
     };