Authored by ccbikai(👎🏻🍜)

Merge branch 'hotfix/removeCapture'

... ... @@ -142,7 +142,6 @@ const indexMobilePage = (req, res, next) => {
service.getAreaDataAsync()
.then(result => {
res.render('back/mobile', Object.assign({
width750: true,
module: 'passport',
page: 'back-mobile',
title: '找回密码-通过手机号'
... ... @@ -218,13 +217,11 @@ const sendCodeToMobileAPI = (req, res, next) => {
}
req.session.backupCaptch.useTime = req.session.backupCaptch.useTime - 1;
} else {
_.set(req.session, 'backupCaptch.useTime', 5);
req.session.backupCaptch.useTime = 5;
}
if (verifyCode) {
let captcha = _.get(req, 'session.captcha');
if (captcha && verifyCode.toString() === captcha) {
if (verifyCode.toString() === _.get(req, 'session.backupCaptch.code', '').toString()) {
req.session.backupCaptch.verifyResult = true;
} else {
return res.json({
... ...
... ... @@ -5,7 +5,7 @@
* @date: 2016/05/09
*/
'use strict';
const _ = require('lodash');
const passport = require('passport');
// const md5 = require('md5');
... ... @@ -78,7 +78,6 @@ const common = {
}
};
const local = {
loginPage: (req, res) => {
// 先清除cookie
... ... @@ -98,9 +97,7 @@ const local = {
});
res.render('login', {
width750: true,
loginIndex: true, // 模板中使用JS的标识
captchaShow: _.get(req.session, 'login.errorCount') <= 0,
// 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
... ... @@ -138,11 +135,9 @@ const local = {
});
res.render('international', {
width750: true,
// 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
loginInternational: true, // 模板中使用JS的标识
captchaShow: _.get(req.session, 'login.errorCount') <= 0,
isPassportPage: true, // 模板中模块标识
headerText: '登录',
areaCode: '+86', // 默认区号
... ... @@ -153,44 +148,13 @@ const local = {
});
},
login: (req, res, next) => {
let count = _.get(req.session, 'login.errorCount');
if (count == null) { // eslint-disable-line
_.set(req.session, 'login.errorCount', 3);
} else if (count <= 0) {
let captchaInput = req.body.captcha;
let captchaCode = _.get(req.session, 'captcha');
delete req.session.captcha; // 用过就丢弃
if (!captchaInput || !captchaCode || captchaInput !== captchaCode) {
res.json({
code: 400,
message: '请将图片旋转到正确方向',
captchaShow: true
});
return;
}
}
passport.authenticate('local', (err, user) => {
let loginSession = req.session.login;
if (err) {
let obj = {
res.json({
code: 400,
message: err,
data: ''
};
--loginSession.errorCount;
if (loginSession.errorCount <= 0) {
obj.captchaShow = true;
}
res.json(obj);
});
} else {
let refer = req.cookies.refer;
... ...
... ... @@ -8,7 +8,6 @@
'use strict';
const _ = require('lodash');
const url = require('url');
const utils = require(global.utils);
const helpers = global.yoho.helpers;
const sign = global.yoho.sign;
... ... @@ -27,7 +26,6 @@ const captchaService = require('../models/captcha-service');
}
*/
/**
* 步骤校验
* step: 预期步骤
... ... @@ -60,17 +58,6 @@ let index = (req, res) => {
return res.redirect(req.get('refer') || '/');
}
// 判断是否 来自 个人中心
if (!_.get(req.session, 'phoneReg.isFromMy')) {
let referer = req.get('Referer') || '';
let urlObj = url.parse(referer, true, true);
referer = _.get(urlObj, 'query.refer', '');
urlObj = url.parse(referer, true, true);
urlObj.path === '/home' && _.set(req.session, 'phoneReg.isFromMy', '1');
}
// 设置注册有效时间30分钟, 防机器刷
// req.session.REG_EXPIRE = Date.now() + 1800000;
let refer = req.query.refer;
... ... @@ -89,7 +76,6 @@ let index = (req, res) => {
}
res.render('reg/index', {
width750: true,
module: 'passport',
page: 'reg',
title: '注册',
... ... @@ -113,7 +99,7 @@ let verifyMobile = (req, res, next) => {
let mobile = +req.body.phoneNum;
let area = +(req.body.areaCode || 86);
let captcha = (req.body.captcha || '').trim();
let diffCaptcha = _.get(req.session, 'captcha');
let diffCaptcha = _.get(req.session, 'phoneReg.captcha');
// error case: 没有验证码
if (!diffCaptcha) {
... ... @@ -124,7 +110,7 @@ let verifyMobile = (req, res, next) => {
});
}
delete req.session.captcha; // captcha 一次性
delete req.session.phoneReg.captcha; // captcha 一次性
// error case: 验证码不匹配
if (captcha !== diffCaptcha) {
... ... @@ -199,6 +185,7 @@ let codeAction = (req, res, next) => {
res.render('reg/code', {
page: 'code',
title: '注册-验证码',
backUrl: '/?go=1', // eslint-disable-line
headerText: '注册', // 头部信息
isPassportPage: true, // 模板中模块标识
areaCode: area, // 默认的区号
... ... @@ -374,7 +361,6 @@ let setPassword = (req, res, next) => {
let password = req.body.password;
let token = req.body.token;
let smsCode = +req.body.smsCode;
let isFromMy = _.get(req.session, 'phoneReg.isFromMy', '0');
// 判断参数是否合法
if (!smsCode || !_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) {
... ... @@ -397,40 +383,29 @@ let setPassword = (req, res, next) => {
let shoppingKey = cookie.getShoppingKey(req);
// 验证注册的标识码是否有效
let resultCopy = null;
RegService.regMobileAes(area, mobile, password, shoppingKey, smsCode, isFromMy).then((result) => {
RegService.regMobileAes(area, mobile, password, shoppingKey, smsCode).then((result) => {
if (!result.code || result.code !== 200) {
return Promise.reject(result);
}
if (!result.data || !result.data.uid) {
return Promise.reject(result);
}
resultCopy = result;
return AuthHelper.syncUserSession(result.data.uid, req, res);
}).then(() => {
// 返回跳转到来源页面
let refer = req.cookies.refer;
// isFromMy to 新人会场
if (resultCopy.data.newUserPage) {
refer = resultCopy.data.msgDelivery; // 来自个人中心,跳新人会场
if (refer) {
refer = decodeURI(req.cookies.refer);
} else {
if (refer) {
refer = decodeURI(req.cookies.refer);
} else {
refer = '/home';
}
if (/sign|login/.test(refer)) {
refer = '/home';
}
refer = '/home';
}
refer = utils.refererLimit(refer);
if (/sign|login/.test(refer)) {
refer = '/home';
}
refer = utils.refererLimit(refer);
delete req.session.phoneNum;
... ...
/* eslint no-unused-vars: ["error", { "args": "none" }] */
'use strict';
const _ = require('lodash');
const moment = require('moment');
const helpers = global.yoho.helpers;
const cookie = global.yoho.cookie;
const EventEmitter = require('events');
const utils = require(global.utils);
const RegService = require('../models/reg-service');
const PhoneService = require('../models/phone-service');
const AuthHelper = require('../models/auth-helper');
const captchaService = require('../models/captcha-service');
// constrant
const CODE_REQUIRED = '请输入校验码';
const PASSWORD_REQUIRED = '请输入密码';
const PASSWORD_LENGTH_ERROR = '密码6-20位,请重新输入';
const BAD_PASSWORD = '密码格式不正确';
const TOO_MANY = '请求太频繁';
const LOGIN_SUCCSS = '登录成功';
const VERIFY_ERROR = '校验失败';
... ... @@ -44,7 +44,6 @@ const _step1 = (req, res, next) => {
let template = 'sms/login';
let viewData = {
width750: true,
module: 'passport',
page: 'sms-login',
title: '手机短信登录',
... ... @@ -56,8 +55,6 @@ const _step1 = (req, res, next) => {
};
res.render(template, viewData);
};
// 短信登录 第二步: 输入 校验码
... ... @@ -121,75 +118,44 @@ exports.loginPage = (req, res, next) => {
}
};
/**
* step1 的表单提交验证
*/
exports.indexCheck = (req, res, next) => {
_.set(req.session, 'smsLogin.step', 1);
let area = req.body.area = (req.body.area || '').trim();
let mobile = req.body.mobile = (req.body.mobile || '').trim();
let captcode = (req.body.captcode || '').trim();
let captcodeValid = _.get(req.session, 'captcha');
let em = new EventEmitter();
// 校验 成功
em.on('resolve', () => {
// 1. 将信息放入 session
_.set(req.session, 'smsLogin.area', area);
_.set(req.session, 'smsLogin.mobile', mobile);
_.set(req.session, 'smsLogin.step', 2);
PhoneService.sendSMS(mobile, area, 1);
--req.session.smsLogin.count;
if (!req.session.smsLogin.count) {
_.set(req.session, 'smsLogin.interval', Date.now() + 5 * 60 * 1000);
} else {
_.set(req.session, 'smsLogin.interval', Date.now() + 60 * 1000);
}
res.json({
code: 200,
redirect: '/passport/sms_login?step=2'
});
});
// 校验 失败
em.on('reject', error => {
_.set(req.session, 'smsLogin.step', 1);
res.json(error);
});
exports.tokenBefore = (req, res, next) => {
let area = req.query.area = (req.query.area || '').trim();
let mobile = req.query.mobile = (req.query.mobile || '').trim();
let step = _.get(req.session, 'smsLogin.step');
let count = _.get(req.session, 'smsLogin.count');
let interval = _.get(req.session, 'smsLogin.interval');
let captcha1 = _.get(req.session, 'smsLogin.captcha');
let captcha2 = (req.query.captcha || '').trim();
req.session.captcha = void 0; // 验证码 用过就扔
if (!req.xhr) {
return next(404);
}
// 验证
if ([area, mobile].some(val => val === '')) {
return em.emit('reject', {code: 400, message: '请填写手机号'});
} else if (!captcode) {
return em.emit('reject', {code: 400, message: '请填写验证码'});
} else if (captcode !== captcodeValid) {
return em.emit('reject', {code: 400, message: '请将图片旋转到正确位置'});
return res.json({
code: 401,
message: '手机号 必填'
});
}
// congratulation~~
em.emit('resolve');
};
exports.tokenBefore = (req, res, next) => {
let step = _.get(req.session, 'smsLogin.step');
let count = _.get(req.session, 'smsLogin.count');
let interval = _.get(req.session, 'smsLogin.interval');
delete req.session.smsLogin.captcha; // 图形验证码 一次性
// step1 要 校验图形验证码
if (step === 1) {
if (!captcha2) {
return res.json({
code: 400,
message: '请填写验证码'
});
}
if (!req.xhr || step !== 2) {
return next(404);
if (captcha1 !== captcha2) {
return res.json({
code: 400,
message: VERIFY_ERROR
});
}
}
let now = Date.now();
... ... @@ -198,14 +164,11 @@ exports.tokenBefore = (req, res, next) => {
// 1. 过了冻结期, count 重设为 5次
// 2. 没过冻结期, end
// 没有用完, 判断是否请求太频繁
let during = moment.duration(interval - now, 'ms').minutes();
let message = `请${during}分钟后再试`;
if (!count) {
if (interval > now) {
return res.json({
code: 400,
message: message,
message: TOO_MANY,
during: Math.ceil((interval - now) / 1000)
});
} else {
... ... @@ -214,19 +177,17 @@ exports.tokenBefore = (req, res, next) => {
} else if (interval > now) {
return res.json({
code: 429,
message: message
message: TOO_MANY
});
}
next();
};
// AJAX 获取验证码
exports.token = (req, res, next) => {
let area = _.get(req.session, 'smsLogin.area');
let mobile = _.get(req.session, 'smsLogin.mobile');
let area = req.query.area;
let mobile = req.query.mobile;
PhoneService.sendSMS(mobile, area, 1).then(result => {
if (result.code === 200) {
... ... @@ -415,7 +376,6 @@ exports.password = (req, res, next) => {
/**
* 生成 校验码
*/
/*
exports.genCaptcha = (req, res) => {
let captcha = captchaService.generateCaptcha(90, 52, 4);
... ... @@ -426,4 +386,3 @@ exports.genCaptcha = (req, res) => {
.status(200)
.send(captcha.image);
};
*/
... ...
'use strict';
const _ = require('lodash');
const aes = require('./aes-pwd');
const sign = global.yoho.sign;
const api = global.yoho.API;
... ... @@ -88,17 +87,10 @@ class Auth {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 2592000000) // 有效期一年
});
req.session.AVATAR = data.head_ico;
_.set(req.session, 'USER.AVATAR', data.head_ico);
_.set(req.session, 'USER.NAME', data.profile_name);
}
req.session.TOKEN = publicToken;
req.session.LOGIN_UID = uid;
_.set(req.session, 'USER.ENCRYPTION_UID', encryptionUid);
res.cookie('_TOKEN', publicToken, {
httpOnly: true,
domain: 'yohobuy.com',
... ...
... ... @@ -96,16 +96,13 @@ const RegService = {
return api.post('', params);
},
regMobileAes(area, mobile, password, shoppingKey, smsCode, isFromMy) {
isFromMy = isFromMy || '0';
regMobileAes(area, mobile, password, shoppingKey, smsCode) {
let params = {
method: 'app.passport.registerAES',
area: area,
profile: mobile,
password: aes.aesPwd(password),
verifyCode: smsCode,
isFromMy
verifyCode: smsCode
};
if (shoppingKey) {
... ...
... ... @@ -41,7 +41,6 @@ router.post('/passport/login/auth', login.local.login);
// SMS 短信
router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn);
router.get('/passport/sms_login', smsLogin.loginPage);
router.post('/passport/sms_login/step1_check', smsLogin.indexCheck);
router.get('/passport/sms_login/token.json',
smsLogin.tokenBefore,
smsLogin.token); // only ajax;
... ... @@ -49,6 +48,7 @@ router.get('/passport/sms_login/check.json',
smsLogin.checkBefore,
smsLogin.check); // only ajax
router.post('/passport/sms_login/password.json', smsLogin.password);
router.get('/passport/sms_login/captcha.png', smsLogin.genCaptcha);
// 微信登录
router.get('/passport/login/wechat', login.common.beforeLogin, login.wechat.login);
... ... @@ -126,9 +126,4 @@ router.get('/passport/newpower', agreement.newpower);// 新力传媒
router.get('/passport/yohobuy', agreement.aboutYoho);// 关于有货
router.get('/passport/agreement', agreement.agreement);// 服务条款
// 验证码
let captcha = require(`${cRoot}/captcha`);
router.get('/passport/captcha/get', captcha.get);
module.exports = router;
... ...
... ... @@ -6,11 +6,12 @@
<span id="area-code" class="area-code">{{areaCode}}</span>
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
</div>
{{!--图片验证 start--}}
<div id="js-img-check">
<input type="hidden" name="captsrc" value="{{captsrc}}">
<div class="passport-captcha row">
<div class="passport-captcha-img"><img id="verify-code-img" src="{{verifySrc}}" alt="verify code"></div>
<div class="passport-captcha-input">
<input id="verify-code" type="text" placeholder="验证码">
</div>
</div>
{{!--图片验证 end--}}
<span id="btn-next" class="btn btn-next disable row">下一步</span>
</div>
</div>
... ...
... ... @@ -9,8 +9,6 @@
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<div id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<span id="btn-login" class="btn btn-login disble row">登录</span>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -8,10 +8,9 @@
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<div id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<span id="btn-login" class="btn btn-login disable">登录</span>
<p class="op-container">
<a class="sms-login" href={{smsLoginUrl}}>手机号码快捷登录</a>
{{!--<a class="sms-login" href={{smsLoginUrl}}>手机号码快捷登录</a>--}}
<span id="forget-pwd" class="forget-pwd">忘记密码</span>
</p>
<div class="third-party-login">
... ... @@ -44,4 +43,4 @@
</li>
</ul>
</div>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -6,13 +6,16 @@
<span id="area-code" class="area-code">{{areaCode}}</span>
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
</div>
{{!--图片验证 start--}}
<div id="js-img-check">
<input type="hidden" name="captsrc" value="{{captsrc}}">
<!-- 验证码: start-->
<div class="passport-captcha row">
<div class="passport-captcha-img">
<img class="passport-captcha-png" src="{{captchaUrl}}">
</div>
<div class="passport-captcha-input">
<input id="js-captcha" type="text" placeholder="验证码">
</div>
</div>
{{!--图片验证 end--}}
<!-- 验证码: end-->
<span id="btn-next" class="btn btn-next disable row">下一步</span>
<p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p>
</div>
... ...
... ... @@ -7,11 +7,12 @@
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
<button class="clear-input" type="button"></button>
</div>
{{!--图片验证 start--}}
<div id="js-img-check">
<input type="hidden" name="captsrc" value="{{captsrc}}">
<div class="passport-captcha row">
<div class="passport-captcha-img"><img src="{{captchaUrl}}" alt=""></div>
<div class="passport-captcha-input">
<input id="js-captcha" type="text" placeholder="验证码">
</div>
</div>
{{!--图片验证 end--}}
<button id="btn-next" class="btn btn-next disable row" disabled>获取短信验证码</button>
</div>
</div>
\ No newline at end of file
... ...
{
"name": "m-yohobuy-node",
"version": "5.3.0",
"version": "5.3.1",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -19,18 +19,6 @@ var tip = require('../../plugin/tip');
var trim = $.trim;
var showErrTip = tip.show;
// 图片验证码
let ImgCheck = require('plugin/img-check');
let imgCheck = new ImgCheck('#js-img-check', {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
imgCheck.init();
api.selectCssHack($('#country-select'));
api.bindClearEvt();
... ... @@ -57,13 +45,12 @@ $verifyCodeImg.on('touchstart', function() {
$btnNext.on('touchstart', function() {
var pn = trim($phoneNum.val()),
area = trim($countrySelect.val()),
verify = trim(imgCheck.getResults());
verify = trim($verifyCode.val());
if ($btnNext.hasClass('disable')) {
return;
}
if (verify && area && pn && api.phoneRegx[area].test(pn)) {
$.ajax({
url: '/passport/back/sendcode',
... ... @@ -76,21 +63,18 @@ $btnNext.on('touchstart', function() {
success: function(data) {
if (data.code === 200) {
location.href = data.data;
return;
} else if (data.code === 409) {
showErrTip(data.message);
location.href = data.refer;
} else {
showErrTip(data.message);
}
imgCheck.refresh();
}
});
} else if (!area) {
showErrTip('出错了,请重新刷新页面');
} else if (verify === '0000') {
showErrTip('请将图片旋转到正确位置');
} else if (!verify) {
showErrTip('请输入验证码');
} else {
showErrTip('手机号格式不正确,请重新输入');
}
... ...
... ... @@ -4,7 +4,6 @@
* @date: 2015/10/8
*/
var $ = require('yoho-jquery');
var ImgCheck = require('plugin/img-check');
var $phoneNum = $('#phone-num'),
$countrySelect = $('#country-select'),
... ... @@ -12,8 +11,6 @@ var $phoneNum = $('#phone-num'),
$pwd = $('#pwd'),
$loginBtn = $('#btn-login'),
$captcha = $('#js-img-check'),
pnPass = false,
pwdPass = false;
... ... @@ -23,28 +20,13 @@ var tip = require('../../plugin/tip');
var trim = $.trim;
var showErrTip = tip.show;
var imgCheck = new ImgCheck($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
if ($captcha.data('init') != null) { //eslint-disable-line
imgCheck.init();
}
// 登录按钮状态切换
function switchLoginBtnStatus() {
var bool = !(pnPass && pwdPass);
$loginBtn.toggleClass('disable', bool);
}
function resetForm() {
$pwd.val('').focus();
$loginBtn.text('登录').addClass('disable');
if (pnPass && pwdPass) {
$loginBtn.removeClass('disable');
} else {
$loginBtn.addClass('disable');
}
}
// Android-UC下显示select的direction:rtl无效的临时解决办法
... ... @@ -85,39 +67,23 @@ $countrySelect.change(function() {
$loginBtn.on('touchstart', function() {
var pn = trim($phoneNum.val()),
areaCode = $countrySelect.val(),
pwd = trim($pwd.val()),
captcha = null;
pwd = trim($pwd.val());
if ($loginBtn.hasClass('disable')) {
return;
}
if (imgCheck.atWorking) {
captcha = imgCheck.getResults();
if (captcha === '0000') {
return tip.show(' 请将图片旋转到正确方向');
}
}
$loginBtn.text('正在登录...').addClass('disable');
if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) {
let data = {
areaCode: areaCode.replace('+', ''),
account: pn,
password: pwd
};
if (imgCheck.atWorking) {
$.extend(data, {captcha});
}
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data,
data: {
areaCode: areaCode.replace('+', ''),
account: pn,
password: pwd
},
success: function(data) {
var res,
time;
... ... @@ -144,27 +110,21 @@ $loginBtn.on('touchstart', function() {
location.href = res.href;
}, 3000);
$loginBtn.text('登录成功').off();
showErrTip('登录成功');
} else {
if (data.captchaShow) {
imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init();
}
showErrTip(data.message);
resetForm();
}
},
error: function() {
showErrTip('网络断开连接啦~');
$loginBtn.text('登录');
imgCheck.atWorking && imgCheck.refresh();
},
complete: function() {
$loginBtn.text('登录').removeClass('disable');
}
});
} else {
showErrTip('账号或密码有错误,请重新输入');
$loginBtn.text('登录').addClass('disable');
$loginBtn.text('登录').removeClass('disable');
}
});
... ...
... ... @@ -4,7 +4,6 @@
* @date: 2015/9/30
*/
var $ = require('yoho-jquery');
var ImgCheck = require('plugin/img-check');
var $account = $('#account'),
$pwd = $('#pwd'),
... ... @@ -13,8 +12,6 @@ var $account = $('#account'),
$mask = $('#retrive-pwd-mask'),
$ways = $('#retrive-pwd-ways'),
$captcha = $('#js-img-check'),
accPass = false,
pwdPass = false;
... ... @@ -24,30 +21,13 @@ var tip = require('../../plugin/tip');
var trim = $.trim;
var showErrTip = tip.show;
var imgCheck = new ImgCheck($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
if ($captcha.data('init') != null) { //eslint-disable-line
imgCheck.init();
}
// 登录按钮状态切换
function switchLoginBtnStatus() {
var bool = true;
bool = !(accPass && pwdPass);
$loginBtn.toggleClass('disable', bool);
}
function resetForm() {
$pwd.val('').focus();
$loginBtn.text('登录').addClass('disable');
if (accPass && pwdPass) {
$loginBtn.removeClass('disable');
} else {
$loginBtn.addClass('disable');
}
}
// 显示找回密码面板
... ... @@ -90,38 +70,23 @@ $pwd.bind('input', function() {
// Login
$loginBtn.on('touchstart', function() {
var acc = trim($account.val()),
pwd = trim($pwd.val()),
captcha = null;
pwd = trim($pwd.val());
if ($loginBtn.hasClass('disable')) {
return;
}
if (imgCheck.atWorking) {
captcha = imgCheck.getResults();
if (captcha === '0000') {
return tip.show(' 请将图片旋转到正确方向');
}
}
$loginBtn.text('正在登录...').addClass('disable');
// 验证账号(数字或者邮箱)和密码合理性
if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) {
let data = {
account: acc,
password: pwd
};
if (imgCheck.atWorking) {
$.extend(data, {captcha});
}
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data,
data: {
account: acc,
password: pwd
},
success: function(data) {
var res;
... ... @@ -130,22 +95,12 @@ $loginBtn.on('touchstart', function() {
showErrTip('登录成功');
location.href = res.href;
$loginBtn.text('登录成功').off();
} else {
if (data.captchaShow) {
imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init();
}
showErrTip(data.message);
resetForm();
}
return data;
},
error: function() {
showErrTip('网络断开连接啦~');
imgCheck.atWorking && imgCheck.refresh();
},
complete: function() {
$loginBtn.text('登录').removeClass('disable');
... ...
... ... @@ -35,7 +35,7 @@ $pwd.bind('input', function() {
});
$btnSure.toggleClass('disable', !bool);
});
})
qs = window.queryString;
... ... @@ -137,4 +137,4 @@ $('.agreement-detail').on('click', function() {
// 如果有值, 立刻校验
if ($pwd.val()) {
$pwd.triggerHandler('input');
}
}
\ No newline at end of file
... ...
... ... @@ -24,29 +24,17 @@ api.selectCssHack($('#country-select'));
api.bindClearEvt();
// 图片验证码
let ImgCheck = require('plugin/img-check');
let imgCheck = new ImgCheck('#js-img-check', {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
imgCheck.init();
/**
* 必填校验
*/
function checkEnableNext() {
var phone = trim($phoneNum.val());
var area = trim($countrySelect.val());
var captcha = trim($captcha.val());
var ret = true;
$.each([phone, area], function(i, val) {
$.each([phone, area, captcha], function(i, val) {
if (!val) {
ret = false;
return ret;
... ... @@ -56,13 +44,24 @@ function checkEnableNext() {
return ret;
}
/**
* 刷新 校验码
*/
function refreshCaptcha() {
$captcha.val('').focus();
$captchaPNG.attr('src', ['//m.yohobuy.com/passport/reg/captcha.png', '?t=', Date.now()].join(''));
}
/*
Event bind
*/
$('.reg-page')
.on('input', '.phone-num', function() {
.on('input', '.phone-num, #js-captcha', function() {
$btnNext.toggleClass('disable', !checkEnableNext());
});
})
.on('click', '.passport-captcha-png', refreshCaptcha);
$countrySelect.change(function() {
$areaCode.text($countrySelect.val());
... ... @@ -71,10 +70,10 @@ $countrySelect.change(function() {
$btnNext.on('touchstart', function() {
var pn = trim($phoneNum.val()),
areaCode = $countrySelect.val(),
captcha = imgCheck.getResults();
captcha = $captcha.val().trim();
if (captcha === '0000') {
tip.show('请将图片旋转到正确位置');
if (!captcha) {
tip.show('请输入验证码');
return false;
}
... ... @@ -103,7 +102,7 @@ $btnNext.on('touchstart', function() {
if (data.code === 200) {
location.href = data.data;
} else {
imgCheck.refresh();
refreshCaptcha();
showErrTip(data.message);
requested = false;
... ... @@ -111,7 +110,7 @@ $btnNext.on('touchstart', function() {
},
error: function() {
showErrTip('出错了,请重试');
imgCheck.refresh();
refreshCaptcha();
requested = false;
}
});
... ...
... ... @@ -17,26 +17,10 @@ tip = require('plugin/tip');
api = require('./api');
checkPoint = require('./smslogin/check-point');
// 图片验证码
let ImgCheck = require('plugin/img-check');
let imgCheck = new ImgCheck('#js-img-check', {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
imgCheck.init();
page = {
init: function() {
this.domInit();
this.bindEvent();
this.toggleNextBtn();
},
domInit: function() {
$countrySelect = $('#country-select');
... ... @@ -44,6 +28,8 @@ page = {
$nextBtn = $('#btn-next');
$phoneNum = $('#phone-num');
$resetBtn = $('.clear-input');
$captcha = $('.passport-captcha input');
$captchaPNG = $('.passport-captcha-img img');
},
bindEvent: function() {
var self = this;
... ... @@ -55,6 +41,12 @@ page = {
self.toggleNextBtn();
});
$captcha.on('input', function() {
self.toggleNextBtn();
});
$captchaPNG.on('click', $.proxy(this.refreshCapatch, this));
$nextBtn.on('click', function() {
self.goNext();
});
... ... @@ -70,7 +62,7 @@ page = {
// 切换$nextBtn disable状态
toggleNextBtn: function() {
var bool = Boolean($.trim($phoneNum.val()));
var bool = Boolean($.trim($phoneNum.val())) && Boolean($.trim($captcha.val()));
$nextBtn
.toggleClass('disable', !bool)
... ... @@ -79,11 +71,17 @@ page = {
$resetBtn.toggle(bool);
},
refreshCapatch: function() {
$captchaPNG.attr('src', '/passport/sms_login/captcha.png?t=' + Date.now());
$captcha.val('');
},
// 提交按钮
goNext: function() {
var self = this;
var areaCode = $countrySelect.val();
var phone = $.trim($phoneNum.val());
var captcha = $.trim(imgCheck.getResults());
var captcha = $.trim($captcha.val());
if ($nextBtn.prop('disabled')) {
return;
... ... @@ -94,16 +92,11 @@ page = {
return;
}
if (captcha === '0000') {
tip.show('请将图片旋转到正确位置');
return;
}
$nextBtn.prop('disabled', true);
$.post('/passport/sms_login/step1_check', {
$.get('/passport/sms_login/token.json', {
area: areaCode.replace('+', ''),
mobile: phone,
captcode: captcha
captcha: captcha
})
.done(function(data) {
if (data.code === 200) {
... ... @@ -111,12 +104,11 @@ page = {
$nextBtn.off();
location.href = data.redirect;
} else {
imgCheck.refresh();
self.refreshCapatch();
tip.show(data.message);
}
})
.fail(function() {
imgCheck.refresh();
tip.show('出错了, 请重试');
})
.always(function() {
... ...
... ... @@ -12,12 +12,10 @@ var sendInfo = function(eventName) {
channel = channelMap[channel] || 1;
param = JSON.stringify({C_ID: channel});
if (yas && yas.sendCustomInfo) {
yas.sendCustomInfo({
op: eventName,
param: param
}, true);
}
yas && yas.sendCustomInfo({
op: eventName,
param: param
}, true);
};
module.exports = sendInfo;
... ...