...
|
...
|
@@ -8,6 +8,7 @@ |
|
|
|
|
|
const mcHandler = require('../models/menu-crumb-handler');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const config = global.yoho.config;
|
|
|
const settingModel = require('../models/setting');
|
|
|
const accountModel = require('../models/account');
|
|
|
const passportHelper = require('../../passport/models/passport-helper');
|
...
|
...
|
@@ -18,13 +19,15 @@ var path = require('path'); |
|
|
const uuid = require('uuid');
|
|
|
const os = require('os');
|
|
|
const _ = require('lodash');
|
|
|
const regMobile = /(\d{3})\d{4}(\d{4})/;// 正则匹配替换手机号码中间4位
|
|
|
const regEmail = /(\d{3})\d{4}/;// 正则匹配替换邮箱中间4位
|
|
|
const regMobile = /(\d{3})\d{4}(\d{4})/; // 正则匹配替换手机号码中间4位
|
|
|
const regEmail = /(\d{3})\d{4}/; // 正则匹配替换邮箱中间4位
|
|
|
|
|
|
const captchaUrl = helpers.urlFormat('/passport/images', {t: Date.now()});
|
|
|
const captchaUrl = helpers.urlFormat('/passport/images', {
|
|
|
t: Date.now()
|
|
|
});
|
|
|
|
|
|
// 根据type获取标题
|
|
|
const _getTitle = (type)=> {
|
|
|
const _getTitle = (type) => {
|
|
|
let typeName;
|
|
|
let proName;
|
|
|
let isModifyMobile = false;
|
...
|
...
|
@@ -74,6 +77,18 @@ const _getTitle = (type)=> { |
|
|
};
|
|
|
};
|
|
|
|
|
|
const cookieHelper = {
|
|
|
setVal(res, k, v, ops) {
|
|
|
res.cookie(k, v, Object.assign({
|
|
|
domain: config.cookieDomain,
|
|
|
httpOnly: true
|
|
|
}, ops));
|
|
|
},
|
|
|
getVal(req, k) {
|
|
|
return req.cookies[k];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 个人设置页面加载
|
|
|
*/
|
...
|
...
|
@@ -132,11 +147,11 @@ const index = (req, res, next) => { |
|
|
* @param res
|
|
|
* @param next
|
|
|
*/
|
|
|
const editUserInfo = (req, res, next)=> {
|
|
|
const editUserInfo = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let query = req.body;
|
|
|
|
|
|
settingModel.editUserInfo(uid, query).then(result=> {
|
|
|
settingModel.editUserInfo(uid, query).then(result => {
|
|
|
res.send(result);
|
|
|
}).catch(next);
|
|
|
};
|
...
|
...
|
@@ -149,13 +164,13 @@ const bindMobile = (req, res, next) => { |
|
|
let uid = req.user.uid;
|
|
|
let type = req.params.type;
|
|
|
|
|
|
settingModel.getUserInfo(uid).then(result=> {
|
|
|
settingModel.getUserInfo(uid).then(result => {
|
|
|
if (result.info.verify_mobile !== '') {
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
let info = result.info;
|
|
|
|
|
|
info.ellipsisMobile = info.verify_mobile.replace(regMobile, '$1****$2');
|
|
|
info.checkCode = settingModel.cipheriv(info.uid + '.completeverify');
|
|
|
info.checkCode = req.csrfToken();
|
|
|
|
|
|
res.display('index', {
|
|
|
module: 'me',
|
...
|
...
|
@@ -188,12 +203,12 @@ const bindEmail = (req, res, next) => { |
|
|
let uid = req.user.uid;
|
|
|
let type = req.params.type;
|
|
|
|
|
|
settingModel.getUserInfo(uid).then(result=> {
|
|
|
settingModel.getUserInfo(uid).then(result => {
|
|
|
if (result.info.verify_email !== '') {
|
|
|
let info = result.info;
|
|
|
|
|
|
info.ellipsisEmail = info.verify_email.replace(regEmail, '$1****');
|
|
|
info.checkCode = settingModel.cipheriv(info.uid + '.completeverify');
|
|
|
info.checkCode = req.csrfToken();
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
...
|
...
|
@@ -221,9 +236,8 @@ const bindEmail = (req, res, next) => { |
|
|
/**
|
|
|
*step1 登录密码进行身份验证
|
|
|
*/
|
|
|
const modifyPassword = (req, res) => {
|
|
|
const modifyType = (req, res) => {
|
|
|
let type = req.params.type;
|
|
|
let checkCode = settingModel.cipheriv(req.user.uid + '.completeverify');
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
...
|
...
|
@@ -239,7 +253,7 @@ const modifyPassword = (req, res) => { |
|
|
proTitle: _getTitle(type).proName,
|
|
|
captchaUrl: captchaUrl,
|
|
|
isShowPassword: true,
|
|
|
checkCode: checkCode
|
|
|
checkCode: req.csrfToken()
|
|
|
}
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -248,103 +262,107 @@ const modifyPassword = (req, res) => { |
|
|
/*
|
|
|
* step2 操作界面-渲染页面
|
|
|
* */
|
|
|
const edit = (req, res)=> {
|
|
|
const edit = (req, res) => {
|
|
|
let type = req.params.type;
|
|
|
let code = settingModel.decipheriv(req.query.checkCode.split(' ').join('+'));
|
|
|
let codes = code.split('.');
|
|
|
|
|
|
if (parseInt(codes[0], 10) === req.user.uid && codes[1] === 'completeverify') {
|
|
|
let result = {
|
|
|
title: _getTitle(type).typeName,
|
|
|
proTitle: _getTitle(type).proName,
|
|
|
isShowMobile: _getTitle(type).isModifyMobile || _getTitle(type).isBindMobile,
|
|
|
isShowEmail: _getTitle(type).isModifyEmail || _getTitle(type).isBindEmail,
|
|
|
isShowPassword: _getTitle(type).isShowPassword
|
|
|
};
|
|
|
let checkCode = settingModel.cipheriv(req.user.uid + '.completeoperate');
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
|
|
module: 'me',
|
|
|
page: 'setting',
|
|
|
isMe: true,
|
|
|
content: Object.assign({
|
|
|
region: passportHelper.getCountry(),
|
|
|
location: '+86',
|
|
|
nav: mcHandler.getMeCrumb('个人设置'),
|
|
|
navigation: mcHandler.getSideMenu('个人设置'),
|
|
|
banner: thumb,
|
|
|
operateStep: true,
|
|
|
stepUrl: '/me/setting/step3/' + type,
|
|
|
captchaUrl: captchaUrl,
|
|
|
checkCode: checkCode
|
|
|
}, result)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (Number(cookieHelper.getVal(req, type + "_STEP")) !== 1) {
|
|
|
res.redirect(helpers.urlFormat('/me/setting/step1/' + type));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let result = {
|
|
|
title: _getTitle(type).typeName,
|
|
|
proTitle: _getTitle(type).proName,
|
|
|
isShowMobile: _getTitle(type).isModifyMobile || _getTitle(type).isBindMobile,
|
|
|
isShowEmail: _getTitle(type).isModifyEmail || _getTitle(type).isBindEmail,
|
|
|
isShowPassword: _getTitle(type).isShowPassword
|
|
|
};
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
|
|
module: 'me',
|
|
|
page: 'setting',
|
|
|
isMe: true,
|
|
|
content: Object.assign({
|
|
|
region: passportHelper.getCountry(),
|
|
|
location: '+86',
|
|
|
nav: mcHandler.getMeCrumb('个人设置'),
|
|
|
navigation: mcHandler.getSideMenu('个人设置'),
|
|
|
banner: thumb,
|
|
|
operateStep: true,
|
|
|
stepUrl: '/me/setting/step3/' + type,
|
|
|
captchaUrl: captchaUrl,
|
|
|
checkCode: req.csrfToken()
|
|
|
}, result)
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* step3 操作成功-渲染界面
|
|
|
* */
|
|
|
const success = (req, res)=> {
|
|
|
const success = (req, res) => {
|
|
|
let type = req.params.type;
|
|
|
let code = settingModel.decipheriv(req.query.checkCode.split(' ').join('+'));
|
|
|
let codes = code.split('.');
|
|
|
|
|
|
if (parseInt(codes[0], 10) === req.user.uid && codes[1] === 'completeoperate') {
|
|
|
let result = {
|
|
|
title: _getTitle(type).typeName,
|
|
|
proTitle: _getTitle(type).proName,
|
|
|
isModifyMobile: _getTitle(type).isModifyMobile,
|
|
|
isBindMobile: _getTitle(type).isBindMobile,
|
|
|
isModifyEmail: _getTitle(type).isModifyEmail,
|
|
|
isBindEmail: _getTitle(type).isBindEmail,
|
|
|
isShowPassword: _getTitle(type).isShowPassword
|
|
|
};
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
|
|
module: 'me',
|
|
|
page: 'setting',
|
|
|
isMe: true,
|
|
|
content: Object.assign({
|
|
|
region: passportHelper.getCountry(),
|
|
|
location: '+86',
|
|
|
nav: mcHandler.getMeCrumb('个人设置'),
|
|
|
navigation: mcHandler.getSideMenu('个人设置'),
|
|
|
banner: thumb,
|
|
|
successStep: true,
|
|
|
captchaUrl: captchaUrl
|
|
|
}, result)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
let step = Number(cookieHelper.getVal(req, type + "_STEP")) || 0;
|
|
|
if (step !== 2) {
|
|
|
res.redirect(helpers.urlFormat('/me/setting/step' + (step + 1) + '/' + type));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
cookieHelper.setVal(res, type + "_STEP", 0, {
|
|
|
maxAge: -1
|
|
|
});
|
|
|
|
|
|
let result = {
|
|
|
title: _getTitle(type).typeName,
|
|
|
proTitle: _getTitle(type).proName,
|
|
|
isModifyMobile: _getTitle(type).isModifyMobile,
|
|
|
isBindMobile: _getTitle(type).isBindMobile,
|
|
|
isModifyEmail: _getTitle(type).isModifyEmail,
|
|
|
isBindEmail: _getTitle(type).isBindEmail,
|
|
|
isShowPassword: _getTitle(type).isShowPassword
|
|
|
};
|
|
|
|
|
|
mcHandler.getMeThumb().then((thumb) => {
|
|
|
res.display('index', {
|
|
|
module: 'me',
|
|
|
page: 'setting',
|
|
|
isMe: true,
|
|
|
content: Object.assign({
|
|
|
region: passportHelper.getCountry(),
|
|
|
location: '+86',
|
|
|
nav: mcHandler.getMeCrumb('个人设置'),
|
|
|
navigation: mcHandler.getSideMenu('个人设置'),
|
|
|
banner: thumb,
|
|
|
successStep: true,
|
|
|
captchaUrl: captchaUrl
|
|
|
}, result)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* post1 第一步身份验证的post请求
|
|
|
* */
|
|
|
const validate1 = (req, res)=> {
|
|
|
co(function *() {
|
|
|
const validate1 = (req, res) => {
|
|
|
co(function*() {
|
|
|
let type = req.params.type;
|
|
|
let uid = req.user.uid;
|
|
|
let body = req.body;
|
|
|
let a;
|
|
|
|
|
|
if (type === 'password') {
|
|
|
let a = yield accountModel.verifyPwd(uid, body.password);
|
|
|
|
|
|
res.send(a);
|
|
|
a = yield accountModel.verifyPwd(uid, body.password);
|
|
|
} else if (type === 'mobile') {
|
|
|
let a = yield accountModel.checkVerifyMsg(body.code, body.mobile, body.area);
|
|
|
|
|
|
|
|
|
res.send(a);
|
|
|
a = yield accountModel.checkVerifyMsg(body.code, body.mobile, body.area);
|
|
|
} else if (type === 'email') {
|
|
|
let a = yield accountModel.sendVerifyEmail(uid, body.email);
|
|
|
a = yield accountModel.sendVerifyEmail(uid, body.email);
|
|
|
}
|
|
|
|
|
|
if (a) {
|
|
|
cookieHelper.setVal(res, req.body.type + "_STEP", 1);
|
|
|
res.send(a);
|
|
|
}
|
|
|
})();
|
...
|
...
|
@@ -353,8 +371,8 @@ const validate1 = (req, res)=> { |
|
|
/*
|
|
|
* post2 第二步具体操作的post请求
|
|
|
* */
|
|
|
const validate2 = (req, res)=> {
|
|
|
co(function *() {
|
|
|
const validate2 = (req, res) => {
|
|
|
co(function*() {
|
|
|
let type = req.params.type;
|
|
|
let uid = req.user.uid;
|
|
|
let body = req.body;
|
...
|
...
|
@@ -362,18 +380,24 @@ const validate2 = (req, res)=> { |
|
|
if (type === 'password') {
|
|
|
let a = yield accountModel.changePwd(uid, body.password);
|
|
|
|
|
|
res.send(a);
|
|
|
if (a.code === 200) {
|
|
|
cookieHelper.setVal(res, body.type + "_STEP", 2);
|
|
|
res.send(a);
|
|
|
}
|
|
|
|
|
|
} else if (type === 'mobile') {
|
|
|
let a = yield accountModel.checkVerifyMsg(body.code, body.mobile, body.area);
|
|
|
let b = yield accountModel.modifyVerifyMobile(uid, body.area, body.mobile);
|
|
|
let msg = [];
|
|
|
|
|
|
if (a.code === 200 && b.code === 200) {
|
|
|
cookieHelper.setVal(res, body.type + "_STEP", 2);
|
|
|
res.send({
|
|
|
code: 200,
|
|
|
data: {}
|
|
|
});
|
|
|
} else {
|
|
|
let msg = [];
|
|
|
|
|
|
if (a.code !== 200) {
|
|
|
msg.push('<p>图片验证:' + a.message + '</p>');
|
|
|
}
|
...
|
...
|
@@ -413,12 +437,12 @@ function getfilePath(req, res, next) { |
|
|
* @param req
|
|
|
* @param res
|
|
|
*/
|
|
|
const modifyHead = (req, res)=> {
|
|
|
const modifyHead = (req, res) => {
|
|
|
let uid = req.user.uid;
|
|
|
let bucket = 'yhb-head';
|
|
|
let filePath = req.filePath;
|
|
|
|
|
|
settingModel.modifyHead(uid, bucket, filePath).then(result=> {
|
|
|
settingModel.modifyHead(uid, bucket, filePath).then(result => {
|
|
|
res.send(result);
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -428,11 +452,11 @@ module.exports = { |
|
|
editUserInfo,
|
|
|
bindMobile,
|
|
|
bindEmail,
|
|
|
modifyPassword,
|
|
|
modifyType,
|
|
|
edit,
|
|
|
success,
|
|
|
validate1,
|
|
|
validate2,
|
|
|
getfilePath,
|
|
|
modifyHead
|
|
|
}; |
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|