back-new.js
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const _ = require('lodash');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
const backService = require('../models/back-service');
const SIGN_IN = helpers.urlFormat('/signin.html');
class BackNew {
/**
* 通过手机找回密码
*/
backByMobile(req, res, next) {
_.set(req.session, 'backupCaptch.verifyResult', false);
if (req.session.captchaValidCount == null) { // eslint-disable-line
req.session.captchaValidCount = 5;
}
co(function* () {
let countrysResult = yield backService.getAreaDataAsync(); // 地区信息列表
let countrys = _.get(countrysResult, 'data', []);
res.render('back/mobile-new', {
width750: true,
localCss: true,
module: 'passport',
page: 'back-mobile-new',
countrys: countrys,
});
})().catch(next);
}
/**
* 提交表单数据处理,设置新的密码
*/
setNewPasswordByMobileAPI(req, res, next) {
let phoneNum = req.body.phoneNum || '';
let code = req.body.code || '';
let areaCode = req.body.areaCode || '86';
let newPwd = req.body.password;
co(function* () {
let valiResult = yield backService.validateMobileCodeAsync(phoneNum, code, areaCode);
if (valiResult.code === 200) {
let token = _.get(valiResult, 'data.token', '');
let setPwdResult = yield backService.modifyPasswordByMobileAsyncAes(phoneNum, token, newPwd, areaCode);
if (setPwdResult.code === 200) {
res.json({
code: 200,
data: SIGN_IN
});
} else {
res.json({
code: 400,
message: '修改密码失败'
});
}
} else {
return res.json({
code: 400,
message: '验证码失败'
});
}
})().catch(next);
}
/**
* 通过邮箱找回密码
*/
backByEmail(req, res) {
res.render('back/email-new', {
width750: true,
localCss: true,
module: 'passport',
page: 'back-email-new'
});
}
/**
* 通过邮箱找回密码成功页
*/
backByEmailSuccess(req, res, next) {
let email = req.query.email || '';
if (!helpers.verifyEmail(email)) {
return next();
}
res.render('back/email-success-new', {
width750: true,
localCss: true,
module: 'passport',
page: 'back-email-success-new',
doneUrl: helpers.urlFormat('/signin.html'),
resendUrl: helpers.urlFormat('/passport/back/resendemail', { email: email })
});
}
}
module.exports = BackNew;