...
|
...
|
@@ -5,19 +5,30 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const library = '../../../library';
|
|
|
const helpers = require(`${library}/helpers`);
|
|
|
const service = require('../models/back-service');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const service = require('../models/back-service');
|
|
|
const passportHelper = require('../models/passport-helper');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
// 本地地址 localhost
|
|
|
helpers.urlFormat = helpers.fakeUrlFormat;
|
|
|
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;
|
|
|
//
|
|
|
//};
|
|
|
|
|
|
/**
|
|
|
* 找回密码主页面
|
|
|
*/
|
|
|
const indexPage = (req, res, next) => {
|
|
|
const index = (req, res, next) => {
|
|
|
service.indexPageDataAsync()
|
|
|
.then(result => {
|
|
|
res.render('back/index', Object.assign({
|
...
|
...
|
@@ -34,12 +45,11 @@ const indexPage = (req, res, next) => { |
|
|
*/
|
|
|
const validateInputAPI = (req, res, next) => {
|
|
|
let userInput = req.body.phoneNum || '';
|
|
|
let areaCode = (req.body.area || '86').replace('+', '');
|
|
|
let areaCode = (req.body.area || '86').replace('+', '');
|
|
|
|
|
|
service.validateEmailOrMobileAsync(userInput, areaCode)
|
|
|
.then(result => {
|
|
|
req.inputInfo = result;
|
|
|
console.log(result);
|
|
|
next();
|
|
|
})
|
|
|
.catch(err => {
|
...
|
...
|
@@ -55,7 +65,7 @@ const validateInputAPI = (req, res, next) => { |
|
|
*/
|
|
|
const validateUserPage = (req, res, next) => {
|
|
|
let userInput = req.body.phoneNum || '';
|
|
|
let areaCode = (req.body.area || '86').replace('+', '');
|
|
|
let areaCode = (req.body.area || '86').replace('+', '');
|
|
|
|
|
|
service.validateEmailOrMobileAsync(userInput, areaCode)
|
|
|
.then(result => {
|
...
|
...
|
@@ -63,7 +73,7 @@ const validateUserPage = (req, res, next) => { |
|
|
next();
|
|
|
})
|
|
|
.catch(()=> {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -82,16 +92,14 @@ const sendCodePage = (req, res, next) => { |
|
|
|
|
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
if (_.isEmpty(result)) {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
|
|
|
if (result.code && result.code === 200) {
|
|
|
return next();
|
|
|
} else {
|
|
|
next();
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
})
|
|
|
.catch(() => {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
});
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
const saveInSession = (req, res) => {
|
...
|
...
|
@@ -99,24 +107,27 @@ const saveInSession = (req, res) => { |
|
|
case 'email':
|
|
|
{
|
|
|
req.session.email = req.inputInfo.phone;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/sendEmail.html'));
|
|
|
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.html'));
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
{
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const sendBackMobileAPI = (req, res, next) => {
|
|
|
let mobile = req.body.mobile || '';
|
|
|
let area = req.body.area || '86';
|
|
|
|
|
|
service.sendCodeToMobileAsync(area, mobile)
|
|
|
.then(result => {
|
|
|
res.json(result);
|
...
|
...
|
@@ -126,15 +137,13 @@ const sendBackMobileAPI = (req, res, next) => { |
|
|
|
|
|
const validateMobileAPI = (req, res, next) => {
|
|
|
let mobile = req.body.mobile || '';
|
|
|
|
|
|
let area = req.body.area || '86';
|
|
|
|
|
|
const ERR = {code: 400, message: '验证失败'};
|
|
|
|
|
|
if (!helpers.verifyAreaMobile(helpers.makeAreaMobile(area, mobile))) {
|
|
|
res.json(ERR);
|
|
|
if (!passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(area, mobile))) {
|
|
|
return res.json(ERR);
|
|
|
} else {
|
|
|
next();
|
|
|
return next();
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -142,7 +151,7 @@ const validateEmailInSession = (req, res, next) => { |
|
|
let email = req.session.email || '';
|
|
|
|
|
|
if (!email) {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
const mapperEmailISP = {
|
...
|
...
|
@@ -161,7 +170,7 @@ const sendEmailPage = (req, res, next) => { |
|
|
res.render('back/send-email', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-send-email-ok',
|
|
|
title : "邮件发送成功"
|
|
|
title : '邮件发送成功'
|
|
|
}, {
|
|
|
sendEmail: {
|
|
|
coverHref: result.url,
|
...
|
...
|
@@ -169,7 +178,8 @@ const sendEmailPage = (req, res, next) => { |
|
|
email : req.body.emailUrl
|
|
|
}
|
|
|
}));
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
|
|
|
};
|
|
|
|
...
|
...
|
@@ -183,11 +193,11 @@ const validateCodeByEmailPage = (req, res, next) => { |
|
|
|
|
|
service.checkEmailCodeAsync(code)
|
|
|
.then(result => {
|
|
|
if (result) {
|
|
|
next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
if (!result) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
return next();
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
...
|
...
|
@@ -207,7 +217,7 @@ const resetPasswordPage = (req, res, next) => { |
|
|
coverImg : result.img,
|
|
|
code : code
|
|
|
}, req.mobileAuth)
|
|
|
}))
|
|
|
}));
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
...
|
...
|
@@ -216,6 +226,11 @@ const resetPasswordPage = (req, res, next) => { |
|
|
* 手机验证页面
|
|
|
*/
|
|
|
const verifyCodeByMobilePage = (req, res, next) => {
|
|
|
|
|
|
req.body.mobile = '15062219934';
|
|
|
req.body.area = '86';
|
|
|
req.body.verifyCode = '8933';
|
|
|
|
|
|
passportHelper.getLeftBannerAsync()
|
|
|
.then(result => {
|
|
|
res.render('back/verification', Object.assign({
|
...
|
...
|
@@ -242,7 +257,7 @@ const checkSuccessStatusPage = (req, res, next) => { |
|
|
delete req.session.successType;
|
|
|
next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -258,27 +273,26 @@ const resetPwdSuccessPage = (req, res, next) => { |
|
|
coverHref: result.url,
|
|
|
coverImg : result.img
|
|
|
}
|
|
|
}))
|
|
|
}));
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
const verifyCodeByMobileAPI = (req, res) => {
|
|
|
let mobile = req.param('mobile', '');
|
|
|
let area = req.param('area', '86');
|
|
|
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,
|
|
|
message: '验证码错误!',
|
|
|
data : helpers.urlFormat('/passport/back/index.html')
|
|
|
data : helpers.urlFormat('/passport/back/index')
|
|
|
};
|
|
|
|
|
|
if (!code || mobile !== session.mobile || area !== session.area) {
|
|
|
res.json(ERR);
|
|
|
return;
|
|
|
}
|
|
|
// if (!code || mobile !== session.mobile || area !== session.area) {
|
|
|
// return res.json(ERR);
|
|
|
// }
|
|
|
|
|
|
service.verifyCodyByMobileAsync(area, mobile, mobileCode)
|
|
|
.then(result => {
|
...
|
...
|
@@ -293,14 +307,14 @@ const validateExistCodePage = (req, res, next) => { |
|
|
let code = req.param('code', '');
|
|
|
|
|
|
if (!code) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
const validateCodeByMobilePage = (req, res, next) => {
|
|
|
let code = req.param('code', '');
|
|
|
let code = req.param('code', '');
|
|
|
let mobile = req.param('mobile', '');
|
|
|
|
|
|
if (!mobile) {
|
...
|
...
|
@@ -316,8 +330,10 @@ const validateCodeByMobilePage = (req, res, next) => { |
|
|
create_time: req.param('create_time', 0)
|
|
|
};
|
|
|
|
|
|
code = new Buffer(code, 'base64').toString();
|
|
|
code = new Buffer(code, 'base64').toString();
|
|
|
|
|
|
req.mobileAuth = service.authRequest(data, code);
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
...
|
...
|
@@ -327,41 +343,46 @@ const validatePwdPage = (req, res, next) => { |
|
|
if (helpers.isPassword(pwd)) {
|
|
|
next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const updatePwdAPI = (req, res, next) => {
|
|
|
let code = req.body.code || '';
|
|
|
let mobileAuth = req.mobileAuth;
|
|
|
let newPassword = req.body.pwd;
|
|
|
let code = req.body.code || '';
|
|
|
let mobileAuth = req.mobileAuth || {};
|
|
|
let newPassword = req.body.pwd || '';
|
|
|
|
|
|
service.updatePwdAsync(code, mobileAuth, newPassword)
|
|
|
.then(result => {
|
|
|
if (result.status) {
|
|
|
req.session.successType = result.type;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/resetSuccess.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/resetSuccess'));
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
const validateMobileInSession = (req, res, next) => {
|
|
|
req.body.mobile = req.session.mobile || "";
|
|
|
req.body.verifyCode = req.session.verifyCode || "";
|
|
|
req.body.area = req.session.area || "";
|
|
|
|
|
|
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) {
|
|
|
next()
|
|
|
return next();
|
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
indexPage,
|
|
|
index,
|
|
|
validateInputAPI,
|
|
|
validateUserPage,
|
|
|
getUserInfoAPI,
|
...
|
...
|
|