Authored by 陈峰

commit

@@ -28,6 +28,8 @@ export default { @@ -28,6 +28,8 @@ export default {
28 const validatePass = (rule, value, callback) => { 28 const validatePass = (rule, value, callback) => {
29 if (value === '') { 29 if (value === '') {
30 return callback(new Error('请输入密码')); 30 return callback(new Error('请输入密码'));
  31 + } else if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])[a-zA-Z\d\W_]{8,}$/.test(value)) {
  32 + return callback(new Error('密码长度必须大于八位,且包含大写字母,小写字母,数字和特殊字符'));
31 } else { 33 } else {
32 if (this.formInline.passwdCheck !== '') { 34 if (this.formInline.passwdCheck !== '') {
33 // 对第二个密码框单独验证 35 // 对第二个密码框单独验证
@@ -54,10 +56,10 @@ export default { @@ -54,10 +56,10 @@ export default {
54 }, 56 },
55 ruleInline: { 57 ruleInline: {
56 passwd: [ 58 passwd: [
57 - { validator: validatePass, trigger: 'blur' } 59 + { validator: validatePass, trigger: 'change' }
58 ], 60 ],
59 passwdCheck: [ 61 passwdCheck: [
60 - { validator: validatePassCheck, trigger: 'blur' } 62 + { validator: validatePassCheck, trigger: 'change' }
61 ] 63 ]
62 } 64 }
63 }; 65 };
@@ -71,7 +73,7 @@ export default { @@ -71,7 +73,7 @@ export default {
71 if (valid) { 73 if (valid) {
72 this.update(this.formInline.passwdCheck); 74 this.update(this.formInline.passwdCheck);
73 } else { 75 } else {
74 - this.$Message.error('表单验证失败!'); 76 + this.$Message.error('请按照规则输入密码!');
75 } 77 }
76 }); 78 });
77 }, 79 },
@@ -79,15 +81,13 @@ export default { @@ -79,15 +81,13 @@ export default {
79 this.loading = true; 81 this.loading = true;
80 82
81 this.UserService.update({ 83 this.UserService.update({
82 - account: '123',  
83 password: passwdCheck 84 password: passwdCheck
84 }).then(ret => { 85 }).then(ret => {
  86 + this.loading = false;
85 if (ret.code === 200) { 87 if (ret.code === 200) {
86 - this.loading = false;  
87 Vue.$store.remove('needUpdate'); 88 Vue.$store.remove('needUpdate');
88 this.$router.push('/'); 89 this.$router.push('/');
89 } else { 90 } else {
90 - this.loading = false;  
91 this.$Message.error(ret.message); 91 this.$Message.error(ret.message);
92 } 92 }
93 }); 93 });
@@ -98,6 +98,6 @@ export default { @@ -98,6 +98,6 @@ export default {
98 98
99 <style lang="scss"> 99 <style lang="scss">
100 .password { 100 .password {
101 - width: 400px; 101 + width: 500px;
102 } 102 }
103 </style> 103 </style>
@@ -10,13 +10,7 @@ class UserService extends Service { @@ -10,13 +10,7 @@ class UserService extends Service {
10 }); 10 });
11 } 11 }
12 update(params) { 12 update(params) {
13 - return this.post('/erp/update', params).then(ret => {  
14 - if (ret.code === 200) {  
15 - return this.get('/completeUpdate');  
16 - } else {  
17 - return ret;  
18 - }  
19 - }); 13 + return this.post('/updatePwd', params);
20 } 14 }
21 purviews() { 15 purviews() {
22 return this.post('/erp/getPurview', { 16 return this.post('/erp/getPurview', {
@@ -26,6 +26,6 @@ router.post('/import', before, auth, middleware(ImportController, 'import')); @@ -26,6 +26,6 @@ router.post('/import', before, auth, middleware(ImportController, 'import'));
26 router.post('/config', middleware(UserController, 'config')); 26 router.post('/config', middleware(UserController, 'config'));
27 router.get('/captcha.jpg', middleware(CaptchaController, 'captcha')); 27 router.get('/captcha.jpg', middleware(CaptchaController, 'captcha'));
28 router.get('/geeCaptcha', middleware(GeeCaptchaController, 'captcha')); 28 router.get('/geeCaptcha', middleware(GeeCaptchaController, 'captcha'));
29 -router.get('/completeUpdate', middleware(UserController, 'completeUpdate')); 29 +router.post('/updatePwd', middleware(UserController, 'updatePwd'));
30 30
31 module.exports = router; 31 module.exports = router;
@@ -72,11 +72,31 @@ class UserController extends Context { @@ -72,11 +72,31 @@ class UserController extends Context {
72 }).catch(next); 72 }).catch(next);
73 } 73 }
74 74
75 - completeUpdate(req, res) {  
76 - delete req.session.needUpdate;  
77 - return res.json({  
78 - code: 200,  
79 - data: '密码修改成功' 75 + updatePwd(req, res) {
  76 + if (!req.user.uid) {
  77 + return res.status(401).json({
  78 + code: 401,
  79 + message: '抱歉,您暂未登录!',
  80 + data: {
  81 + refer: '/login'
  82 + }
  83 + });
  84 + }
  85 + if (!req.body.password) {
  86 + return res.json({
  87 + code: 400,
  88 + message: '请输入密码'
  89 + });
  90 + }
  91 + return this.userService.updatePwd(req.user.uid, req.body.password).then(result => {
  92 + if (result.code !== 200) {
  93 + return res.json(result);
  94 + }
  95 + delete req.session.needUpdate;
  96 + return res.json({
  97 + code: 200,
  98 + data: '密码修改成功'
  99 + });
80 }); 100 });
81 } 101 }
82 102
@@ -84,6 +104,7 @@ class UserController extends Context { @@ -84,6 +104,7 @@ class UserController extends Context {
84 delete req.session.USER; 104 delete req.session.USER;
85 delete req.session.LOGIN_UID; 105 delete req.session.LOGIN_UID;
86 delete req.session.CURRENT_SHOP; 106 delete req.session.CURRENT_SHOP;
  107 + delete req.session.needUpdate;
87 res.clearCookie('PHPSESSID', { 108 res.clearCookie('PHPSESSID', {
88 domain: '.yohobuy.com' 109 domain: '.yohobuy.com'
89 }); 110 });
@@ -14,17 +14,6 @@ module.exports = (req, res, next) => { @@ -14,17 +14,6 @@ module.exports = (req, res, next) => {
14 } 14 }
15 }); 15 });
16 } 16 }
17 - if (req.session.needUpdate &&  
18 - req.path !== '/Api/erp/getPurview' &&  
19 - req.path !== '/Api/erp/update') {  
20 - return res.status(403).json({  
21 - code: 403,  
22 - message: '抱歉,您暂未修改密码!',  
23 - data: {  
24 - refer: '/password'  
25 - }  
26 - });  
27 - }  
28 17
29 next(); 18 next();
30 }; 19 };
@@ -31,6 +31,13 @@ class UserService extends Context { @@ -31,6 +31,13 @@ class UserService extends Context {
31 return userInfo.data; 31 return userInfo.data;
32 }); 32 });
33 } 33 }
  34 + updatePwd(pid, password) {
  35 + return this.api.post(config.apiDomain.erp.update, {
  36 + pid,
  37 + password,
  38 + });
  39 + }
  40 +
34 41
35 shopLogin(account, password) { 42 shopLogin(account, password) {
36 return rp.get({ 43 return rp.get({