reset.js
2.08 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
/*
* @Author: Targaryen
* @Date: 2017-04-13 10:21:07
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-18 11:12:16
*/
/* ********************
* 重置密码
**********************/
'use strict';
const config = global.yoho.config;
const utils = require(global.utils);
const reset = require('../models/reset');
const passwordResetPage = (req, res) => {
let passwordWeakObj = req.session.passwordWeak;
let refer = req.cookies.refer;
if (refer) {
refer = decodeURI(req.cookies.refer);
} else {
refer = `${config.siteUrl}/home`;
}
if (/sign|login/.test(refer)) {
refer = `${config.siteUrl}/home`;
}
refer = utils.refererLimit(refer);
res.render('reset/password', {
width750: true,
module: 'passport',
page: 'reset',
pageStyle: 'passport-body',
title: '重置密码',
canSkip: passwordWeakObj.canSkip === 'Y' ? refer : false
});
};
/**
* 重置密码
* @param {*} req
* @param {*} res
* @param {*} next
*/
const passwordReset = (req, res, next) => {
let passwordWeakObj = req.session.passwordWeak;
let uid = req.user && req.user.uid || passwordWeakObj.uid;
if (!uid || !passwordWeakObj.token) {
return res.json({
code: 400,
massage: '非法请求'
});
}
req.session.passwordWeak = null;
reset.resetPassword({
uid: uid,
oldPwd: req.body.oldPwd,
newPwd: req.body.newPwd,
token: passwordWeakObj.token
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 重置密码成功
* @param {*} req
* @param {*} res
*/
const passwordResetOkPage = (req, res) => {
res.clearCookie('_SPK');
res.cookie('_WX_PASS_LOGIN', true, {
domain: 'm.yohobuy.com'
});
res.render('reset/reset-success', {
width750: true,
module: 'passport',
page: 'reset-success',
pageStyle: 'passport-body',
title: '重置密码成功',
});
};
module.exports = {
passwordResetPage,
passwordReset,
passwordResetOkPage
};