...
|
...
|
@@ -5,12 +5,11 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const library = '../../../library';
|
|
|
const helpers = require(`${library}/helpers`);
|
|
|
|
|
|
const service = require('../models/back-service');
|
|
|
const library = '../../../library';
|
|
|
const helpers = require(`${library}/helpers`);
|
|
|
const service = require('../models/back-service');
|
|
|
const passportHelper = require('../models/passport-helper');
|
|
|
const moment = require('moment');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
// 本地地址 localhost
|
|
|
helpers.urlFormat = helpers.fakeUrlFormat;
|
...
|
...
|
@@ -19,13 +18,15 @@ helpers.urlFormat = helpers.fakeUrlFormat; |
|
|
* 找回密码主页面
|
|
|
*/
|
|
|
module.exports.indexPage = (req, res, next) => {
|
|
|
service.indexPageDataAsync().then(result => {
|
|
|
res.render('back/index', Object.assign({
|
|
|
module: 'passport',
|
|
|
page: 'back-index',
|
|
|
title: '找回密码'
|
|
|
}, result));
|
|
|
}).catch(next);
|
|
|
service.indexPageDataAsync()
|
|
|
.then(result => {
|
|
|
res.render('back/index', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-index',
|
|
|
title : '找回密码'
|
|
|
}, result));
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -33,8 +34,7 @@ module.exports.indexPage = (req, res, next) => { |
|
|
*/
|
|
|
module.exports.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 => {
|
...
|
...
|
@@ -44,7 +44,7 @@ module.exports.validateInputAPI = (req, res, next) => { |
|
|
})
|
|
|
.catch(err => {
|
|
|
res.json({
|
|
|
code: 400,
|
|
|
code : 400,
|
|
|
message: err
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -55,8 +55,7 @@ module.exports.validateInputAPI = (req, res, next) => { |
|
|
*/
|
|
|
module.exports.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 => {
|
...
|
...
|
@@ -74,22 +73,25 @@ module.exports.getUserInfoAPI = (req, res, next) => { |
|
|
service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.sendCodePage = (req, res, next) => {
|
|
|
let inputInfo = req.inputInfo;
|
|
|
|
|
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area).then(result => {
|
|
|
if (_.isEmpty(result)) {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
} else {
|
|
|
next();
|
|
|
}
|
|
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
if (_.isEmpty(result)) {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
} else {
|
|
|
next();
|
|
|
}
|
|
|
|
|
|
}).catch(() => {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
});
|
|
|
})
|
|
|
.catch(() => {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports.saveInSession = (req, res) => {
|
...
|
...
|
@@ -103,7 +105,7 @@ module.exports.saveInSession = (req, res) => { |
|
|
case 'mobile':
|
|
|
{
|
|
|
req.session.mobile = req.inputInfo.phone;
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/verification.html'));
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -118,7 +120,8 @@ module.exports.sendBackMobileAPI = (req, res, next) => { |
|
|
service.sendCodeToMobileAsync(area, mobile)
|
|
|
.then(result => {
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.validateMobileAPI = (req, res, next) => {
|
...
|
...
|
@@ -157,13 +160,13 @@ module.exports.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
|
|
|
}
|
|
|
}));
|
|
|
}).catch(next);
|
...
|
...
|
@@ -185,7 +188,8 @@ module.exports.validateCodeByEmailPage = (req, res, next) => { |
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
}
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.resetPasswordPage = (req, res, next) => {
|
...
|
...
|
@@ -195,39 +199,40 @@ module.exports.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)
|
|
|
}))
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 手机验证页面
|
|
|
*/
|
|
|
module.exports.verifyCodeByMobilePage = (req, res, next) => {
|
|
|
|
|
|
passportHelper.getLeftBannerAsync()
|
|
|
.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
|
|
|
}
|
|
|
}));
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.checkSuccessStatusPage = (req, res, next) => {
|
...
|
...
|
@@ -246,31 +251,28 @@ module.exports.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
|
|
|
}
|
|
|
}))
|
|
|
}).catch(next);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.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,
|
|
|
code : 400,
|
|
|
message: '验证码错误!',
|
|
|
data: helpers.urlFormat('/passport/back/index.html')
|
|
|
data : helpers.urlFormat('/passport/back/index.html')
|
|
|
};
|
|
|
|
|
|
if (!code || mobile !== session.mobile || area !== session.area) {
|
...
|
...
|
@@ -298,8 +300,7 @@ module.exports.validateExistCodePage = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
module.exports.validateCodeByMobilePage = (req, res, next) => {
|
|
|
let code = req.param('code', '');
|
|
|
|
|
|
let code = req.param('code', '');
|
|
|
let mobile = req.param('mobile', '');
|
|
|
|
|
|
if (!mobile) {
|
...
|
...
|
@@ -309,13 +310,13 @@ module.exports.validateCodeByMobilePage = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
let data = {
|
|
|
mobile: mobile,
|
|
|
area: req.param('area', ''),
|
|
|
token: req.param('token', ''),
|
|
|
mobile : mobile,
|
|
|
area : req.param('area', ''),
|
|
|
token : req.param('token', ''),
|
|
|
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();
|
|
|
};
|
...
|
...
|
@@ -330,11 +331,9 @@ module.exports.validatePwdPage = (req, res, next) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports.updatePwdAPI = (req, res) => {
|
|
|
let code = req.body.code || '';
|
|
|
|
|
|
let mobileAuth = req.mobileAuth;
|
|
|
|
|
|
module.exports.updatePwdAPI = (req, res, next) => {
|
|
|
let code = req.body.code || '';
|
|
|
let mobileAuth = req.mobileAuth;
|
|
|
let newPassword = req.body.pwd;
|
|
|
|
|
|
service.updatePwdAsync(code, mobileAuth, newPassword)
|
...
|
...
|
@@ -345,13 +344,14 @@ module.exports.updatePwdAPI = (req, res) => { |
|
|
} else {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
}
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
module.exports.validateMobileInSession = (req, res, next) => {
|
|
|
req.body.mobile = req.session.mobile || "";
|
|
|
req.body.mobile = req.session.mobile || "";
|
|
|
req.body.verifyCode = req.session.verifyCode || "";
|
|
|
req.body.area = req.session.area || "";
|
|
|
req.body.area = req.session.area || "";
|
|
|
|
|
|
if (req.body.mobile && req.body.verifyCode) {
|
|
|
next()
|
...
|
...
|
@@ -359,3 +359,4 @@ module.exports.validateMobileInSession = (req, res, next) => { |
|
|
res.redirect(helpers.urlFormat('/passport/back/index.html'));
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|