Authored by 刘传洋

m

... ... @@ -10,21 +10,9 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const passportHelper = require('../models/passport-helper');
const certService = require('../models/cert-service');
const loginService = require('../models/login-service');
const userService = require('../models/user-service');
// const UserService = require('../models/user-service');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
const Sources = {
qq: 'QQ',
sina: '微博',
alipay: '支付宝',
wechat: '微信',
renren: '人人',
douban: '豆瓣'
};
const cert = {
tip: (req, res) => {
let refer = req.query.refer;
... ... @@ -77,17 +65,15 @@ const cert = {
title: '账号关联'
});
res.render('bind/relate', data);
res.render('cert/relate', data);
}).catch(next);
},
success: (req, res) => {
let sourceType = _.trim(req.query.sourceType);
let sourceInfo = sourceType.split('_');
let sourceName = Sources[sourceInfo[0]];
let isRelate = (sourceInfo[1] === 'relate');
let type = _.trim(req.query.type);
let refer = req.query.refer;
let isRelate = (type === 'relate');
let data = {
goShopping: helpers.urlFormat('/'),
sourceName: sourceName,
goShopping: refer,
relate: isRelate,
module: 'passport',
page: 'cert-success',
... ... @@ -95,16 +81,12 @@ const cert = {
title: '绑定手机号'
};
res.render('bind/success', data);
res.render('cert/success', data);
},
check: (req, res, next) => {
let mobile = req.body.mobile;
// let openId = req.body.openId;
let area = req.body.area || '86';
// let sourceType = req.body.sourceType;
if (mobile && area) {
/**
... ... @@ -148,75 +130,81 @@ 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 openId = _.trim(req.body.openId);
let sourceType = _.trim(req.body.sourceType);
let code = _.trim(req.body.code);
let password = _.trim(req.body.password) || '';
let refer = req.body.refer;
bindService.checkBindCode(area, mobile, code).then(result => {
if (result && result.code !== 200) {
return {code: 402, message: '短信验证码不正确', data: ''};
} else {
return bindService.bindMobile(openId, sourceType, mobile, area, password);
}
}).then(result => {
if (result && result.code) {
if (result.code === 200 && result.data && result.data.uid) {
let refer = helpers.urlFormat('/passport/thirdlogin/bindsuccess', {
sourceType: sourceType + '_bind'
});
certService.certMobile(uid, mobile, code, area).then(result => {
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
return {code: result.code, message: result.message, data: {refer: ''}};
}
if (result && result.code === 200) {
let url = helpers.urlFormat('/passport/cert/success', {
type: 'cert',
refer: refer
});
return {
code: 200,
message: result.message,
data: {
nextUrl: url
}
};
} else {
return {code: 400, message: '', data: ''};
return {
code: _.get(result, 'code', 400),
message: _.get(result, 'message')
};
}
}).then(result => {
return res.json(result);
res.json(result);
}).catch(next);
},
relateMobile: (req, res, next) => {
let mobile = req.body.mobile;
let openId = req.body.openId;
let areaCode = req.body.areaCode || '86';
let sourceType = req.body.sourceType;
let code = req.body.code;
if (_.toNumber(mobile) && openId && areaCode && sourceType && code) {
bindService.checkBindCode(areaCode, mobile, code).then(result => {
if (result && result.code && result.code === 200) {
return bindService.relateMobile(openId, sourceType, mobile, areaCode);
} else {
return {code: 402, message: '短信验证码错误', data: ''};
}
}).then(result => {
if (result && result.code) {
if (result.code === 200 && result.data && result.data.uid) {
let refer = helpers.urlFormat('/passport/thirdlogin/bindsuccess', {
sourceType: sourceType + '_relate'
});
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
return {code: result.code, message: result.message, data: {refer: ''}};
}
let uid = req.user.uid;
let mobile = _.trim(req.body.mobile);
let area = _.trim(req.body.areaCode) || '86';
let code = _.trim(req.body.code);
let refer = req.body.refer;
let email;
userService.profile(uid).then(info => {
if (info && info.code === 200) {
email = _.get(info, 'data.email');
} else {
res.json({
code: 400,
message: '系统错误,请稍后再试!'
});
}
certService.relateMobile(uid, email, code, mobile, area).then(result => {
if (result && result.code === 200) {
let url = helpers.urlFormat('/passport/cert/success', {
type: 'relate',
refer: refer
});
return {
code: 200,
message: result.message,
data: {
nextUrl: url
}
};
} else {
return {code: 400, message: '', data: ''};
return {
code: _.get(result, 'code', 400),
message: _.get(result, 'message')
};
}
}).then(result => {
return res.json(result);
res.json(result);
}).catch(next);
} else {
return res.json({code: 400, message: '', data: ''});
}
}).catch(next);
}
};
... ...
... ... @@ -31,6 +31,7 @@
<div class="btnwrapper confirmwrapper">
<a href="javascript:void(0)" class="yohobindbtn" id="confirmsubmit" >确定</a>
<a href="javascript:void(0)">上一步</a>
</div>
<input type="hidden" value="{{mobile}}" id="mobile" name="mobile"/>
<input type="hidden" value="{{area}}" id="area"/>
... ...
... ... @@ -4,7 +4,7 @@
<span class="yoho">YOHO!FAMILY</span>
</h3>
<p class="safeword">为了您的账户安全,请您完善账户信息,以便为您提供更优质的服务</p>
<p class="safeword">为了您的账户安全,请您完善账户信息,以便为您提供更优质的服务</p>
<form action="" id="bindmobileform" method="post">
<input type="hidden" value="86" id="areacode" name="area"/>
<div class="yohobindrow">
... ... @@ -75,7 +75,7 @@
</div>
<div class="backdrop" style="display:none"></div>
</div>-->
<div id="alreayregist" style="display:none">
<!--<div id="alreayregist" style="display:none">
<div class="mask">
<div class="bindconfrimwrapper">
<div class="topwrapper">
... ... @@ -118,4 +118,4 @@
</div>
</div>
<div class="backdrop" style="display:none"></div>
</div>
</div>-->
... ...
... ... @@ -9,9 +9,9 @@
{{/if}}
</div>
{{#if relate}}
<h3 class="info">该手机号码不能用来登录此账户,您可以选择继续使用{{sourceName}}登录</h3>
<h3 class="info">该手机号码不能用来登录此账户,您可以选择继续使用邮箱登录</h3>
{{^}}
<h3 class="info">今后您可以选择{{sourceName}}或绑定的手机号码+密码的方式登录此账户</h3>
<h3 class="info">今后您可以选择邮箱或绑定的手机号码+密码的方式登录此账户</h3>
{{/if}}
<a href="{{goShopping}}" class="yohobindbtn gobuynow">立即购物</a>
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -60,36 +60,6 @@ function getcomplex(curType, preType) {
}
}
/**
* @desc: 计算密码复杂度(from:http://www.oschina.net/code/snippet_127301_17269)
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/5/6
*/
function computeComplex(password) {
var complex = 0;
var length = password.length;
var pre = '';
var preType = 0;
var i = 0;
var cur = '';
var curType = '';
for (i; i < length; i++) {
cur = password.charAt(i);
curType = gettype(password, i);
if (preType !== curType || !isregular(cur, pre, curType)) {
complex += curType + getcomplex(curType, preType);
}
pre = cur;
preType = curType;
}
return complex;
}
function changeSecond() {
second -= 1;
if (second < 0) {
... ... @@ -122,7 +92,7 @@ function sendMessageValidate() {
area = $('#area').val();
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/sendBindMsg',
url: '/passport/cert/sendCertMsg',
data: {
mobile: mobile,
area: area
... ... @@ -136,127 +106,28 @@ function sendMessageValidate() {
});
}
function codeValidate() {
var validatenum = '';
$(document).on('keyup', '#validatenum', function() {
$('#err-info').hide();
validatenum = $(this).val();
if (validatenum.length === 4) {
if (!dovalidate) {
dovalidate = true;
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/checkBindMsg',
data: {
code: validatenum,
mobile: $('#mobile').val(),
area: $('#area').val()
}
}).then(function(data) {
dovalidate = false;
if (data.code !== 200) {
$('#err-info').show();
} else {
isvalidatecode = true;
}
});
}
}
});
}
function pwdKeyupEvt() {
var pwd = $pwd.val(),
pwdStrength = computeComplex(pwd),
level = 0;
if (pwdStrength === 0) {
level = 0;
} else if (pwdStrength <= 10) {
level = 1;
} else if (pwdStrength <= 20) {
level = 2;
} else {
level = 3;
}
switch (level) {
case 0:
$pwdParent.removeClass('red yellow green');
$pwdIntensity.removeClass('color');
break;
case 1:
$pwdParent.addClass('red').removeClass('yellow green');
$pwdIntensity.filter('.low').addClass('color');
$pwdIntensity.filter('.mid,.high').removeClass('color');
break;
case 2:
$pwdParent.addClass('yellow').removeClass('red green');
$pwdIntensity.filter('.low,.mid').addClass('color');
$pwdIntensity.filter('.high').removeClass('color');
break;
case 3:
$pwdParent.addClass('green').removeClass('yellow red');
$pwdIntensity.addClass('color');
break;
default:
break;
}
if (pwd === '') {
isvalidatepwd = false;
$pwdTip1.removeClass('red yes no').addClass('default');
} else {
if (pwd.length < 6 || pwd.length > 20) {
isvalidatepwd = false;
$pwdTip1.removeClass('default yes').addClass('no red');
} else {
isvalidatepwd = true;
$pwdTip1.removeClass('default no red').addClass('yes');
}
}
}
function validatePwd() {
$(document).on('keyup', '.pwdcontent', function() {
pwdKeyupEvt($(this));
});
$(document).on('focus', '.pwdcontent', function() {
$('#pwd-tips').removeClass('hide');
});
$(document).on('blur', '.pwdcontent', function() {
$('#pwd-tips').addClass('hide');
});
}
/**
* 最终提交表单
*/
function actionSubmit() {
var mobile = '';
var area = '';
var pwd = '';
var code = '';
area = $('#area').val();
pwd = $('#pwd').val();
mobile = $('#mobile').val();
code = $('#validatenum').val();
$.ajax({
type: 'POST',
url: '/passport/autouserinfo/bindMobile',
url: '/passport/cert/certMobile',
data: {
area: area,
openId: $('#openId').val(),
sourceType: $('#sourceType').val(),
mobile: mobile,
password: pwd,
code: code
}
}).then(function(data) {
if (data.code === 200) {
window.location.href = '/passport/thirdlogin/bindsuccess';
window.location.href = data.data.nextUrl;
} else {
alert(data.message);
}
... ... @@ -269,31 +140,18 @@ function actionSubmit() {
*/
function actionConfirm() {
var validatenum = '';
var pwd = '';
$('#confirmsubmit').on('click', function() {
validatenum = $('#validatenum').val();
pwd = $('#pwd').val();
if (validatenum === '') {
alert('短信验证码不能为空');
return;
}
if (pwd === '') {
alert('密码不能为空');
return;
}
if (!/^(?![^a-zA-Z]+$)(?!\D+$).{6,20}$/.test(pwd)) {
alert('密码只支持6-20位字符,建议字母+数字的组合。');
return;
}
if (isvalidatecode === false) {
alert('请输入正确的验证码');
return;
}
if (isvalidatepwd === false) {
alert('请输入符合强度的密码');
return;
}
actionSubmit();
});
}
... ... @@ -302,13 +160,8 @@ function actionConfirm() {
function init() {
circleTime(); // 倒计时
$pwd = $('#pwd');
$pwdParent = $('.safelevel');
$pwdIntensity = $('.pwd-intensity');
$pwdTip1 = $('#pwd-tip1');
sendMessageValidate();
codeValidate();
validatePwd();
actionConfirm();
}
... ...
... ... @@ -6,11 +6,11 @@
var $ = require('yoho-jquery');
var phoneRegx = require('../common/mail-phone-regx').phoneRegx;
var nopermissionoption = $('#nopermissionmessage').html(); // 倒计时dom
var sendmessagehtml = $('.validatewrapper').html(); // 发送短信dom
// var nopermissionoption = $('#nopermissionmessage').html(); // 倒计时dom
// var sendmessagehtml = $('.validatewrapper').html(); // 发送短信dom
var second = +$('.second').text(); // 倒计时秒数
var dovalidate = false; // 校验验证码标识
var validatecode = false; // 验证码是否通过
// var validatecode = false; // 验证码是否通过
var choosedpic = 'http://cdn.yoho.cn/yohobuy/assets/img/passport/choosed.png';// 已选择图片
var $wrapper = $('.bindwrapper'),
... ... @@ -27,7 +27,7 @@ function chooseProtocol() {
$('.choosetag').on('change', function() {
var btnColor = '#f02200';
if ($(this).attr('checked') === 'checked') {
if ($(this).prop('checked')) {
$('.choosewrapper').css({
'background-image': 'url("' + choosedpic + '")'
});
... ... @@ -48,7 +48,7 @@ function chooseProtocol() {
* @return {[type]} [description]
*/
function isagree() {
return $('.choosetag').attr('checked') === 'checked';
return $('.choosetag').prop('checked');
}
/**
... ... @@ -65,7 +65,7 @@ function chooseAreaToogle() {
* 验证码校验
* @return {[type]} [description]
*/
function codeValidate() {
/* function codeValidate() {
var validatenum = '';
$(document).on('keyup', '#validatenum', function() {
... ... @@ -98,7 +98,7 @@ function codeValidate() {
}).blur(function() {
$(this).attr('placeholder', '验证码');
});
}
}*/
/**
* 选择区域
... ... @@ -156,7 +156,7 @@ function fixAreaNum() {
* 关闭蒙层
* @return {[type]} [description]
*/
function closeMask() {
/* function closeMask() {
var $target;
$(document).on('click', '#alreayregist', function(e) {
... ... @@ -167,37 +167,37 @@ function closeMask() {
}
});
/* $(document).on('click', '#bindconfirm', function(e) {
$(document).on('click', '#bindconfirm', function(e) {
$target = $(e.target);
if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
$('#bindconfirm').hide();
$('.backdrop').hide();
}
});*/
}
});
}*/
/**
* 绑定其他手机号
* @return {[type]} [description]
*/
function yohoBindBtn() {
/* $(document).on('click', '#yohobindbtn', function() {
/* function yohoBindBtn() {
$(document).on('click', '#yohobindbtn', function() {
$('.phonenum').val('');
$('#bindconfirm').hide();
$('.backdrop').hide();
});*/
});
$(document).on('click', '#yohobindbtn2', function() {
$('.phonenum').val('');
$('#alreayregist').hide();
$('.backdrop').hide();
});
}
}*/
/**
* 发送短信的时间变换动画
* @return {[type]} [description]
*/
function changeSecond() {
/* function changeSecond() {
second -= 1;
if (second < 0) {
second = 60;
... ... @@ -208,23 +208,23 @@ function changeSecond() {
window.setTimeout(changeSecond, 1000);
}
}
}*/
/**
* 时间循环
* @param {[type]} phonenum [description]
* @return {[type]} [description]
*/
function circleTime(phonenum) {
/* function circleTime(phonenum) {
$('.validatewrapper').html(nopermissionoption);
window.setTimeout(changeSecond, 1000);
}
}*/
/**
* 发送短信
* @return {[type]} [description]
*/
function sendMessageValidate() {
/* function sendMessageValidate() {
$(document).on('click', '#sendmessage', function() {
if ($('#sendmessage').attr('disabled') === 'disabled') {
return;
... ... @@ -244,12 +244,12 @@ function sendMessageValidate() {
});
});
}
}*/
/**
* 最终提交表单
*/
function actionSubmit() {
/* function actionSubmit() {
var mobile = '';
var area = '';
... ... @@ -276,13 +276,13 @@ function actionSubmit() {
alert(data.message);
}
});
}
}*/
/**
* 确认去绑定
* @return {[type]} [description]
*/
function goToBindPhone() {
/* function goToBindPhone() {
$(document).on('click', '#gotobindphone', function() {
if (validatecode === true) {
$('#inarea').val($('#areacode').val());
... ... @@ -292,7 +292,7 @@ function goToBindPhone() {
alert('请输入正确验证码');
}
});
}
}*/
/**
* 点击下一步
... ... @@ -301,8 +301,9 @@ function goToBindPhone() {
function nextStep() {
var mobile = '';
var areaCode = '';
var username = '';
var headImg = '';
// var username = '';
// var headImg = '';
$('#bindfirststep').on('click', function(e) {
var regx;
... ... @@ -356,15 +357,15 @@ $wrapper.on('keydown', '.phonenum', function(e) {
function init() {
fixAreaNum(); // 去掉所有区域的+
sendMessageValidate(); // 有交互的发送短信
// sendMessageValidate(); // 有交互的发送短信
chooseProtocol(); // 选择协议
chooseArea(); // 选择区域
chooseAreaToogle(); // 选择区域展示或关闭
cancelChooseArea(); // 取消选择区域
nextStep(); // 下一步
closeMask(); // 关闭蒙层
yohoBindBtn(); // 绑定其他手机号点击
goToBindPhone(); // 绑定手机
codeValidate(); // 验证码校验
// closeMask(); // 关闭蒙层
// yohoBindBtn(); // 绑定其他手机号点击
// goToBindPhone(); // 绑定手机
// codeValidate(); // 验证码校验
}
init();
... ...