...
|
...
|
@@ -10,20 +10,20 @@ const service = require('../models/back-service'); |
|
|
const passportHelper = require('../models/passport-helper');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
//helpers.urlFormat = (url, qs) => {
|
|
|
// let localhost = 'http://localhost:6002';
|
|
|
//
|
|
|
// if (_.isEmpty(qs)) {
|
|
|
// return localhost + url;
|
|
|
// }
|
|
|
//
|
|
|
// const queryString = require('queryString');
|
|
|
//
|
|
|
// let str = queryString.stringify(qs);
|
|
|
//
|
|
|
// return localhost + url + '?' + str;
|
|
|
//
|
|
|
//};
|
|
|
helpers.urlFormat = (url, qs) => {
|
|
|
let localhost = 'http://localhost:6002';
|
|
|
|
|
|
if (_.isEmpty(qs)) {
|
|
|
return localhost + url;
|
|
|
}
|
|
|
|
|
|
const queryString = require('queryString');
|
|
|
|
|
|
let str = queryString.stringify(qs);
|
|
|
|
|
|
return localhost + url + '?' + str;
|
|
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 找回密码主页面
|
...
|
...
|
@@ -33,8 +33,8 @@ const index = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/index', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-index',
|
|
|
title : '找回密码'
|
|
|
page: 'back-index',
|
|
|
title: '找回密码'
|
|
|
}, result));
|
|
|
})
|
|
|
.catch(next);
|
...
|
...
|
@@ -54,7 +54,7 @@ const validateInputAPI = (req, res, next) => { |
|
|
})
|
|
|
.catch(err => {
|
|
|
res.json({
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: err
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -93,11 +93,11 @@ const sendCodePage = (req, res, next) => { |
|
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
|
|
|
if (result.code && result.code === 200) {
|
|
|
return next();
|
|
|
} else {
|
|
|
if (!(result.code && result.code === 200)) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
return next();
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
...
|
...
|
@@ -105,22 +105,22 @@ const sendCodePage = (req, res, next) => { |
|
|
const saveInSession = (req, res) => {
|
|
|
switch (req.inputInfo.type) {
|
|
|
case 'email':
|
|
|
{
|
|
|
req.session.email = req.inputInfo.phone;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
|
|
|
break;
|
|
|
}
|
|
|
{
|
|
|
req.session.email = req.inputInfo.phone;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
|
|
|
break;
|
|
|
}
|
|
|
case 'mobile':
|
|
|
{
|
|
|
req.session.mobile = req.inputInfo.phone;
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
break;
|
|
|
}
|
|
|
{
|
|
|
req.session.mobile = req.inputInfo.phone;
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
{
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
{
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -142,24 +142,23 @@ const validateMobileAPI = (req, res, next) => { |
|
|
|
|
|
if (!passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(area, mobile))) {
|
|
|
return res.json(ERR);
|
|
|
} else {
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
const validateEmailInSession = (req, res, next) => {
|
|
|
let email = req.session.email || '';
|
|
|
|
|
|
if (!email) {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
let isp = email.split('@')[1];
|
|
|
const mapperEmailISP = {
|
|
|
'yoho.cn': 'http://smail.yoho.cn'
|
|
|
};
|
|
|
|
|
|
let isp = email.split('@')[1];
|
|
|
|
|
|
req.body.emailUrl = mapperEmailISP[isp] || `http://mail.${isp}`;
|
|
|
next();
|
|
|
};
|
...
|
...
|
@@ -169,13 +168,13 @@ const sendEmailPage = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/send-email', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-send-email-ok',
|
|
|
title : '邮件发送成功'
|
|
|
page: 'back-send-email-ok',
|
|
|
title: '邮件发送成功'
|
|
|
}, {
|
|
|
sendEmail: {
|
|
|
coverHref: result.url,
|
|
|
coverImg : result.img,
|
|
|
email : req.body.emailUrl
|
|
|
coverImg: result.img,
|
|
|
email: req.body.emailUrl
|
|
|
}
|
|
|
}));
|
|
|
})
|
...
|
...
|
@@ -187,8 +186,7 @@ const validateCodeByEmailPage = (req, res, next) => { |
|
|
let code = req.query.code || '';
|
|
|
|
|
|
if (!_.isEmpty(req.mobileAuth)) {
|
|
|
next();
|
|
|
return;
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
service.checkEmailCodeAsync(code)
|
...
|
...
|
@@ -209,13 +207,13 @@ const resetPasswordPage = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/reset-pwd', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-reset-pwd',
|
|
|
title : '重置密码'
|
|
|
page: 'back-reset-pwd',
|
|
|
title: '重置密码'
|
|
|
}, {
|
|
|
resetPwd: Object.assign({
|
|
|
coverHref: result.url,
|
|
|
coverImg : result.img,
|
|
|
code : code
|
|
|
coverImg: result.img,
|
|
|
code: code
|
|
|
}, req.mobileAuth)
|
|
|
}));
|
|
|
})
|
...
|
...
|
@@ -235,14 +233,14 @@ const verifyCodeByMobilePage = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/verification', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-verify-mobile-code',
|
|
|
title : '手机验证'
|
|
|
page: 'back-verify-mobile-code',
|
|
|
title: '手机验证'
|
|
|
}, {
|
|
|
verification: {
|
|
|
coverHref : result.url,
|
|
|
coverImg : result.img,
|
|
|
mobile : req.body.mobile,
|
|
|
area : req.body.area,
|
|
|
coverHref: result.url,
|
|
|
coverImg: result.img,
|
|
|
mobile: req.body.mobile,
|
|
|
area: req.body.area,
|
|
|
verifyCode: req.body.verifyCode
|
|
|
}
|
|
|
}));
|
...
|
...
|
@@ -253,12 +251,12 @@ const verifyCodeByMobilePage = (req, res, next) => { |
|
|
const checkSuccessStatusPage = (req, res, next) => {
|
|
|
let successType = req.session.successType || '';
|
|
|
|
|
|
if (successType) {
|
|
|
delete req.session.successType;
|
|
|
next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
if (!successType) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
delete req.session.successType;
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
const resetPwdSuccessPage = (req, res, next) => {
|
...
|
...
|
@@ -266,12 +264,12 @@ const resetPwdSuccessPage = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/reset-success', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-index',
|
|
|
title : '重置密码成功'
|
|
|
page: 'back-index',
|
|
|
title: '重置密码成功'
|
|
|
}, {
|
|
|
resetSuccess: {
|
|
|
coverHref: result.url,
|
|
|
coverImg : result.img
|
|
|
coverImg: result.img
|
|
|
}
|
|
|
}));
|
|
|
})
|
...
|
...
|
@@ -282,12 +280,13 @@ const verifyCodeByMobileAPI = (req, res) => { |
|
|
let mobile = req.param('mobile', '');
|
|
|
let area = req.param('area', '86');
|
|
|
let mobileCode = req.param('code', '');
|
|
|
const session = req.session;
|
|
|
|
|
|
// const session = req.session;
|
|
|
|
|
|
const ERR = {
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: '验证码错误!',
|
|
|
data : helpers.urlFormat('/passport/back/index')
|
|
|
data: helpers.urlFormat('/passport/back/index')
|
|
|
};
|
|
|
|
|
|
// if (!code || mobile !== session.mobile || area !== session.area) {
|
...
|
...
|
@@ -304,7 +303,7 @@ const verifyCodeByMobileAPI = (req, res) => { |
|
|
};
|
|
|
|
|
|
const validateExistCodePage = (req, res, next) => {
|
|
|
let code = req.param('code', '');
|
|
|
let code = req.query.code || req.body.code;
|
|
|
|
|
|
if (!code) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
...
|
...
|
@@ -314,24 +313,25 @@ const validateExistCodePage = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
const validateCodeByMobilePage = (req, res, next) => {
|
|
|
let code = req.param('code', '');
|
|
|
let mobile = req.param('mobile', '');
|
|
|
let code = req.query.code || req.body.code;
|
|
|
let mobile = req.query.mobile || req.body.mobile;
|
|
|
let area = req.query.area || req.body.area;
|
|
|
let token = req.query.token || req.body.token;
|
|
|
let createdAt = req.query.createdAt || req.body.createdAt;
|
|
|
|
|
|
if (!mobile) {
|
|
|
req.mobileAuth = {};
|
|
|
next();
|
|
|
return;
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
let data = {
|
|
|
mobile : mobile,
|
|
|
area : req.param('area', ''),
|
|
|
token : req.param('token', ''),
|
|
|
create_time: req.param('create_time', 0)
|
|
|
mobile: mobile,
|
|
|
area: area,
|
|
|
token: token,
|
|
|
createdAt: createdAt
|
|
|
};
|
|
|
|
|
|
code = new Buffer(code, 'base64').toString();
|
|
|
|
|
|
req.mobileAuth = service.authRequest(data, code);
|
|
|
|
|
|
next();
|
...
|
...
|
@@ -340,11 +340,11 @@ const validateCodeByMobilePage = (req, res, next) => { |
|
|
const validatePwdPage = (req, res, next) => {
|
|
|
let pwd = req.body.pwd || '';
|
|
|
|
|
|
if (helpers.isPassword(pwd)) {
|
|
|
next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
if (!passportHelper.validator.isPassword(pwd)) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
const updatePwdAPI = (req, res, next) => {
|
...
|
...
|
@@ -365,20 +365,15 @@ const updatePwdAPI = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
const validateMobileInSession = (req, res, next) => {
|
|
|
|
|
|
console.log(req.session.mobile);
|
|
|
console.log(req.session.area);
|
|
|
|
|
|
|
|
|
req.body.mobile = req.session.mobile || '';
|
|
|
req.body.verifyCode = req.session.verifyCode || '';
|
|
|
req.body.area = req.session.area || '';
|
|
|
|
|
|
if (req.body.mobile && req.body.verifyCode) {
|
|
|
return next();
|
|
|
} else {
|
|
|
if (!(req.body.mobile && req.body.verifyCode)) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|