Authored by htoooth

fix

... ... @@ -55,13 +55,10 @@ passport.use('local', new LocalStrategy({
const captchaNeeded = await req.ctx(CaptchaServiceModel).try();
if (result.code === 50004) {
return done({
code: result.code,
message: result.message,
needCaptcha: captchaNeeded,
username: encodeURIComponent(username),
password: encodeURIComponent(password)
});
req.session.forceBind = {
username,
password
};
}
return done({
... ...
... ... @@ -17,8 +17,6 @@ const config = global.yoho.config;
const cert = {
index: (req, res) => {
let refer = req.query.refer || `${config.siteUrl}`;
let username = req.query.username;
let password = req.query.password;
res.render('cert/index', {
region: passportHelper.getCountry(),
... ... @@ -29,8 +27,6 @@ const cert = {
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
module: 'passport',
page: 'cert',
username,
password,
title: '登录完善信息'
});
},
... ... @@ -93,45 +89,26 @@ const cert = {
check: (req, res, next) => {
let mobile = req.body.mobile;
let area = req.body.area || '86';
let code = req.body.code;
if (mobile && area) {
/**
* 接口绑定返回值:
* code:200,isCanBind=Y // 可绑定
* code:200,isCanBind=Y // 不可绑定
*/
req.ctx(CertService).certCheck(mobile, area).then(result => {
if (!result || !result.code) {
return {code: 400, message: '', data: ''};
} else if (result.code === 200) {
let nextUrl;
if (_.get(result, 'data.isCanBind') === 'Y') {
nextUrl = helpers.urlFormat('/passport/cert/cert');
return {code: 200, message: result.message, data: {next: nextUrl}};
} else {
// 不可以关联
return {code: 403, message: '绑定失败,该手机号已注册,请更换或使用该手机号直接登录'};
}
} else {
return {code: result.code, message: result.message, data: result.data ? result.data : ''};
}
}).then(result => {
return res.json(result);
}).catch(next);
} else {
if (!mobile || !area || !code) {
return res.json({code: 400, message: '', data: ''});
}
req.ctx(CertService).certCheck(mobile, area, code).then(({error, result}) => {
if (error) {
return res.json({code: 400, message: '验证错误,请重新登录', data: ''});
}
return res.json({code: 200, data: result});
}).catch(next);
},
sendCertMsg: (req, res, next) => {
let mobile = req.body.mobile;
let area = req.body.area;
let id = req.session.id;
let captcha = req.body.verifyCode;
req.ctx(CertService).sendCertMsg(mobile, area, id, captcha).then(result => {
req.ctx(CertService).sendCertMsg(mobile, area).then(result => {
console.log(result);
if (result && result.code) {
return res.json(result);
} else {
... ... @@ -140,37 +117,48 @@ const cert = {
}).catch(next);
},
certMobile: (req, res, next) => {
let uid = req.user.uid;
let mobile = _.trim(req.body.mobile);
let area = _.trim(req.body.area) || '86';
let code = _.trim(req.body.code);
let refer = req.body.refer;
req.ctx(CertService).certMobile(uid, mobile, code, area).then(result => {
if (!code) {
return {
code: 400,
message: '短信验证码错误'
};
}
if (result && result.code === 200) {
let url = helpers.urlFormat('/passport/cert/success', {
type: 'cert',
refer: refer
});
if (!req.session.forceBind ||
!req.session.forceBind.username ||
!req.session.forceBind.password
) {
return {
code: 400,
message: '请重新登录'
};
}
return {
code: 200,
message: result.message,
data: {
nextUrl: url
}
};
} else {
return {
code: _.get(result, 'code', 400),
req.ctx(CertService).certMobile(
req.session.forceBind.username,
req.session.forceBind.password,
mobile, code, area
).then(result => {
delete req.session.forceBind;
if (!result || result.code !== 200) {
return res.json({
code: 400,
message: _.get(result, 'message') || '操作错误,请稍后再试!'
};
});
}
}).then(result => {
res.json(result);
}).catch(next);
return res.json({
code: 200
});
}).catch(() => {
delete req.session.forceBind;
next();
});
},
relateMobile: (req, res, next) => {
let uid = req.user.uid;
... ...
... ... @@ -156,10 +156,7 @@ const local = {
data: {
needCaptcha: err.needCaptcha,
type: err.type,
session: helpers.urlFormat('/passport/cert/index', {
username: user.username,
password: user.password
})
session: helpers.urlFormat('/passport/cert/index')
}
});
}
... ...
... ... @@ -4,40 +4,37 @@
'use strict';
const PAGE = 'pc';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
certCheck(mobile, area) {
certCheck(mobile, area, code) {
let params = {
method: 'app.passport.checkIsCanBind',
method: 'app.bind.changeMobileCheck',
area: area,
mobile: mobile
mobile: mobile,
code: code
};
return this.get({data: params});
}
sendCertMsg(mobile, area, id, captcha) {
sendCertMsg(mobile, area) {
let params = {
method: 'app.passport.smsbind',
method: 'app.bind.sendChangeBindMobileCodeOnly',
mobile: mobile,
area: area,
udid: id,
degrees: captcha,
fromPage: PAGE,
};
return this.get({data: params});
}
certMobile(uid, mobile, code, area) {
certMobile(username, password, mobile, code, area) {
let params = {
method: 'app.passport.changeMobile',
uid: uid,
method: 'app.bind.bindEmailLoginMobile',
email: username,
password,
mobile: mobile,
area: area,
code: code
... ...
... ... @@ -3,8 +3,6 @@
const CertApi = require('./cert-api');
const CaptchaImgService = require('./captcha-img-service');
const _ = require('lodash');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -12,19 +10,24 @@ module.exports = class extends global.yoho.BaseModel {
this.api = new CertApi(ctx);
this.captchaService = new CaptchaImgService(ctx);
this.certCheck = this.api.certCheck.bind(this.api);
this.sendCertMsg = this.api.sendCertMsg.bind(this.api);
this.certMobile = this.api.certMobile.bind(this.api);
this.relateMobile = this.api.relateMobile.bind(this.api);
this.checkEmailCertTip = this.api.checkEmailCertTip.bind(this.api);
}
async sendCertMsg(mobile, area, id, captcha) {
let result = await this.api.sendCertMsg(mobile, area, id, captcha);
let captchaNeed = await this.captchaService.try();
async certCheck(mobile, area, smsCode) {
let {code, data} = await this.api.certCheck(mobile, area, smsCode);
_.set(result, 'data.needCaptcha', captchaNeed);
if (!code || code !== 200) {
return {
error: new Error('error')
};
}
return result;
return {
result: data
};
}
};
... ...
... ... @@ -78,6 +78,7 @@ router.post('/passport/autouserinfo/relateMobile', bind.relateMobile);
// 未实名认证的老邮箱用户登录
router.get('/passport/cert/index', cert.index); /** 输入手机号码页面 **/
router.get('/passport/cert/success', cert.success); /** 成功提示页面 **/
router.post('/passport/cert/check', cert.check);
router.post('/passport/cert/sendCertMsg', cert.sendCertMsg);
router.post('/passport/cert/certMobile', cert.certMobile);
... ...
... ... @@ -6,9 +6,6 @@
<p class="safeword">为了您的账户安全,请您完善账户信息,以便为您提供更优质的服务!</p>
<form action="" id="bindmobileform" method="post">
<input type="hidden" id="username" name="username" value="{{username}}"/>
<input type="hidden" id="password" name="password" value="{{password}}"/>
<input type="hidden" value="86" id="areacode" name="area"/>
<input type="hidden" name="refer" value="{{refer}}">
<div class="yohobindrow" style="margin-bottom: 10px;">
... ... @@ -46,21 +43,23 @@
<div class="yohobindrow">
<div class="name phonetag">验证码</div>
<div class="content">
<div class="yohophonewrapper" style="width: 130px;">
<input type="text" class="validatenum phonenum" value="" id="validatenum" maxlength="4"/>
<div class="yohophonewrapper" style="width: 110px;">
<input type="text" class="validatenum phonenum" value="" id="smscode" maxlength="4"/>
<span class="err-tip code-err-tip hide">
<i></i>
<em></em>
<em>短信验证码错误</em>
</span>
</div>
</div>
<div class="validatewrapper">
<a href="javascript:void(0)" id="sendmessage" class="yohobindbtn left"
style="width: 130px; margin-left: 10px; height: 48px;">发送短信验证码</a>
style="width: 150px; margin-left: 10px; height: 48px;">发送短信验证码</a>
</div>
<div class="hide left" id="nopermissionmessage">
<span class="second">60</span>
秒后可重新操作
<div class="hide" id="nopermissionmessage">
<div class="second-timer">
<span class="second">60</span>
秒后可重新操作
</div>
</div>
</div>
</form>
... ...
<div>
<div class="title"> 该手机号已被注册,是否选择绑定?</div>
<div class="title2"> 点击“继续”原注册账号将被停用。</div>
</div>
... ...
<div>
<div class="title"> 该手机号已绑定Yoho!Family其他账号,</div>
<div class="question" > 点击“继续”将解绑并绑定当前账号。</div>
<div class="question"> 是否继续?</div>
<div class="subtitle">解绑后原帐号将不能使用该手机号登录!</div>
</div>
... ...
var Dialog = require('../../common/dialog').Dialog;
var infoTpl = require('hbs/passport/bind-info.hbs');
var infoTpl2 = require('hbs/passport/bind-info2.hbs');
exports.showBind = function(goLoginCb, goNextCb) {
var dia = new Dialog({
className: 'bind-info-wrapper',
closeIcon: true,
content: infoTpl(),
btns: [{
id: 'login',
btnClass: ['btn-cancel'],
name: '去登录',
cb: function() {
console.log('login');
goLoginCb && goLoginCb();
}
}, {
id: 'next',
btnClass: ['btn-ok'],
name: '继续',
cb: function() {
console.log('next');
goNextCb && goNextCb();
}
}]
});
dia.show();
};
exports.showBind2 = function(goLoginCb, goNextCb) {
var dia2 = new Dialog({
className: 'bind-info-wrapper',
closeIcon: true,
content: infoTpl2(),
btns: [{
id: 'login',
btnClass: ['btn-cancel'],
name: '去登录',
cb: function() {
goLoginCb && goLoginCb();
}
}, {
id: 'next',
btnClass: ['btn-ok'],
name: '继续',
cb: function() {
goNextCb && goNextCb();
}
}]
});
dia2.show();
};
... ...
/**
* 第三方登录首页
* @author: wq
* @date: 2016/1/21
* 邮箱登录绑定手机
* @author: htoo
* @date: 2018/1/18
*/
var $ = require('yoho-jquery');
var phoneRegx = require('../common/mail-phone-regx').phoneRegx;
... ... @@ -12,6 +12,7 @@ var $wrapper = $('.bindwrapper'),
$nextBtn = $wrapper.find('.yohobindbtn');
var Alert = require('../../common/dialog').Alert;
var dialog = require('./dialog');
var nopermissionoption = $('#nopermissionmessage').html();
var sendmessagehtml = $('.validatewrapper').html();
... ... @@ -164,6 +165,20 @@ function fixAreaNum() {
});
}
function goLogin() {
window.jumpUrl('/signin.html');
}
function goBind(area, mobile, code) {
$.post('/passport/cert/certMobile', { area, mobile, code }).then(function(result) {
if (result.code !== 200) {
return window.alert(result.message); // eslint-disable-line
}
window.jumpUrl('/passport/cert/success');
});
}
/**
* 点击下一步
... ... @@ -172,6 +187,7 @@ function fixAreaNum() {
function nextStep() {
var mobile = '';
var areaCode = '';
var smsCode = '';
$('#bindfirststep').on('click', function(e) {
var regx;
... ... @@ -180,6 +196,7 @@ function nextStep() {
mobile = $('.phonenum').val();
areaCode = $('#areanum').text();
regx = phoneRegx['+' + areaCode];
smsCode = $('#smscode').val();
if (!isagree()) {
return;
... ... @@ -190,22 +207,39 @@ function nextStep() {
return;
}
if (!$.trim(smsCode)) {
return;
}
$.ajax({
type: 'post',
url: '/passport/cert/check',
data: {
mobile: mobile,
area: areaCode
area: areaCode,
code: smsCode
},
dataType: 'json',
success: function(data) {
var isBind, isRegister;
if (data.code === 200) {
isBind = data.data && data.data.isBind;
isRegister = data.data && data.data.isRegister;
if (data.code === 200) { // 绑定/关联
$('#bindmobileform').attr('action', data.data.next);
$('#bindmobileform').submit();
} else if (data.code === 402) {
$phoneTip.find('em').text('手机格式错误');
$phoneTip.removeClass('hide');
if (isRegister === 'Y') {
if (isBind === 'N') {
dialog.showBind(goLogin, function() {
goBind(areaCode, mobile, smsCode);
});
} else {
dialog.showBind2(goLogin, function() {
goBind(areaCode, mobile, smsCode);
});
}
} else {
goBind(areaCode, mobile, smsCode);
}
} else {
if (data && data.message) {
new Alert(data.message).show();
... ...
... ... @@ -109,14 +109,15 @@
content: "";
}
#nopermissionmessage {
.second-timer {
display: block;
color: black;
float: left;
background-color: #d8d8d8;
text-align: center;
font-size: 16px;
line-height: 45px;
width: 130px;
width: 150px;
margin-left: 10px;
height: 48px;
}
... ... @@ -798,3 +799,59 @@
background: resolve("passport/angle.png");
}
}
.bind-info-wrapper {
.iconfont {
font-size: 25px;
}
.title {
font-size: 20px;
margin-top: 50px;
margin-bottom: 10px;
}
.title2 {
font-size: 20px;
margin-bottom: 55px;
}
.question {
font-size: 20px;
margin-bottom: 10px;
}
.subtitle {
font-size: 16px;
color: #999;
margin-top: 24px;
margin-bottom: 43px;
}
.btn-cancel {
border-radius: 3px;
width: 120px;
height: 35px;
line-height: 35px;
color: #999;
border: solid 1px #999;
padding: 0 !important;
}
.btn-ok {
width: 120px;
height: 35px;
color: white;
background: #444;
border-radius: 3px;
line-height: 35px;
border: solid 1px #444;
padding: 0 !important;
margin-left: 38px !important;
}
min-width: 320px !important;
padding-left: 55px;
padding-right: 55px;
padding-bottom: 40px;
}
... ...