Beispiel #1
0
def send_message():
    phone = request.args.get('phone')
    if not phone:
        return xtjson.json_params_error(message=u'必须指定一个手机号码')
    if xtcache.get(phone):
        return xtjson.json_params_error(message=u'验证码已发送,60秒内有效')

    app_key = contants.APP_KEY
    app_secret = contants.APP_SECRET
    req = top.setDefaultAppInfo(app_key,app_secret)
    req = top.api.AlibabaAliqinFcSmsNumSendRequest()
    req.extend=""
    req.sms_type='normal'
    req.sms_free_sign_name = contants.ALIDAYU_SIGN_NAME
    graph_captcha = captcha.gene_text()
    req.sms_param = "{code:%s}"% graph_captcha
    req.rec_num = phone.decode('utf-8').encode('ascii')
    req.sms_template_code = contants.ALIDAYU_TEMPLATE_CODE
    try:
        resp = req.getResponse()
        xtcache.set(phone,graph_captcha)
        print xtcache.get(graph_captcha)
        return xtjson.json_result()
    except Exception,e:
        print e
        return xtjson.json_server_error()
Beispiel #2
0
 def validate_phone_captcha(self, field):
     phone_captcha = field.data
     phone = self.phone.data
     message = xtcache.get(phone)
     if not message or message.lower() != phone_captcha.lower():
         raise ValidationError(message=u'手机短信验证码错误')
     return True
Beispiel #3
0
 def check_captcha(cls, captcha):
     captcha_lower = captcha.lower()
     if xtcache.get(captcha_lower):
         xtcache.delete(captcha_lower)
         return True
     else:
         return False
Beispiel #4
0
def sms_captcha():
    telephone = flask.request.args.get('telephone')
    if not telephone:
        return xtjson.json_params_error(message=u'手机号不能为空!')
    p2 = re.compile('^0\d{2,3}\d{7,8}$|^1[3587]\d{9}$|^147\d{8}')
    phonematch = p2.match(telephone)
    if not phonematch:
        return xtjson.json_params_error(message=u'手机号格式错误')
    tel = FrontUser.query.filter_by(telephone=telephone).first()
    if tel:
        return xtjson.json_params_error(message=u'该手机号已被注册,请勿重复注册')
    if xtcache.get(telephone):
        return xtjson.json_params_error(message=u'验证码已发送,请于1分钟后重新发送')
    app_key = constants.ALIDAYU_APP_KEY
    app_secret = constants.ALIDAYU_APP_SECRET
    req = top.setDefaultAppInfo(app_key, app_secret)
    req = top.api.AlibabaAliqinFcSmsNumSendRequest()
    req.extend = ""
    req.sms_type = 'normal'
    req.sms_free_sign_name = constants.ALIDAYU_SIGN_NAME
    # 给模版的参数
    captcha = Captcha.gene_text()
    req.sms_param = "{code:'%s'}" % captcha
    req.rec_num = telephone.decode('utf-8').encode('ascii')
    req.sms_template_code = constants.ALIDAYU_TEMPLATE_CODE
    try:
        resp = req.getResponse()
        xtcache.set(telephone, captcha)
        return xtjson.json_result()
    except Exception, e:
        print e
        return xtjson.json_server_error()
Beispiel #5
0
 def validate_sms_captcha(self, field):
     sms_captcha = field.data
     telephone = self.telephone.data
     cache_captcha = xtcache.get(telephone)
     if not cache_captcha or cache_captcha.lower() != sms_captcha.lower():
         raise ValidationError(message='短信验证码错误!')
     return True
Beispiel #6
0
def sms_captcha():
    telephone = flask.request.args.get('telephone')
    # 获取用户名,用于发送短信验证码显示用户名
    # username = flask.request.args.get('username')
    if not telephone:
        return xtjson.json_params_error(message=u'必须指定手机号码!')
    if xtcache.get(telephone):
        return xtjson.json_params_error(message=u'验证码已发送,请1分钟后重复发送!')
    # if not username:
    #     return xtjson.json_params_error(message=u'必须输入用户名!')
    # 阿里大于APP_KEY及APP_SECRET
    app_key = constants.APP_KEY
    app_secret = constants.APP_SECRET
    req = top.setDefaultAppInfo(app_key, app_secret)
    req = top.api.AlibabaAliqinFcSmsNumSendRequest()
    req.extend = ""
    req.sms_type = 'normal'
    # 签名名称
    req.sms_free_sign_name = constants.SIGN_NAME
    # 随即生成字符串
    captcha = Captcha.gene_text()
    # 设置短信的模板
    req.sms_param = "{code:%s}" % captcha
    # req.sms_param = "{username:%s,code:%s}" % (username, captcha)
    req.rec_num = telephone.decode('utf-8').encode('ascii')
    req.sms_template_code = constants.TEMPLATE_CODE
    try:
        resp = req.getResponse()
        xtcache.set(telephone, captcha)
        return xtjson.json_result()
    except Exception, e:
        print e
        return xtjson.json_server_error()
