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()
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()
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()
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()
def send(): form = SmscaptchaForm(request.form) if form.validate(): mobile = request.form.get("telephone") captcha = Captcha.gene_text() #调用验证码内容 if send_captcha.send_capt(mobile, captcha): #调用封装好的短信发送函数 cache.set(mobile, captcha) #将短信验证码存储在memcache中 return restful.success(message="发送成功") #成功直接调用不传参数 else: return restful.paramserror(message="发送失败") else: message = form.errors.popitem()[1][0] return restful.paramserror(message)
def manage_send_captcha_email(): email=request.form.get('email') Captcha.number=6 code=Captcha.gene_text() Captcha.number=4 db_code=Utils_Redis.get('email') if db_code: return xtjson.json_params_error(message=u'已向该邮箱发送邮件了,请稍后再试!') else: Utils_Redis.set(email,code.lower(),ex=10*60) dic=dict(subject=u'报关系统修改邮箱验证码',receivers=email,body=u'您的验证码为 %s 在10分钟有效' %code) celery_send_email.delay(**dic) return xtjson.json_result()
def validate(self): if not super(SMSCaptchaForm,self).validate(): return False else: phone=self.phone.data db_cache=Utils_Redis.get(phone) Captcha.number=6 text=Captcha.gene_text() Captcha.number = 4 if db_cache: self.phone.errors.append(u'已经向该手机发送验证码了,请%s分钟后再试!' %SMS_TIME) return False else: Utils_Redis.set(phone,text.lower(),ex=SMS_TIME*60) celery_send_sms.delay(phone,text) return True
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()
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'手机号码格式不正确,请重新填写!') captcha = Captcha.gene_text() 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_APP_SIGN_NAME req.sms_param = constants.ALIDAYU_APP_PARAM % ('Jay', captcha) req.rec_num = telephone.decode('utf-8').encode('ascii') req.sms_template_code = constants.ALIDAYU_APP_TEMPLATE_CODE try: # print '短信验证码是:', captcha # 设置缓存 xtcache.set(telephone, captcha) resp = req.getResponse()