back.js
2.28 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
/**
* 找回密码
* Created by Tao.Huang on 2016/6/12.
*/
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const service = require('../models/back-service');
// 本地地址 localhost
helpers.urlFormat = helpers.fakeUrlFormat;
const SIGN_IN_URL = helpers.urlFormat('/signin.html');
/**
* 找回密码主页面
*/
module.exports.indexPage = (req, res) => {
service.indexPageDataAsync().then(result => {
res.render('back/index', Object.assign({
module: 'back',
page: 'index',
title: '找回密码'
}, result));
});
};
/**
* 校验用户输入信息,是否是已经注册的用户
*/
module.exports.identifyUserByInputAPI = (req, res) => {
let userInput = req.body.phoneNum || '';
let areaCode = req.body.area || '86';
service.identifyUserByEmailOrMobileAsync(userInput, areaCode)
.then(result => {
res.json(result);
});
};
module.exports.sendCodeAPI = (req, res, next) => {
let userInput = req.body.phoneNum || '';
let areaCode = req.body.area || '86';
service.sendCodeToUserAsync(userInput, areaCode).then(result => {
switch (result) {
case 'mobile':
{
res.redirect('/passport/back/sendemail.html');
break;
}
case 'email':
{
res.redirect('/passport/back/verification.html');
break;
}
default:
{
res.redirect('./passport/back/index.html');
}
}
}).catch(next);
};
module.exports.verifyCodeByMobilePage = (req, res, next) => {
service.getVerifyCodeByMobilePageDataAsync()
.then(result => {
res.render('back/verification', Object.assign({
module: 'back',
page: 'verification',
title: '手机验证'
}, {
verification: {
coverHref: result.url,
coverImg: result.img,
mobile: result.mobile,
area: result.area,
verifyCode: result.verifyCode
}
}));
}).catch(next);
};