Authored by 陈轩

push

... ... @@ -45,6 +45,16 @@ let verifyMobile = (req, res, next) => {
let mobile = +req.body.phoneNum;
let area = +(req.body.areaCode || 86);
let captcha = +(req.body.captcha);
if (captcha !== req.session.regCaptch) {
return res.json({
code: 111,
message: '校验码不正确'
});
}
// 判断参数是否合法
if (!_.isNumber(mobile) || !_.isNumber(area)) {
... ... @@ -282,7 +292,7 @@ const genCaptcha = (req, res) => {
res.type('png')
.set('Cache-Control', 'no-cache')
.status(200)
.end(captcha.image);
.send(captcha.image);
};
module.exports = {
... ...
... ... @@ -8,10 +8,9 @@
</div>
<!-- 验证码: start-->
<div class="passport-captcha row">
<input type="text" placeholder="验证码">
<input id="js-captcha" type="text" placeholder="验证码">
<div class="passport-captcha-img">
<img class="passport-captcha-png" src="{{captchaUrl}}">
<button class="passport-captcha-refresh" type="button">换一张</button>
</div>
</div>
<!-- 验证码: end-->
... ...
... ... @@ -8,6 +8,8 @@ var $ = require('yoho-jquery');
var $phoneNum = $('#phone-num'),
$countrySelect = $('#country-select'),
$areaCode = $('#area-code'),
$captcha = $('#js-captcha'),
$captchaPNG = $('.passport-captcha-png'),
$btnNext = $('#btn-next');
var api = require('../api');
... ... @@ -22,13 +24,43 @@ api.selectCssHack($('#country-select'));
api.bindClearEvt();
$phoneNum.bind('input', function() {
if (trim($phoneNum.val()) === '') {
$btnNext.addClass('disable');
} else {
$btnNext.removeClass('disable');
}
});
/**
* 必填校验
*/
function checkEnableNext() {
var phone = trim($phoneNum.val());
var area = trim($countrySelect.val());
var captcha = trim($captcha.val());
var ret = true;
$.each([phone, area, captcha], function(i, val) {
if (!val) {
ret = false;
return ret;
}
});
return ret;
}
/**
* 刷新 校验码
*/
function refreshCaptcha() {
$captchaPNG.attr('src', ['//m.yohobuy.com/passport/reg/captcha.png', '?t=', Date.now()].join(''));
}
/*
Event bind
*/
$('.reg-page')
.on('input', '.phone-num, #js-captcha', function() {
$btnNext.toggleClass('disable', !checkEnableNext());
})
.on('click', '.passport-captcha-png', refreshCaptcha);
$countrySelect.change(function() {
$areaCode.text($countrySelect.val());
... ... @@ -36,7 +68,13 @@ $countrySelect.change(function() {
$btnNext.on('touchstart', function() {
var pn = trim($phoneNum.val()),
areaCode = $countrySelect.val();
areaCode = $countrySelect.val(),
captcha = $captcha.val().trim();
if (!captcha) {
tip.show('请输入验证码');
return false;
}
if ($btnNext.hasClass('disable')) {
return;
... ... @@ -56,7 +94,8 @@ $btnNext.on('touchstart', function() {
type: 'POST',
data: {
areaCode: areaCode.replace('+', ''),
phoneNum: pn
phoneNum: pn,
captcha: captcha
},
success: function(data) {
if (data.code === 200) {
... ...
... ... @@ -16,8 +16,6 @@ div.passport-captch>input+div>img+button
text-align: left;
input {
display: inline-block;
width: 50%;
position: relative;
padding-left: 15px;
height: 52PX;
... ... @@ -30,28 +28,14 @@ div.passport-captch>input+div>img+button
}
.passport-captcha-img {
width: 50%;
float: right;
text-align: right;
img {
display: inline-block;
margin-right: 30px;
background-color: #fff;
height: 52PX;
width: 90PX;
vertical-align: bottom;
}
}
.passport-captcha-refresh {
display: inline-block;
text-decoration: underline;
font-size: 18px;
color: #ff1901;
background-color: transparent;
padding: 0;
margin: 0;
border: 0;
outline: 0;
}
\ No newline at end of file
}
\ No newline at end of file
... ...