Beispiel #7
0
def telphone_captcha():
    telphone = flask.request.args.get('telphone')

    if not telphone:
        return xtjson.json_params_error(message=u'请输入手机号码!')

    if xtcache.get(telphone):
        return xtjson.json_params_error(message=u'该手机号码已经申请过验证码,请在10分钟后再试!')

    telphone_captcha = xtcaptcha.Captcha.gene_text()
    xtcache.set(telphone,telphone_captcha,timeout=600) # 10分钟过期

    app_key = ''
    app_secret = ''
    req = top.setDefaultAppInfo(app_key,app_secret)
    req = top.api.AlibabaAliqinFcSmsNumSendRequest()
    req.extend = ""
    req.sms_type = 'normal'
    req.sms_free_sign_name = 'python论坛'
    req.sms_param = "{code:'%s'}" % telphone_captcha
    req.rec_num = telphone.decode('utf-8').encode('ascii')
    req.sms_template_code = 'SMS_37105066'
    try:
        resp = req.getResponse()
        return xtjson.json_result()
    except Exception,e:
        return xtjson.json_params_error(message=u'短信发送太频繁')
Beispiel #8
0
def mail_captcha():

    # 生成验证码

    email = flask.request.args.get('email')

    if xtcache.get(email):
        return xtjson.json_params_error('该邮箱已经发送验证码了!')

    captcha = Captcha.gene_text()

    # 给请求修改邮箱的用户发送邮箱验证码

    # if xtmail.send_mail(subject='DUDU论坛邮箱验证码', receivers=email, body='邮箱验证码:'+captcha):
    #     # 1.为了下次可以验证邮箱和验证码
    #     # 2.为了防止用户不断的刷这个接口
    #     xtcache.set(email,captcha)
    #     return xtjson.json_result()
    # else:
    #     return xtjson.json_server_error()

    celery_send_mail.delay(subject='DUDU论坛邮箱验证码',
                           receivers=email,
                           body='邮箱验证码:' + captcha)
    return xtjson.json_result()
Beispiel #9
0
 def validate_graph_captcha(self, field):
     graph_captcha = field.data
     che_graph_captcha = xtcache.get(graph_captcha)
     if not che_graph_captcha or graph_captcha.lower(
     ) != che_graph_captcha.lower():
         raise ValidationError(message=u'图片验证码错误')
     return True
Beispiel #10
0
 def validate_captcha(self,field):
     email = self.email.data
     captcha = field.data
     captcha_cache = xtcache.get(email)
     if not captcha_cache or captcha_cache.lower() != captcha.lower():
         raise ValidationError(message=u'验证码输入有误,请重新输入')
     return True
