Authored by htoooth

add fix

... ... @@ -16,7 +16,7 @@ const config = global.yoho.config;
const cache = global.yoho.cache;
const AuthHelper = require('../models/auth-helper');
const PassportHelper = require('../models/passport-helper');
const loginPage = `${config.siteUrl}/signin`;
const loginPage = `${config.siteUrl}/passport/login`;
// 第三方登录回调
function doPassportCallback(req, res, user) {
... ... @@ -302,67 +302,11 @@ const alipay = {
}
};
const douban = {
login: (req, res, next) => {
req.session = req.session || {};
req.session.authState = uuid.v4();
return passport.authenticate('douban', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res, next) => {
passport.authenticate('douban', (err, user) => {
if (err) {
log.error(`douban authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.displayName;
let openId = user.id;
doPassportCallback(req, res, {
openId: openId,
nickname: nickname,
sourceType: 'douban'
}).catch(next);
})(req, res, next);
}
};
const renren = {
login: (req, res, next) => {
req.session = req.session || {};
req.session.authState = uuid.v4();
return passport.authenticate('renren', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res, next) => {
passport.authenticate('renren', (err, user) => {
if (err) {
log.error(`renren authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.displayName;
let openId = user.id;
doPassportCallback(req, res, {
openId: openId,
nickname: nickname,
sourceType: 'renren'
}).catch(next);
})(req, res, next);
}
};
module.exports = {
common: common,
wechat: wechat,
local: local,
sina: sina,
wechat: wechat,
qq: qq,
alipay: alipay,
douban: douban,
renren: renren
sina: sina,
alipay: alipay
};
... ...
... ... @@ -69,7 +69,7 @@
<li class="clearfix">
<input name="refer" id="refer" type="hidden" value="http%3A%2F%2Fwww.yohoblk.com%2F">
<div class="center">
<input id="find-btn" class="find-btn disable" type="submit" value="下一步">
<a id="find-btn" class="find-btn disable" >下一步</a>
</div>
</li>
</form>
... ...
... ... @@ -15,7 +15,8 @@ var $regionCodeText = $('#country-code'),
$imgCaptchaInput = $('#verifyCode'),
$regionSelectCtrl = $('#area'),
$nextBtn = $('#find-btn'),
$phone = $('#phone');
$phone = $('#phone'),
$form = $('#back-form');
var emailRegx = regx.emailRegx,
phoneRegx = regx.phoneRegx;
... ... @@ -73,15 +74,8 @@ function validatePhoneNumAsync() {
}
function nextStep(url) {
return $.ajax({
type: 'POST',
url: url,
data: {
verifyCode: $.trim($imgCaptchaInput.val()),
phoneNum: $phoneNumInput.val(),
area: $regionCodeText.text()
}
});
$form.attr('action', url);
$form.submit();
}
function validatePhoneNumLocal() {
... ... @@ -230,22 +224,21 @@ exports.init = function() {
});
$nextBtn.on('click', function() {
var urlPhone = '/passport/back/mobile',
urlEmail = '/passport/back/email';
var url = null;
if ($(this).hasClass('disable')) {
return;
}
if (/^[0-9]+$/.test($.trim($phoneNumInput.val()))) {
url = urlPhone;
} else {
url = urlEmail;
}
if ($(this).hasClass('disable')) {
return;
}
$nextBtn.addClass('disable');
nextStep(url);
... ...
... ... @@ -9,7 +9,7 @@ var EventProxy = require('../common/eventproxy');
var $phoneNumInput = $('#account'),
$passwordInput = $('#password'),
$captchaInput = $('#captcha'),
$imgCaptchaInput = $('#captcha'),
$loginBtn = $('#login-btn'),
$phone = $('#phone');
... ... @@ -37,8 +37,6 @@ var checkbox = {
unchecked: '&#xe601;'
};
var emailAcTime;
var $errTip = $('.tips');
var $errMsg = $errTip.find('.rectangle');
... ... @@ -56,7 +54,6 @@ function errTip(ele, msg) {
}).removeClass('hide');
}
// 验证账户名
function validateAccountLocal() {
var phoneNum = $.trim($phoneNumInput.val()),
... ... @@ -66,7 +63,6 @@ function validateAccountLocal() {
if (/^[0-9]+$/.test(phoneNum)) {
// 不是11位
if (phoneNum.length !== 11) {
ep.emit('phone', false);
errTip($phone, '手机号码不正确,请重新输入');
return false;
}
... ... @@ -74,10 +70,8 @@ function validateAccountLocal() {
// 如果是纯数字,则作为手机号码处理
if (regionCode !== '+86' ||
mailPhoneRegx.phoneRegx[regionCode].test(phoneNum)) {
ep.emit('phone', true);
return true;
} else {
ep.emit('phone', false);
errTip($phone, '手机号码不正确,请重新输入');
return false;
}
... ... @@ -85,17 +79,14 @@ function validateAccountLocal() {
// 邮箱验证
if (mailPhoneRegx.emailRegx.test(phoneNum)) {
ep.emit('phone', true);
return true;
} else {
ep.emit('phone', false);
errTip($phone, '邮箱格式不正确,请重新输入');
return false;
}
}
} else {
ep.emit('phone', false);
errTip($phone, '请输入账号');
return false;
}
... ... @@ -111,10 +102,8 @@ function validateAccountAsync() {
}
}).then(function(data) {
if (data.code && data.code === 200) {
ep.emit('phone', true);
return true;
} else {
ep.emit('phone', false);
errTip($phone, '账号不存在');
return false;
}
... ... @@ -122,17 +111,29 @@ function validateAccountAsync() {
}
function validateAccount() {
function validate() {
var defer = $.Deferred(); // eslint-disable-line
if (validateAccountLocal()) {
validateAccountAsync().then(function(result) {
if (result) {
defer.resolve(result);
} else {
defer.reject(result);
}
});
} else {
defer.resolve(false);
defer.reject(false);
}
return defer.promise();
}
return validate().then(function() {
ep.emit('phone', true);
}).fail(function() {
ep.emit('phone', false);
});
}
// 验证密码
... ... @@ -158,7 +159,7 @@ function validatePasswordLocal() {
// 验证验证码
function validateCaptchaLocal() {
var captcha = $.trim($captchaInput.val());
var captcha = $.trim($imgCaptchaInput.val());
var length = captcha.length;
if ($captchaWrap.hasClass('hide')) {
... ... @@ -168,14 +169,14 @@ function validateCaptchaLocal() {
switch (length) {
case 0:
errTip($captchaInput, '请输入验证码');
errTip($imgCaptchaInput, '请输入验证码');
ep.emit('captcha', false);
break;
case 4:
ep.emit('captcha', true);
break;
default:
errTip($captchaInput, '请输入长度为4字符的验证码');
errTip($imgCaptchaInput, '请输入长度为4字符的验证码');
ep.emit('captcha', false);
break;
}
... ... @@ -185,7 +186,7 @@ function validateCaptchaLocal() {
function showAccountErrTimes() {
$captchaWrap.removeClass('hide');
$captchaImg.attr('src', captchaUrl + $.now());
$captchaInput.val('');
$imgCaptchaInput.val('');
}
// 登录
... ... @@ -197,7 +198,7 @@ function login() {
areaCode: $regionCodeText.text().replace('+', ''),
account: $.trim($phoneNumInput.val()),
password: $.trim($passwordInput.val()),
captcha: $.trim($captchaInput.val()),
captcha: $.trim($imgCaptchaInput.val()),
isRemember: $remember.hasClass('checked') ? true : false
},
success: function(res) {
... ... @@ -209,7 +210,7 @@ function login() {
}
} else {
if (res.data.errorType === 'captcha') {
$captchaInput.val('');
$imgCaptchaInput.val('');
} else {
$loginTip.removeClass('hide').children('em').html(res.message);
$passwordInput.val('');
... ... @@ -225,7 +226,7 @@ function login() {
}
mailAc($phoneNumInput, function() {
function validateUser() {
function throttle() {
return $.ajax({
url: '/passport/login/account',
type: 'GET',
... ... @@ -237,7 +238,7 @@ mailAc($phoneNumInput, function() {
validateAccount().then(function(result) {
if (result) {
return validateUser();
return throttle();
} else {
return false;
}
... ... @@ -260,6 +261,7 @@ $phoneNumInput.on('focus', function() {
$('[placeholder]').placeholder();
// 选择地点
$regionSelectCtrl.change(function() {
var $this = $(this);
... ... @@ -270,22 +272,20 @@ $regionSelectCtrl.change(function() {
$passwordInput.on('blur', function() {
$passwordInput.removeClass('focus');
validatePasswordLocal();
$captchaInput.trigger('blur');
}).on('focus', function() {
$passwordInput.addClass('focus');
});
// 验证码
$captchaInput.on('blur', function() {
$captchaInput.removeClass('focus');
$imgCaptchaInput.on('blur', function() {
$imgCaptchaInput.removeClass('focus');
validateCaptchaLocal();
}).on('focus', function() {
$captchaInput.addClass('focus');
$imgCaptchaInput.addClass('focus');
});
// 邮箱自动完成列表项点击
$emailAutoComplete.on('click', 'li', function() {
clearTimeout(emailAcTime); // 清空默认关闭
$phoneNumInput.val($(this).text()).focus();
$emailAutoComplete.addClass('hide');
});
... ... @@ -303,13 +303,6 @@ $remember.on('click', function() {
}
});
// focus到输入框则隐藏错误提示和样式
$('.va').on('focus', function() {
var $this = $(this);
$this.siblings('.err-tip').addClass('hide');
});
// 验证码刷新
$captchaWrap.on('click', '.change-captcha, .captcha-img', function() {
$captchaImg.attr('src', captchaUrl + $.now());
... ... @@ -363,3 +356,5 @@ $('input.va').on('keypress', function(e) {
}
});
// 首次触发
$imgCaptchaInput.trigger('blur');
... ...
... ... @@ -87,12 +87,13 @@
}
.find-btn {
border: 0;
display: inline-block;
width: 180px;
height: $item-height;
background-color: $theme-color;
color: white;
margin-top: 40px;
line-height: @height;
&.disable {
background-color: $inactive-color;
... ...