• 一百一十七:CMS系统之注册页面对接短信验证码


    from flask import Blueprint, request
    from exts import alidayu
    from utils import restful
    from utils.captcha import Captcha

    bp = Blueprint("common", __name__, url_prefix='/common')


    @bp.route('/sms_captcha/')
    def sms_captcha():
    telephone = request.args.get('telephone')
    if not telephone:
    return restful.params_error('请输入手机号')

    # 获取随机的验证码
    captcha = Captcha.gene_text(number=4) # 4位

    # alidayu.send_sms(telephone, code=captcha) # 发送短信验证码
    # return restful.success() if alidayu.send_sms(telephone, code=captcha) else restful.params_error('验证码发送失败')
    return restful.success(captcha) # 由于没有触发发送验证码,这里只要手机号验证通过统一返回验证码

    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'])
    }
    }
    });
    });
    });
    
    

     

  • 相关阅读:
    protobuf简单测试应用
    golang代码片段(摘抄)
    ibatis中 $ 于 # 的 区别?
    eclipse debug 执行到断点处并没有停下,断点无效问题
    使用selenium遇到java.lang.NoSuchMethodError: org.apache.xpath.XPathContext,排查
    设置MAVEN_OPTS的推荐方法
    UI型Bug定义的处理方法
    select count(*)和select count(1)的区别
    mac下搭建java开发环境:eclipse+tomcat+maven
    eclipse中svn提交报错的解决
  • 原文地址:https://www.cnblogs.com/zhongyehai/p/11953779.html
Copyright © 2020-2023  润新知