Authored by htoooth

fix home.account

... ... @@ -12,10 +12,13 @@ const _ = require('lodash');
const crypto = global.yoho.crypto;
const AccountApi = require('./account-api');
const CaptchaImgService = require('../../passport/models/captcha-img-service');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.captchaService = new CaptchaImgService(ctx);
}
// 时间转换为时间戳
... ... @@ -220,7 +223,7 @@ module.exports = class extends global.yoho.BaseModel {
auditCheckStatus(uid, checkType, step) {
let that = this;
return co(function*() {
return co(function* () {
let accountDataModel = new AccountApi(that.ctx);
let res = yield accountDataModel.getVerifyInfo(uid),
ret = {status: false};
... ... @@ -236,7 +239,7 @@ module.exports = class extends global.yoho.BaseModel {
if (ischeckMobile && ischeckEmail) {
firstCheck = (that.datetimeToUnix(data.mobileVerifyTime) <=
that.datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
that.datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
}
let verifyType = 1,
... ... @@ -313,7 +316,7 @@ module.exports = class extends global.yoho.BaseModel {
getAccountInfo(uid) {
let that = this;
return co(function*() {
return co(function* () {
let accountDataModel = new AccountApi(that.ctx);
let resq = [{
... ... @@ -361,7 +364,7 @@ module.exports = class extends global.yoho.BaseModel {
userPwd(params) {
let that = this;
return co(function*() {
return co(function* () {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
... ... @@ -447,7 +450,7 @@ module.exports = class extends global.yoho.BaseModel {
userEmail(params) {
let that = this;
return co(function*() {
return co(function* () {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
... ... @@ -534,7 +537,7 @@ module.exports = class extends global.yoho.BaseModel {
userMobile(params) {
let that = this;
return co(function*() {
return co(function* () {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
... ... @@ -621,7 +624,7 @@ module.exports = class extends global.yoho.BaseModel {
sendEmailSuccess(params) {
let that = this;
return co(function*() {
return co(function* () {
let checkType = params.checkType || 'userpwd',
uid = params.uid,
email = params.email || '',
... ... @@ -637,7 +640,7 @@ module.exports = class extends global.yoho.BaseModel {
};
}
emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
'mail.google.com' : 'mail.' + email.split('@')[1]);
'mail.google.com' : 'mail.' + email.split('@')[1]);
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
... ... @@ -680,7 +683,7 @@ module.exports = class extends global.yoho.BaseModel {
mailResult(params) {
let that = this;
return co(function*() {
return co(function* () {
let code = params.code;
let accountDataModel = new AccountApi(that.ctx);
let check = yield accountDataModel.checkEmailCode(code);
... ... @@ -715,7 +718,7 @@ module.exports = class extends global.yoho.BaseModel {
verifyPassword(req) {
let that = this;
return co(function*() {
return co(function* () {
let password = _.trim(req.body.password || ''),
uid = req.user.uid,
accountDataModel = new AccountApi(that.ctx);
... ... @@ -738,7 +741,7 @@ module.exports = class extends global.yoho.BaseModel {
checkPassword(req) {
let that = this;
return co(function*() {
return co(function* () {
let password = _.trim(req.body.password || ''),
uid = req.user.uid,
resqData = {code: 400},
... ... @@ -774,7 +777,7 @@ module.exports = class extends global.yoho.BaseModel {
identityMobile(req) {
let that = this;
return co(function*() {
return co(function* () {
let mobile = req.body.mobile || '',
resqData = {code: 400},
uid = req.user.uid,
... ... @@ -811,37 +814,40 @@ module.exports = class extends global.yoho.BaseModel {
/**
* 向验证手机号发送短信-ajax
*/
sendMobileMsg(req, uid) {
let that = this;
return co(function*() {
let mobile = req.body.mobile || '',
_code = req.body.checkCode,
resqData = {code: 400};
async sendMobileMsg(req, uid) {
let mobile = req.body.mobile || '',
_code = req.body.checkCode,
resqData = {code: 400};
let accountDataModel = new AccountApi(that.ctx);
let accountDataModel = new AccountApi(this.ctx);
let id = req.session.id;
let captcha = req.body.verifyCode;
// 发送验证码前置数据校验
if (!_code) {
let verifyInfo = yield accountDataModel.getVerifyInfo(uid);
// 发送验证码前置数据校验
if (!_code) {
let verifyInfo = await accountDataModel.getVerifyInfo(uid);
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!that.checkCode(_code, uid)) {
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!this.checkCode(_code, uid)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
let mobileInfo = that.handleMobile(mobile);
let mobileInfo = this.handleMobile(mobile);
resqData = yield accountDataModel.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
resqData = await accountDataModel.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area, id, captcha);
let captchaNeeded = await this.captchaService.try();
_.set(resqData, 'data.needCaptcha', captchaNeeded);
return resqData;
}
/**
... ... @@ -850,7 +856,7 @@ module.exports = class extends global.yoho.BaseModel {
checkMobileMsg(req, uid) {
let that = this;
return co(function*() {
return co(function* () {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
... ... @@ -911,7 +917,7 @@ module.exports = class extends global.yoho.BaseModel {
sendEmail(req) {
let that = this;
return co(function*() {
return co(function* () {
let uid = req.user.uid,
checkType = req.body.checkType || 'userpwd',
email = req.body.email || '',
... ... @@ -944,7 +950,7 @@ module.exports = class extends global.yoho.BaseModel {
checkEmail(req) {
let that = this;
return co(function*() {
return co(function* () {
let uid = req.user.uid,
email = req.body.email || '',
resqData = {code: 400};
... ... @@ -962,7 +968,7 @@ module.exports = class extends global.yoho.BaseModel {
modifyPwd(req, params) {
let that = this;
return co(function*() {
return co(function* () {
let uid = params.uid,
newPwd = params.newPwd || '',
_code = params.checkCode;
... ... @@ -989,7 +995,7 @@ module.exports = class extends global.yoho.BaseModel {
modifyMobile(req, uid) {
let that = this;
return co(function*() {
return co(function* () {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
... ... @@ -1044,7 +1050,7 @@ module.exports = class extends global.yoho.BaseModel {
checkMobile(params, uid) {
let that = this;
return co(function*() {
return co(function* () {
let mobile = params.mobile || '',
resqData = {code: 400};
... ... @@ -1063,7 +1069,7 @@ module.exports = class extends global.yoho.BaseModel {
modifyEmail(req) {
let that = this;
return co(function*() {
return co(function* () {
let uid = req.user.uid,
email = req.body.email || '',
_code = req.body.checkCode,
... ...
... ... @@ -57,7 +57,6 @@ module.exports = class extends global.yoho.BaseModel {
'/home/account/userpwd',
'/home/account/email',
'/home/account/mobile',
'/home/account/checkverifycode',
'/home/account/checkpassword',
'/home/account/verifypassword',
'/home/account/modifypwd',
... ...
... ... @@ -225,8 +225,6 @@ router.get('/account/email', tabsMiddleware.getCommonHeader, captcha.required, A
router.get('/account/mobile', tabsMiddleware.getCommonHeader, captcha.required, AccountController.userMobile);
router.post('/account/checkverifycode', tabsMiddleware.getCommonHeader, AccountController.checkVerifyCode);
router.post('/account/checkpassword', tabsMiddleware.getCommonHeader, AccountController.checkPassword);
router.post('/account/verifypassword', tabsMiddleware.getCommonHeader, AccountController.verifyPassword);
... ...
... ... @@ -41,7 +41,7 @@
</li>
{{/each}}
{{#if mobileCode}}
<li class="user-form-li captcha-li">
<li class="user-form-li captcha-li {{#unless @root.captcha.value}}hide{{/unless}}">
<div class="safe-form-l">图形验证码:</div>
<div class="captcha-safe-form-r"></div>
</li>
... ...
... ... @@ -23,7 +23,8 @@ var sInt,
var baseQs;
var captcha = new Captcha('.captcha-safe-form-r').init();
var $captchaWrap = $('captcha-safe-form-r');
var captcha = new Captcha('.captcha-safe-form-r', {checkURI: ''}).init();
require('../common');
... ... @@ -52,6 +53,10 @@ if (!Array.prototype.indexOf) {// eslint-disable-line
};
}
function showCaptchaImg() {
$captchaWrap.removeClass('hide');
}
function errorInfoAction(opt, txt) {
canFlag = false;
opt.$checkInfo.html('<div class="form-error">' + txt + '</div>');
... ... @@ -253,15 +258,22 @@ function sendMobileMsg(mobileV) {
reqData.checkCode = baseQs.checkCode;
}
$.post('/home/account/sendmobilemsg', reqData, function(data) {
if (typeof data.code !== 'undefined' && data.code === 200) {
if (captcha.getResults()) {
reqData.verifyCode = captcha.getResults();
}
$.post('/home/account/sendmobilemsg', reqData, function(result) {
if (typeof result.code !== 'undefined' && result.code === 200) {
canSend = false;
sInt = setInterval(function() {
code();
}, 1000);
$ccheckInfo.html('');
} else {
$ccheckInfo.html('<div class="form-error">验证码发送失败</div>');
if (result.data && result.data.needCaptcha) {
showCaptchaImg();
}
$ccheckInfo.html('<div class="form-error">' + result.message + '</div>');
}
});
}
... ... @@ -476,9 +488,7 @@ $(function() {
});
$('#send-mobile-code').on('click', function() {
captcha.check().then(function() {
sendcode();
});
sendcode();
});
if ($('#newPwd').length > 0) {
... ...