Authored by wenjiekong

‘账号安全接口都写了

... ... @@ -15,6 +15,138 @@ const getVerifyInfo = uid => {
};
const checkEmailCode = code => {
return api.get('', {
method: 'web.passport.checkCodeValid',
code: code
});
};
const modifyVerifyEmail = code => {
return api.get('', {
method: 'web.passport.changeVerifyEmail',
code: code
});
};
const verifyPwd = (uid, password) => {
return api.get('', {
method: 'web.passport.verifyUserPwd',
uid: uid,
password: password
});
};
const checkVerifyMsg = (area, mobile, code) => {
return api.get('', {
method: 'web.passport.checkcode',
area: area,
mobile: mobile,
code: code
});
};
/**
* 邮箱身份验证--发送邮件
* @param type $email
* @param type $callback 成功后跳转链接
* @return type
*/
const sendVerifyEmailForNext = (email, callback) => {
return api.get('', {
method: 'web.passport.sendVerifyEmailInfo',
email: email,
callback: callback
});
};
/**
* 修改验证手机号
* @param type $uid
* @param type $area
* @param type $newMobile
* @return type
*/
const modifyVerifyMobile = (uid, area, newMobile) => {
return api.get('', {
method: 'web.passport.modifyVerifyMobile',
uid: uid,
area: area,
newMobile: newMobile
});
};
/**
* 修改邮箱前校验
* @param type $uid
* @param type $email
*/
const checkVerifyEmail = (uid, email) => {
return api.get('', {
method: 'web.passport.checkVerifyEmail',
uid: uid,
email: email
});
};
/**
* 验证邮箱--发送邮件
* @param type $uid
* @param type $email
* @return type
*/
const sendVerifyEmail = (uid, email) => {
return api.get('', {
method: 'web.passport.verifyEmail',
uid: uid,
email: email
});
};
/**
* 修改手机号前校验
* @param type $mobile
* @param type $area
* @return type
*/
const checkVerifyMobile = (uid, mobile, area) => {
return api.get('', {
method: 'web.passport.checkVerifyMobile',
uid: uid,
mobile: mobile,
area: area
});
};
/**
* 修改密码
* @param type $uid
* @param type $newPwd
* @return type
*/
const modifyPwd = (uid, newPwd) => {
return api.get('', {
method: 'web.passport.changePwd',
uid: uid,
newPwd: newPwd
});
};
module.exports = {
getVerifyInfo
getVerifyInfo,
checkEmailCode,
modifyVerifyEmail,
verifyPwd,
checkVerifyMsg,
sendVerifyEmailForNext,
checkVerifyEmail,
checkVerifyMobile,
sendVerifyEmail,
modifyVerifyMobile,
modifyPwd
};
... ...
... ... @@ -10,6 +10,7 @@
const _ = require('lodash');
const crypto = global.yoho.crypto;
const accountApi = require('./account-api');
const userApi = require('./user-api');
const headerModel = require('../../../doraemon/models/header');
// 时间转换为时间戳
... ... @@ -23,6 +24,26 @@
return parseInt(now.getTime() / 1000, 10);
}
/**
* 根据输入的mobile获取area
* @param type $mobile
* @return int
*/
function handleMobile(mobile) {
let res = {};
//国际号
if (mobile.indexOf("-") > 0) {
let areaTmp = mobile.split("-");
res.area = areaTmp[0];
res.mobile = areaTmp[1];
}else {
res.area = 86;
res.mobile = mobile;
}
return res;
}
/**
* 获得标题文案
... ... @@ -73,7 +94,7 @@
}], formData2 = [{// 只验证手机号
inputTxt: '已验证的手机号',
isVerify: true,
verifyAccount: data.mobile.slice(0, 2) + '****' + data.email.slice(6),
verifyAccount: data.mobile.slice(0, 3) + '****' + data.email.slice(7),
realAccount: data.mobile
}], formData3 = [{// 只验证邮箱
inputTxt: '已验证邮箱',
... ... @@ -559,37 +580,374 @@
/**
* 个人中心-邮箱验证身份-邮件发送成功过渡页
*/
// const sendEmailSuccess = (req, res, channel) => {
const sendEmailSuccess = (req, res, channel) => {
return co(function*() {
let checkType = req.body.checkType || 'userpwd',
email = req.body.email || '',
emailDomain = '',
type = req.body.email || 1;//1:身份验证 2:修改邮箱
let headerData = yield headerModel.requestHeaderData(channel);
// 验证信息
let verifyInfo = yield auditCheckStatus(uid, 'mobile', step);
// };
if (!verifyInfo.status) {
return {
headerData: headerData,
meValidatePage: true
};
}
emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
'mail.google.com' : 'mail.' + email.split[1]);
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
progressCur: (type === 1) ? 'progress1' : 'progress2',
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
],
returnInfo: true,
sendEmail: {
emailInfo: email.slice(0, 2) + '****' + email.slice(6),
emailUrl: emailDomain
}
};
if (type === 1) {
data.progress[0].iscur = true;
}
else {
data.progress[1].iscur = true;
}
let resqData = {meValidatePage: true};
resqData[verifyInfo.pageKey] = data;
return resqData;
})();
};
/**
* 分-验证图形验证码-ajax
* 点击邮箱验证链接方法--修改验证邮箱
*/
const checkVerifyCode = (req) => {
let code = _.trim(req.body.verifyCode || ''),
resqData = {};
const mailResult = (req, res) => {
return co(function*() {
let code = req.body.code;
// captchaCode = code.toLowerCase(),
let check = yield accountApi.checkEmailCode(code);
// if (!PassportModel::verifyCode($captchaCode)) {
// resqData.code = 400;
// resqData.message = '图形验证码不正确';
// }
// else {
resqData.code = code;
resqData.message = '';
if (check.code === 200) {
let data = yield accountApi.modifyVerifyEmail(code);
// }
if (data.code === 200) {
res.redirect(helpers.urlFormat('/home/account/email',
{step: 3,success: true}));
}
}
res.redirect(helpers.urlFormat('/home/account/email',
{step: 3,success: false}));
})();
};
/**
* 身份验证-登录密码验证Ajax
*/
const verifyPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.uid,
captchaCode = _.trim(req.body.verifyCode || '').toLowerCase();
if (captchaCode && captchaCode !== req.session.captcha) {
return {
code: 400,
message:'图形验证码不正确'
}
}
let data = yield accountApi.verifyPwd(uid, password);
if (data.code == 200) {
let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + password + captchaCode + 'completeverify');
data.data = checkCode;
}
return data;
})();
};
/**
* 分-验证密码正确性-ajax
*/
const checkPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.uid,
resqData = {code: 400};
resqData = yield accountApi.verifyPwd(uid, password);
return resqData;
})();
};
/**
* 分-验证图形验证码-ajax
*/
const checkVerifyCode = (req) => {
let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
resqData = {};
if (captchaCode && captchaCode !== req.session.captcha) {
resqData.code = 400;
resqData.message = '图形验证码不正确';
}else {
resqData.code = code;
resqData.message = '';
}
return resqData;
};
/**
* 手机身份验证-校验手机号
*/
const identityMobile = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400},
uid = req.uid,
check = false,
userId;
let mobileInfo = handleMobile(mobile);
let userInfo = yield userApi.getUserInfoByMobile(area, mobile);
userId = 'uid' in userInfo.data ? userInfo.data.uid : 0;
if (userId === uid) {
check = true;
}
if (check) {
resqData = {
code: 200,
message: '',
data: ''
}
}else {
resqData = {
code: 400,
message: '手机号错误',
data: ''
}
}
return resqData;
})();
};
/**
* 向验证手机号发送短信-ajax
*/
const sendMobileMsg = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400},
uid = req.uid;
let mobileInfo = handleMobile(mobile);
resqData = yield accountApi.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
/**
* 校验短信验证码-ajax
*/
const checkMobileMsg = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
uid = req.uid,
resqData;
if (mobile === '') {
resqData = {
code: 400,
message: '手机号为空',
data: ''
}
return resqData;
}
if (code === '') {
resqData = {
code: 400,
message: '验证码为空',
data: ''
}
return resqData;
}
let mobileInfo = handleMobile(mobile);
resqData = yield accountApi.checkVerifyMsg(uid, mobileInfo.mobile, mobileInfo.area);
if (resqData.code === 200) {
let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' +
mobileInfo.mobile + mobileInfo.area + 'completeverify');
resqData.data = checkCode;
}
return resqData;
})();
};
/**
* 身份验证时,发送邮件-ajax
*/
const sendEmail = (req) => {
return co(function*() {
let uid = req.body.uid,
checkType = req.body.checkType || 'userpwd',
email = req.body.email || '',
resqData = {code: 400};
let checkCode = crypto.encrypt('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + email + checkType + 'completeverify'),
callback = 'home/account/' + checkType + '?step=2&checkCode=' + checkCode; //callback拼接于邮箱域名处;
resqData = yield accountApi.sendVerifyEmailForNext(email, callback);
return resqData;
})();
};
/**
* 分-修改邮箱前,校验邮箱-ajax
*/
const checkEmail = (req) => {
return co(function*() {
let uid = req.body.uid,
email = req.body.email || '',
resqData = {code: 400};
resqData = yield accountApi.checkVerifyEmail(uid, email);
return resqData;
})();
};
/**
* 修改密码
*/
const modifyPwd = (req) => {
return co(function*() {
let uid = req.body.uid,
newPwd = req.body.newPwd || '',
captchaCode = _.trim(req.body.verifyCode || '').toLowerCase();
resqData = {code: 400};
if (captchaCode && captchaCode !== req.session.captcha) {
resqData.code = 400;
resqData.message = '图形验证码不正确';
}else {
resqData = yield accountApi.modifyPwd(uid, newPwd);
}
return resqData;
})();
};
/**
* 修改验证手机号
*/
const modifyMobile = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
uid = req.uid,
resqData = {code: 400};
if (mobile === '') {
resqData = {
code: 400,
message: '手机号为空',
data: ''
}
return resqData;
}
if (code === '') {
resqData = {
code: 400,
message: '验证码为空',
data: ''
}
return resqData;
}
let mobileInfo = handleMobile(mobile);
let checkFlag = accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
if (checkFlag.code === 200) {
resqData = accountApi.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile);
}else {
resqData = {
code: checkFlag.data,
message: checkFlag.message,
data: ''
}
}
return resqData;
})();
};
/**
* 分-检查手机号是否可修改-ajax
*/
const checkMobile = (req) => {
return co(function*() {
let uid = req.body.uid,
mobile = req.body.mobile || '',
resqData = {code: 400};
let mobileInfo = handleMobile(mobile);
resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
/**
* 修改验证邮箱校验并发送邮件-ajax
*
*/
const modifyEmail = (req) => {
return co(function*() {
let uid = req.body.uid,
email = req.body.email || '',
resqData = {code: 400};
let check = yield accountApi.checkVerifyEmail(uid, email);
if (check.code === 200) {
resqData = accountApi.sendVerifyEmail(uid, email);
}
return resqData;
})();
};
module.exports = {
getAccountInfo,
userPwd,
userEmail,
userMobile,
checkVerifyCode
sendEmailSuccess,
mailResult,
verifyPassword,
checkPassword,
checkVerifyCode,
identityMobile,
sendMobileMsg,
checkMobileMsg,
sendEmail,
checkEmail,
checkMobile,
modifyEmail,
modifyMobile,
modifyPwd
};
... ...
... ... @@ -102,6 +102,20 @@ const editUserLikeBrand = (uid, brand) => {
});
};
/**
* 根据手机号获取用户信息[TODO +cache]
* @param string $area
* @param string $mobile
* @return array
*/
const getUserInfoByMobile = (area, mobile) => {
return api.get('', {
method: 'app.passport.getProfileByMobile',
area: area,
mobile: mobile
});
};
module.exports = {
getUserInfo,
editUserInfo,
... ... @@ -112,5 +126,6 @@ module.exports = {
editUserHabitsInfo,
getUserLikeBrand,
editUserLikeBrand,
getTipConfig
getTipConfig,
getUserInfoByMobile
};
... ...