One hundred seventeen: the registration page CMS systems docking SMS verification code

 

Import the Blueprint Flask from, Request 
from EXTS Import alidayu
from utils Import RESTful
from utils.captcha Import Captcha

BP = the Blueprint ( "Common", the __name__, url_prefix = '/ Common')


@ bp.route ( '/ sms_captcha /')
DEF sms_captcha ():
Telephone request.args.get = ( 'Telephone')
IF Not Telephone:
( 'enter phone number') return restful.params_error

# acquired random codes
captcha = Captcha.gene_text (number = 4) # 4 bit

# alidayu.send_sms (telephone, code = captcha ) # send message codes
# return restful.success () if alidayu.send_sms ( telephone, code = captcha) else restful.params_error ( ' failed verification code')
return restful.success (captcha) # Since there is no trigger to send a verification code, phone number here as long as verified by a unified code return

js

// 短信验证码
$(function () {
$('#sms-captcha-btn').click(function (event) {
event.preventDefault();
var self = $(this);
var telephone = $("input[name=telephone]").val();
console.log(telephone);
if(!(/^1[345789]\d{9}$/.test(telephone))){
xtalert.alertInfoToast('请输入正确的手机号');
return;
}
ajax.get({
'url': '/common/sms_captcha/?telephone=' + telephone,
'success': function (data) {
if(data['code'] == 200){
xtalert.alertSuccessToast('验证码发送成功');
alert('验证码为:' + data['message']); // 由于没有真实的发送验证码,这里弹窗提示验证码
self.attr('disabled', 'disabled'); // 给按钮设置属性,不允许点击
// 倒计时60秒
var timeCount = 60;
var timer = setInterval(function () {
timeCount --;
self.text(timeCount);
if(timeCount <= 0){
self.removeAttr('disabled'); // 移除不能点击属性
clearInterval(timer);
self.text('发送验证码')
}
},1000)
}else{
xtalert.alertInfoToast(data['message'])
}
}
});
});
});
 

 

 

Guess you like

Origin www.cnblogs.com/zhongyehai/p/11953779.html