Authored by 陈峰

Merge branch 'feature/imageCheck' into 'gray'

Feature/image check



See merge request !236
... ... @@ -17,7 +17,8 @@ const AUTH_TIME = 2592000000;
const updateSessionKey = (res, sessionKey) => {
if (sessionKey) {
res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), {
domain: config.cookieDomain
domain: config.cookieDomain,
httpOnly: true
});
}
};
... ...
... ... @@ -100,19 +100,19 @@ module.exports = class extends global.yoho.BaseModel {
}
/**
* [检查是否绑定手机号]
* [检查手机号是否注册绑定]
* @param {[type]} area [区号]
* @param {[type]} mobile [手机号]
* @param {[type]} code [图形验证码]
* @return {[type]} [{}]
*/
checkIsCanBind(area, mobile) {
let options = {
method: 'app.passport.checkIsCanBind',
changeMobileCheck(area, mobile, code) {
return this.get({data: {
method: 'app.bind.changeMobileCheck',
area: area,
mobile: mobile
};
return this.get({data: options});
mobile: mobile,
code: code
}});
}
/**
... ... @@ -123,7 +123,7 @@ module.exports = class extends global.yoho.BaseModel {
*/
smsbind(area, mobile, id, captcha) {
let options = {
method: 'app.passport.smsbind',
method: 'app.bind.sendChangeBindMobileCodeOnlyImg',
area: area,
mobile: mobile,
udid: id,
... ... @@ -144,7 +144,7 @@ module.exports = class extends global.yoho.BaseModel {
*/
changeMobile(area, mobile, code, uid) {
let options = {
method: 'app.passport.changeMobile',
method: 'app.bind.changeMobileForce',
area: area,
mobile: mobile,
code: code,
... ...
... ... @@ -6,6 +6,7 @@
'use strict';
const Promise = require('bluebird');
const _ = require('lodash');
const md5 = require('md5');
const helpers = global.yoho.helpers;
const MeGiftAPi = require('./me-gift-api');
const setPager = require(`${global.utils}/pager`).setPager;
... ... @@ -137,24 +138,56 @@ module.exports = class extends global.yoho.BaseModel {
// 发验手机证码
smsBind(params) {
return this.meGiftAPi.checkIsCanBind(params.area, params.mobile).then(res => {
if (_.get(res, 'data.isCanBind') === 'N') {
return {
code: 401,
message: '<p>绑定失败,该手机号已被绑定</p><p>请更换手机号</p>'
};
return this.meGiftAPi.smsbind(params.area, params.mobile, params.id, params.captcha);
}
// 验证手机号
checkMobile(params, uid) {
let {fcode, ccode} = params;
if (fcode && ccode) {
if (md5(`${ccode}_${uid}`) === fcode) {
return Promise.resolve({code: 200});
} else {
return Promise.resolve({code: 400, message: '信息校验失败,请刷新后重试'});
}
return this.meGiftAPi.smsbind(params.area, params.mobile, params.id, params.captcha);
});
} else {
return this.meGiftAPi.changeMobileCheck(params.area, params.mobile, params.code);
}
}
// 修改绑定的手机号
changeMobile(params, uid) {
return this.meGiftAPi.changeMobile(params.area, params.mobile, params.code, uid).then(res => {
if (res.code === 200) {
_.set(this.ctx, 'req.session.USER_MOBILE', params.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'));
return this.checkMobile(params, uid).then(res => {
if (res.code !== 200) {
return res;
}
let data = res.data || {};
if (data.isRegister === 'Y') {
let ccode = Math.floor(Math.random() * 1000000000000);
return {
code: 200,
data: {
ccode: ccode,
fcode: md5(`${ccode}_${uid}`),
reCheckType: data.isBind === 'N' ? 1 : 2
}
};
}
return res;
return this.meGiftAPi.changeMobile(params.area, params.mobile, params.code, uid).then(result => {
if (result.code === 200) {
result.data = {};
_.set(this.ctx, 'req.session.USER_MOBILE',
params.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'));
}
return result;
});
});
}
... ...
... ... @@ -109,7 +109,8 @@ module.exports = class extends global.yoho.BaseModel {
});
res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), {
domain: config.cookieDomain
domain: config.cookieDomain,
httpOnly: true
});
// 购物车中商品的数量
... ...
... ... @@ -60,7 +60,7 @@ module.exports = (app) => {
name: 'yohobuy_session',
cookie: {
domain: config.cookieDomain,
httpOnly: false
httpOnly: true
},
getid() {
return uuid.v4();
... ... @@ -80,7 +80,8 @@ module.exports = (app) => {
secret: '82dd7e724f2c6870472c89dfa43cf48d',
cookie: {
domain: config.cookieDomain,
ephemeral: true
ephemeral: true,
httpOnly: true
}
}));
... ...
... ... @@ -967,7 +967,7 @@ function searchSuggestHistory() {
// 历史记录清空
$('.search-suggest-title .search-del').click(function() {
window.setCookie('_History', '', {domain: '.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
$searchHistory.empty();
$searchKey.attr('alt', true);
return false;
});
... ...
... ... @@ -2,6 +2,10 @@ var $ = require('yoho-jquery'),
Captcha = require('../plugins/captcha'),
Hbs = require('yoho-handlebars'),
dialog = require('../common/dialog');
var infoTpl = require('hbs/passport/bind-info.hbs');
var infoTpl2 = require('hbs/passport/bind-info2.hbs');
var meGift;
var captcha;
... ... @@ -226,15 +230,21 @@ meGift = {
mobile: '手机号不能为空',
code: '手机验证码不能为空'
};
that.postAjax('/home/megift/changeMobile', {
var data = {
area: ($('.mobile-area').find('em').text() || '').replace(/^\+/, ''),
mobile: $('input.mobile').val(),
code: $('input.mobile-code').val()
}, verifyData).then(function(res) {
};
that.postAjax('/home/megift/changeMobile', data, verifyData).then(function(res) {
if (res.code === 200) {
that.isBinMobile = 1;
dg.close();
if (res.data && res.data.reCheckType) {
return that.reCheckMobile(res.data, data);
}
that.isBinMobile = 1;
that.activateGift();
}
});
... ... @@ -258,6 +268,43 @@ meGift = {
}
});
},
reCheckMobile: function(check, data) {
var that = this;
var dg;
check = check || {};
data = data || {};
dg = new dialog.Dialog({
closeIcon: false,
content: +check.reCheckType === 1 ? infoTpl() : infoTpl2(),
className: 'me-gift-confirm',
btns: [{
id: 'confirm-mobile-cancel',
name: '取消',
btnClass: ['confirm-cancel'],
cb: function() {
dg.close();
}
}, {
id: 'confirm-mobile-sure',
name: '继续',
btnClass: ['confirm-sure'],
cb: function() {
data.fcode = check.fcode;
data.ccode = check.ccode;
that.postAjax('/home/megift/changeMobile', data).then(function(res) {
if (res.code === 200) {
dg.close();
that.isBinMobile = 1;
that.activateGift();
}
});
}
}]
}).show();
},
// 发送手机验证码
smsBind: function() {
... ...
... ... @@ -329,6 +329,17 @@
.bind-mobile-input {
margin: 30px 0 50px;
}
.title2,
.question,
.subtitle {
line-height: 2;
}
.title2,
.subtitle {
margin-bottom: 10px;
}
}
.me-gift-confirm.me-page {
... ...