Authored by 郝肖肖

'第三方绑定手机号'

... ... @@ -323,7 +323,61 @@ const bind = {
}
},
// 绑定手机号发送短信
// 第三方绑定手机号页面
thirdBindMobilePage: (req, res) => {
let headerData = headerModel.setNav({
navTitle: '绑定手机号', // 标题
navBack: true, // 是否显示返回按钮
backUrl: helpers.urlFormat('/signin.html'), // 返回按钮对应的url
navBtn: false // 顶部下拉菜单选项
});
res.render('bind/bind-mobile', {
captchaShow: req.yoho.captchaShow,
width750: true,
pageHeader: headerData,
localCss: true,
module: 'passport',
page: 'third-bind-mobile',
btnName: '绑定手机号',
areaCode: '+86', // 默认区号
countrys: req.ctx(RegServiceModel).getAreaData(), // 国别码
});
},
// 第三方绑定手机号发送短信
thirdSendMsgApi: (req, res, next) => {
req.ctx(BindServiceModel).sendThirdBindMobileCodeOnly(req.body).then(result => {
if (_.get(result, 'code', 400) === 200) {
return next();
}
return res.json(result);
}).catch(next);
},
// 第三方调用绑定接口
thirdBindMobileApi: (req, res, next) => {
if (_.isEmpty(req.body.open_id) || _.isEmpty(req.body.source_type)) {
return res.json({code: 401, data: {}, message: '请重新登录授权'});
}
req.ctx(BindServiceModel).thirdBindMobile(req.body).then(result => {
if (_.get(result, 'code', 400) !== 200) {
return res.json(result);
}
return req.ctx(AuthHelperModel).syncUserSession(
result.data.uid,
req,
res,
result.data.session_key
).then(() => {
return res.json({code: 200, data: {}, message: 'success'});
});
}).catch(next);
},
// 通过邮箱绑定手机号发送短信
sendMsgApi: (req, res, next) => {
req.ctx(BindServiceModel).sendChangeBindMobileCodeOnly(req.body).then(result => {
if (_.get(result, 'code', 400) === 200) {
... ... @@ -334,10 +388,10 @@ const bind = {
},
// 检查手机是否绑定
forceMobileCheckApi: (req, res, next) => {
changeMobileCheckApi: (req, res, next) => {
req.ctx(BindServiceModel).changeMobileCheck(req.body).then(result => {
if (_.get(result, 'data.isBind', 'N') === 'N' &&
_.get(result, 'data.isRegister', 'N') === 'N') {
if (_.get(result, 'data.isBind', '') === 'N' &&
_.get(result, 'data.isRegister', '') === 'N') {
return next();
}
return res.json(result);
... ... @@ -353,7 +407,7 @@ const bind = {
navBtn: false // 顶部下拉菜单选项
});
res.render('bind/email-mobile', {
res.render('bind/bind-mobile', {
captchaShow: req.yoho.captchaShow,
width750: true,
pageHeader: headerData,
... ...
... ... @@ -134,6 +134,29 @@ class BindServiceModel extends global.yoho.BaseModel {
password: aes.aesPwd(params.password || '')
}});
}
// 第三方绑定手机号发送短信
sendThirdBindMobileCodeOnly(params) {
return this.get({data: {
method: 'app.bind.sendThirdBindMobileCodeOnly',
business_line: 'yohobuy',
mobile: params.mobile || '',
area: params.area || '86'
}});
}
// 第三方绑定手机号
thirdBindMobile(params) {
return this.get({data: {
method: 'app.bind.bindMobile',
business_line: 'yohobuy',
mobile: params.mobile || '',
area: params.area || '86',
code: params.code,
open_id: params.open_id,
source_type: params.source_type
}});
}
}
module.exports = BindServiceModel;
... ...
... ... @@ -85,11 +85,20 @@ router.get('/passport/password/resetsuccess', reset.passwordResetOkPage); // 重
router.get('/passport/bind/forceBindMobile', validateCode.load, bind.forceBindMobilePage);
router.post('/passport/bind/forceSendMsg', validateCode.check, bind.sendMsgApi, bind.forceSendMsg);
router.post('/passport/bind/forceMobileCheck',
bind.forceMobileCheckApi,
bind.changeMobileCheckApi,
bind.forceBindMobileApi
);
router.post('/passport/bind/continueMobile', bind.forceBindMobileApi);
// 第三方绑定手机号
router.get('/passport/bind/thirdBindMobile', validateCode.load, bind.thirdBindMobilePage);
router.post('/passport/bind/thirdSendMsg', validateCode.check, bind.thirdSendMsgApi, bind.forceSendMsg);
router.post('/passport/bind/thirdMobileCheck',
bind.changeMobileCheckApi,
bind.thirdBindMobileApi
);
router.post('/passport/bind/thirdContinueMobile', bind.thirdBindMobileApi);
/**
* 密码找回
*/
... ...
require('passport/bind-email-mobile.page.css');
require('passport/bind-mobile.page.css');
const $ = require('yoho-jquery');
const BindEmailMobile = require('./bind/email-mobile.js');
const BindEmailMobile = require('./bind/_email-bind-mobile.js');
$(() => {
new BindEmailMobile();
});
... ...
... ... @@ -15,7 +15,7 @@ const validate = new Validate($captcha, {
});
const showErrTip = tip.show;
class EmailMobile extends Page {
class EmailBindMobile extends Page {
constructor() {
super();
... ... @@ -266,4 +266,4 @@ class EmailMobile extends Page {
}
}
module.exports = EmailMobile;
module.exports = EmailBindMobile;
... ...
import $ from 'yoho-jquery';
import tip from 'plugin/tip';
import Page from 'yoho-page';
import api from '../api';
import Validate from 'plugin/validata';
import dialog from 'plugin/dialog';
import bindDialogHbs from 'passport/bind-dialog-tip.hbs';
const $captcha = $('#js-img-check');
const validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
const showErrTip = tip.show;
class ThirdBindMobile extends Page {
constructor() {
super();
this.selector = {
itime: 0,
countrySelect: $('.mobile-form-login select.country-select'),
mobileInput: $('.mobile-form-login input.mobile-input'),
clearMobile: $('.mobile-form-login .clear'),
verifyCodeInput: $('.mobile-form-login input.verify-code-input'),
verifyCodeBtn: $('.mobile-form-login .get-verify-code'),
loginBtn: $('.mobile-form-login .sms-login-btn'),
};
this.init();
}
init() {
if ($captcha.data('userverify')) {
validate.init();
}
this.bindEvents();
}
bindEvents() {
this.selector.countrySelect.on('change', this.changeBtnStatus.bind(this));
this.selector.mobileInput.on('input', this.changeBtnStatus.bind(this));
this.selector.clearMobile.on('click', this.clearMobile.bind(this));
this.selector.verifyCodeInput.on('input', this.changeBtnStatus.bind(this, true));
this.selector.verifyCodeBtn.on('click', this.getVerifyCode.bind(this));
this.selector.loginBtn.on('click', this.login.bind(this));
}
/**
* 清除输入的手机号
*/
clearMobile() {
this.selector.mobileInput.val('');
this.selector.verifyCodeInput.val('');
this.selector.clearMobile.addClass('hide');
this.selector.countrySelect.trigger('change');
}
/**
* 输入监听,改变按钮状态
*/
changeBtnStatus(isVerifycode) {
let areaCode = $.trim(this.selector.countrySelect.val());
let phoneNum = $.trim(this.selector.mobileInput.val());
let verifyCode = $.trim(this.selector.verifyCodeInput.val());
if (!api.phoneRegx[areaCode]) {
return showErrTip('出错了,请重新刷新页面');
}
if (phoneNum) {
this.selector.clearMobile.removeClass('hide');
}
// 验证码输入框单独处理
if (isVerifycode === true) {
// 提交表单按钮激活
if (verifyCode && api.phoneRegx[areaCode].test(phoneNum)) {
this.selector.loginBtn.addClass('active');
} else {
this.selector.loginBtn.removeClass('active');
}
return;
}
clearInterval(this.selector.itime);
this.selector.verifyCodeBtn.text('获取验证码');
if (api.phoneRegx[areaCode].test(phoneNum)) {
this.selector.verifyCodeBtn.addClass('active');
if (verifyCode) {
this.selector.loginBtn.addClass('active');
}
} else {
this.selector.verifyCodeBtn.removeClass('active');
this.selector.loginBtn.removeClass('active');
}
}
/**
* 获取验证码倒计时
*/
countDown(during) {
let count = parseInt(during, 10) || 59;
if (!this.selector.verifyCodeBtn.hasClass('active')) {
return;
}
this.selector.verifyCodeBtn.removeClass('active');
this.selector.itime = setInterval(() => {
window.setCookie('intTimer', count, {path: '/' });
if (count <= 0) {
this.selector.verifyCodeBtn.text('重新获取').addClass('active');
clearInterval(this.selector.itime);
} else {
this.selector.verifyCodeBtn.text('重新获取 (' + count-- + '秒)');
}
}, 1000);
}
/**
* 获取验证码
*/
getVerifyCode() {
let pn = $.trim(this.selector.mobileInput.val());
let area = $.trim(this.selector.countrySelect.val());
if (!this.selector.verifyCodeBtn.hasClass('active') ||
this.selector.verifyCodeBtn.data('oneClick')) {
return;
}
if (!api.phoneRegx[area]) {
return showErrTip('出错了,请重新刷新页面');
} else if (!api.phoneRegx[area].test(pn)) {
return showErrTip('手机号格式不正确,请重新输入');
}
this.selector.verifyCodeBtn.data('oneClick', true);
validate.getResults().then(result => {
let params = {
area: area.replace('+', ''),
mobile: pn
};
$.extend(params, result);
this.ajax({
url: '/passport/bind/thirdSendMsg',
type: 'POST',
data: params
}).then(codeResult => {
this.selector.verifyCodeBtn.data('oneClick', false);
validate.type === 2 && validate.refresh();
if (codeResult.code === 200) {
this.countDown();
return;
} else {
showErrTip(codeResult.message);
}
(codeResult.changeCaptcha && validate.type !== 2) && validate.refresh();
}).catch(() => {
this.selector.verifyCodeBtn.data('oneClick', false);
showErrTip('出错了,请重试');
validate.refresh();
});
});
}
login() {
let pn = $.trim(this.selector.mobileInput.val());
let area = $.trim(this.selector.countrySelect.val());
let verifyCode = $.trim(this.selector.verifyCodeInput.val());
if (!this.selector.loginBtn.hasClass('active')) {
return;
}
if (!api.phoneRegx[area]) {
return showErrTip('出错了,请重新刷新页面');
} else if (!api.phoneRegx[area].test(pn)) {
return showErrTip('手机号格式不正确,请重新输入');
}
this.selector.loginBtn.data('oneClick', true);
let params = {
area: area.replace('+', ''),
mobile: pn,
code: verifyCode,
};
this.ajax({
url: '/passport/bind/thirdMobileCheck',
type: 'POST',
data: params
}).then(codeResult => {
this.selector.loginBtn.data('oneClick', false);
if (codeResult.code === 200) {
this.continueBind(
$.extend({isBind: 'N', isRegister: 'N'}, codeResult.data),
params
);
} else {
showErrTip(codeResult.message);
}
}).catch(() => {
this.selector.loginBtn.data('oneClick', false);
showErrTip('出错了,请重试');
});
}
continueBind(codeResult, params) {
let that = this;
let goUrl = '/passport/bind/success?type=bind';
let bindParams = {
isBind: codeResult.isBind === 'Y',
isRegister: codeResult.isRegister === 'Y'
};
// 如果没有绑定没有注册,直接注册
if (!(bindParams.isBind || bindParams.isRegister)) {
document.location.href = goUrl;
return;
}
dialog.showDialog({
dialogText: bindDialogHbs(bindParams),
fast: true,
hasFooter: {
leftBtnText: '去登录',
rightBtnText: '继续'
}
}, function() {
return that.ajax({
url: '/passport/bind/thirdContinueMobile',
type: 'POST',
data: params
}).then(cresult => {
if (cresult.code === 200) {
document.location.href = goUrl;
return;
} else {
showErrTip(cresult.message);
}
}).catch(() => {
showErrTip('出错了,请重试');
});
}, function() {
document.location.href = '//m.yohobuy.com/signin.html';
});
$('.dialog-wrapper').addClass('s-dialog-bind');
}
}
module.exports = ThirdBindMobile;
... ...
require('passport/bind-mobile.page.css');
const $ = require('yoho-jquery');
const ThirdEmailMobile = require('./bind/_third-bind-mobile.js');
$(() => {
new ThirdEmailMobile();
});
... ...