Beispiel #11
0
def mail_captcha():
    email = flask.request.args.get('email')
    if xtcache.get(email):
        return xtjson.json_params_error(u'已经给该邮箱发送验证码,请勿重复发送!')
    captcha = Captcha.gene_text()
    if xqmail.send_mail(subject=u'论坛验证码',receivers=email,body=u'您的验证码为:'+captcha+u',请您注意保密'):
        xtcache.set(email,captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Beispiel #12
0
def get_captcha():
    email = request.args.get('email')
    if xtcache.get(email):
        return xtjson.json_params_error(u'该邮箱已经发过验证码了')
    sorce = list(string.letters)
    for x in xrange(0, 10):
        sorce.append(str(x))
    captcha_list = random.sample(sorce, 6)
    captcha = ''.join(captcha_list)
    celery_send_mail.delay(subject=u'大熊论坛验证码',
                           receviers=email,
                           body=u'您本次的验证码是:' + captcha)
    return xtjson.json_result()
Beispiel #13
0
def sms_captcha():
    telephone = flask.request.args.get('telephone')
    if not telephone:
        return xtjson.json_params_error(message=u'必须指定手机号码!')

    if xtcache.get(telephone):
        return xtjson.json_params_error(message=u'验证码已经发送,请等待1分钟后再次发送!')

    if len(telephone) != 11:
        return xtjson.json_params_error(message=u'手机号码格式不正确,请重新填写!')

    try:
        int(telephone)
    except Exception, e:
        # print e
        return xtjson.json_params_error(message=u'手机号码格式不正确,请重新填写!')
Beispiel #14
0
def settings():
    if flask.request.method == 'GET':
        return flask.render_template('front/front_settings.html')
    else:
        form = FrontSettingsForm(flask.request.form)
        if form.validate():
            username = form.username.data
            realname = form.realname.data
            qq = form.qq.data
            avatar = form.avatar.data
            signature = form.signature.data
            gender = form.gender.data
            email = form.email.data
            captcha = form.captcha.data

            user_model = flask.g.front_user
            user_model.username = username
            if realname:
                user_model.realname = realname
            else:
                user_model.realname = ''
            if qq:
                user_model.qq = qq
            else:
                user_model.qq = ''
            if avatar:
                user_model.avatar = avatar
            if signature:
                user_model.signature = signature
            else:
                user_model.signature = ''
                # return  xtjson.json_params_error(message=u'个性签名不能为空')
            if gender:
                user_model.gender = gender
            if email:
                user_model.email = email
                captcha_cache = xtcache.get(email)
                if not captcha_cache or captcha_cache.lower() != captcha.lower(
                ):
                    return xtjson.json_params_error(message=u'验证码输入有误,请重新输入')
            else:
                user_model.email = ''
            db.session.commit()
            return xtjson.json_result()
        else:
            return xtjson.json_params_error(message=form.get_error())
Beispiel #15
0
def mail_captcha():
    email = flask.request.args.get('email')
    if xtcache.get(email):
        return xtjson.json_params_error(u'该邮箱已经发送验证码了!')

    source = list(string.letters)
    for x in xrange(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)
    if xtmail.send_mail(subject=u'潭州Python学院邮件验证码',
                        receivers=email,
                        body=u'邮箱验证码是:' + captcha):
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Beispiel #16
0
def sms_captcha():
    telephone = flask.request.args.get('telephone')
    if not telephone:
        return xtjson.json_params_error(message='必须指定手机号码!')

    if xtcache.get(telephone):
        return xtjson.json_params_error(message='1分钟内请勿重复发送!')

    code = Captcha.gene_text_num()
    # /accoutn/sms_captcha/?telephone=12345678900
    # telephone = flask.request.form.get('telephone')
    result = aliyun.send_sms(telephone, code=code)
    print(result)
    if result:
        xtcache.set(telephone, code)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Beispiel #17
0
def email_captcha():
    email = flask.request.args.get('email')

    if not email:
        return xtjson.json_params_error(message=u'请输入邮箱!')

    if xtcache.get(email):
        return xtjson.json_params_error(message=u'该邮箱已经申请验证码!')

    email_captcha = xtcaptcha.Captcha.gene_text()
    xtcache.set(email,email_captcha,timeout=60)

    # 发送邮件
    xtmail = XTMail(mail_type=XTMailType.MAIL_CAPTCHA)
    xtmail.send_mail(email)


    return xtjson.json_result()
Beispiel #18
0
def mail_captcha():
    # mail_captcha/[email protected]/
    # 查询字符串 /mail_captcha/[email protected]
    email = flask.request.args.get('email')

    if xtcache.get(email):
        return xtjson.json_params_error(message=u'该邮箱已经发送验证码了!')

    source = list(string.letters)
    for x in xrange(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)

    if xtmail.send_mail(subject=u'周杰伦发来的邮箱验证码', receivers=email, body=u'邮箱验证码是:'+captcha):
        # 为了下次可以验证邮箱和验证码
        # 为了防止用户不断的刷新这个接口
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_params_error(message=u'服务器错误')
Beispiel #19
0
def mail_captcha():
    # /mail_captcha/[email protected]/
    # /mail_captcha/[email protected]
    email = flask.request.args.get('email')

    if xtcache.get(email):
        return xtjson.json_params_error(u'该邮箱已经发送验证码了!')

    source = list(string.ascii_letters)
    for x in range(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)

    if xtmail.send_mail(subject=u'知了课堂Python学院邮件验证码',
                        receivers=email,
                        body=u'邮箱验证码是:' + captcha):
        # 1. 为了下次可以验证邮箱和验证码
        # 2. 为了防止用户不断的刷这个接口
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Beispiel #20
0
def sms_captcha():
    telephone = flask.request.args.get('telephone')
    if not telephone:
        return xtjson.json_params_error(message=u'必须指定手机号码!')

    if xtcache.get(telephone):
        return xtjson.json_params_error(message=u'验证码已发送,请1分钟后重复发送!')

    app_key = constants.ALIDAYU_APP_KEY
    app_secret = constants.ALIDAYU_APP_SECRET
    req = AlibabaAliqinFcSmsNumSendRequest(app_key, app_secret)
    req.extend = ""
    req.sms_type = 'normal'
    req.sms_free_sign_name = constants.ALIDAYU_SIGN_NAME
    captcha = Captcha.gene_text()
    req.sms_param = "{code:%s}" % captcha
    req.rec_num = telephone
    req.sms_template_code = constants.ALIDAYU_TEMPLATE_CODE
    try:
        resp = req.getResponse()
        xtcache.set(telephone, captcha)
        return xtjson.json_result()
    except Exception as e:
        return xtjson.json_server_error()
Beispiel #21
0
 def validate_telphone_captcha(self,field):
     telphone_captcha = field.data
     telphone = self.telphone.data
     captcha = xtcache.get(telphone)
     if not captcha or captcha.lower() != telphone_captcha.lower():
         raise wtforms.ValidationError(u'短信验证码错误')
Beispiel #22
0
 def validate_graph_captcha(self, field):
     graph_captcha = field.data
     cache_captcha = xtcache.get(graph_captcha.lower())
     if not cache_captcha or cache_captcha.lower() != graph_captcha.lower():
         raise ValidationError(message='图形验证码错误!')
     return True