reset.js
1.6 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
/*
* @Author: Targaryen
* @Date: 2017-04-13 10:21:07
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-17 15:52:03
*/
/* ********************
* 重置密码
**********************/
'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.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);
};
module.exports = {
passwordResetPage,
passwordReset
};