Authored by htoooth

format code

... ... @@ -3,18 +3,18 @@
* @author gaohongwei <hongwei.gao@yoho.cn>
* @date: 2016/8/30
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
const _ = require('lodash');
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
const _ = require('lodash');
const crypto = global.yoho.crypto;
const accountApi = require('./account-api');
const userApi = require('./user-api');
const crypto = global.yoho.crypto;
const accountApi = require('./account-api');
const userApi = require('./user-api');
// 时间转换为时间戳
function datetimeToUnix(datetime) {
function datetimeToUnix(datetime) {
let tmpDatetime = datetime.replace(/:/g, '-');
tmpDatetime = tmpDatetime.replace(/ /g, '-');
... ... @@ -23,14 +23,14 @@
let now = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
return parseInt(now.getTime() / 1000, 10);
}
}
/**
/**
* 根据输入的mobile获取area
* @param type $mobile
* @return int
*/
function handleMobile(mobile) {
function handleMobile(mobile) {
let res = {};
// 国际号
... ... @@ -44,7 +44,7 @@
res.mobile = mobile;
}
return res;
}
}
/**
* 获得标题文案
... ... @@ -52,7 +52,7 @@
* @param type ischeckEmail
* @param type checkType
*/
function getTitles(ischeckMobile, ischeckEmail, checkType) {
function getTitles(ischeckMobile, ischeckEmail, checkType) {
let subTitle,
enTitle,
pageKey;
... ... @@ -75,7 +75,7 @@
enTitle: enTitle,
pageKey: pageKey
};
}
}
/**
* 第一部页面form结构-step1
... ... @@ -85,24 +85,33 @@
* @param type $firstCheck
* @return string
*/
const getFormDataStep1 = (data, ischeckMobile, ischeckEmail, firstCheck) => {
const getFormDataStep1 = (data, ischeckMobile, ischeckEmail, firstCheck) => {
// 都没验证
let formData1 = [{
let formData1 = [
{
inputTxt: '请输入登录密码',
key: 'password',
type: 'password',
name: 'password'
}], formData2 = [{// 只验证手机号
}
];
let formData2 = [
{// 只验证手机号
inputTxt: '已验证的手机号',
isVerify: true,
verifyAccount: data.mobile.slice(0, 3) + '****' + data.mobile.slice(7),
realAccount: data.mobile
}], formData3 = [{// 只验证邮箱
}
];
let formData3 = [
{// 只验证邮箱
inputTxt: '已验证邮箱',
isVerify: true,
verifyAccount: data.email.slice(0, 2) + '****' + data.email.slice(6),
realAccount: data.email
}];
}
];
let formData,
verifyType,
... ... @@ -138,7 +147,7 @@
checkEmailFlag: checkEmailFlag,
checkMobileFlag: checkMobileFlag
};
};
};
/**
* 第二步-formData
... ... @@ -147,7 +156,7 @@
* @param type $checkType
* @return array
*/
const getFormDataStep2 = (ischeckEmail, ischeckMobile, checkType) => {
const getFormDataStep2 = (ischeckEmail, ischeckMobile, checkType) => {
let formData = [];
switch (checkType) {
... ... @@ -192,8 +201,8 @@
break;
}
return {formData: formData };
};
return {formData: formData};
};
/**
* 个人中心-判断身份验证状态
... ... @@ -202,7 +211,7 @@
* @param type step page步骤
* @return type
*/
const auditCheckStatus = (uid, checkType, step) => {
const auditCheckStatus = (uid, checkType, step) => {
return co(function*() {
let res = yield accountApi.getVerifyInfo(uid),
ret = {status: false};
... ... @@ -255,7 +264,7 @@
return ret;
})();
};
};
/**
* 校验进入第二步
... ... @@ -263,7 +272,7 @@
* @param type $uid
* @return boolean
*/
const checkCode = (ckCode, uid) => {
const checkCode = (ckCode, uid) => {
// checkCode里空格用+替换
let code = decodeURIComponent(ckCode);
let checkStr = crypto.decrypt('yoho9646abcdefgh', code);
... ... @@ -277,13 +286,13 @@
} else {
return false;
}
};
};
/**
* 个人中心-账号安全-index
*
*/
const getAccountInfo = (uid) => {
const getAccountInfo = (uid) => {
return co(function*() {
let resq = [{
... ... @@ -323,12 +332,12 @@
return resq;
})();
};
};
/**
* 个人中心-修改密码身份验证-page1/2/3
*/
const userPwd = (params) => {
const userPwd = (params) => {
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
... ... @@ -408,12 +417,12 @@
meValidatePage: true
};
})();
};
};
/**
/**
* 个人中心-邮箱验证身份-page1/2/3
*/
const userEmail = (params) => {
const userEmail = (params) => {
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
... ... @@ -493,12 +502,12 @@
meValidatePage: true
};
})();
};
};
/**
* 个人中心-手机验证身份-page1/2/3
*/
const userMobile = (params) => {
const userMobile = (params) => {
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
... ... @@ -578,12 +587,12 @@
meValidatePage: true
};
})();
};
};
/**
/**
* 个人中心-邮箱验证身份-邮件发送成功过渡页
*/
const sendEmailSuccess = (params) => {
const sendEmailSuccess = (params) => {
return co(function*() {
let checkType = params.checkType || 'userpwd',
uid = params.uid,
... ... @@ -635,12 +644,12 @@
return resqData;
})();
};
};
/**
* 点击邮箱验证链接方法--修改验证邮箱
*/
const mailResult = (params) => {
const mailResult = (params) => {
return co(function*() {
let code = params.code;
let check = yield accountApi.checkEmailCode(code);
... ... @@ -667,12 +676,12 @@
params: {step: 3, success: false}
};
})();
};
};
/**
* 身份验证-登录密码验证Ajax
*/
const verifyPassword = (req) => {
const verifyPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.uid;
... ... @@ -687,12 +696,12 @@
}
return resqData;
})();
};
};
/**
* 分-验证密码正确性-ajax
*/
const checkPassword = (req) => {
const checkPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.uid,
... ... @@ -702,12 +711,12 @@
return resqData;
})();
};
};
/**
* 分-验证图形验证码-ajax
*/
const checkVerifyCode = (req) => {
const checkVerifyCode = (req) => {
return co(function*() {
let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
resqData = {};
... ... @@ -722,12 +731,12 @@
return resqData;
})();
};
};
/**
/**
* 手机身份验证-校验手机号
*/
const identityMobile = (req) => {
const identityMobile = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400},
... ... @@ -759,12 +768,12 @@
}
return resqData;
})();
};
};
/**
* 向验证手机号发送短信-ajax
*/
const sendMobileMsg = (req, uid) => {
const sendMobileMsg = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400};
... ... @@ -774,12 +783,12 @@
resqData = yield accountApi.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
};
/**
* 校验短信验证码-ajax
*/
const checkMobileMsg = (req, uid) => {
const checkMobileMsg = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
... ... @@ -812,12 +821,12 @@
}
return resqData;
})();
};
};
/**
* 身份验证时,发送邮件-ajax
*/
const sendEmail = (req) => {
const sendEmail = (req) => {
return co(function*() {
let uid = req.uid,
checkType = req.body.checkType || 'userpwd',
... ... @@ -833,12 +842,12 @@
resqData = yield accountApi.sendVerifyEmailForNext(email, callback);
return resqData;
})();
};
};
/**
* 分-修改邮箱前,校验邮箱-ajax
*/
const checkEmail = (req) => {
const checkEmail = (req) => {
return co(function*() {
let uid = req.uid,
email = req.body.email || '',
... ... @@ -847,12 +856,12 @@
resqData = yield accountApi.checkVerifyEmail(uid, email);
return resqData;
})();
};
};
/**
* 修改密码
*/
const modifyPwd = (req, params) => {
const modifyPwd = (req, params) => {
return co(function*() {
let uid = params.uid,
newPwd = params.newPwd || '';
... ... @@ -861,12 +870,12 @@
return resqData;
})();
};
};
/**
* 修改验证手机号
*/
const modifyMobile = (req, uid) => {
const modifyMobile = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
... ... @@ -903,12 +912,12 @@
}
return resqData;
})();
};
};
/**
* 分-检查手机号是否可修改-ajax
*/
const checkMobile = (params, uid) => {
const checkMobile = (params, uid) => {
return co(function*() {
let mobile = params.mobile || '',
resqData = {code: 400};
... ... @@ -918,13 +927,13 @@
resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
};
/**
* 修改验证邮箱校验并发送邮件-ajax
*
*/
const modifyEmail = (req) => {
const modifyEmail = (req) => {
return co(function*() {
let uid = req.uid,
email = req.body.email || '',
... ... @@ -937,9 +946,9 @@
}
return resqData;
})();
};
};
module.exports = {
module.exports = {
getAccountInfo,
userPwd,
userEmail,
... ... @@ -958,4 +967,4 @@
modifyEmail,
modifyMobile,
modifyPwd
};
};
... ...