def validate_sms_captcha(self, field): sms_captcha = field.data telephone = self.telephone.data sms_captcha_mem = zlcache.get(telephone) if not sms_captcha_mem or sms_captcha_mem.lower() != sms_captcha.lower: raise ValidationError(message="短信验证码错误")
def validate_captcha(self, field): captcha = field.data email = self.email.data captcha_cache = zlcache.get(email) if not captcha_cache or captcha.strip().lower() != captcha_cache.lower( ): raise ValidationError("验证码错误!")
def validate_email_captcha(self, field): captcha = field.data # 获取用户输入的邮箱验证码 email = self.email.data # 获取用户输入的邮箱 captcha_cache = zlcache.get(email) # 从缓存中获取发送给用户的邮箱验证码 if not captcha_cache or captcha.lower() != captcha_cache.lower( ): # 验证用户输入的邮箱验证码 raise ValidationError('邮箱验证码错误!')
def validate_captcha(self, field): captcha = field.data email = self.email.data captcha_cache = zlcache.get(email) # 要保证有验证码 要不然直接就等于了 再转换成小写 跟这个验证码的小写进行比对 if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError("邮箱验证码错误")
def validate_graph_captcha(self, field): graph_captcha = field.data graph_captcha_mem = zlcache.get(graph_captcha.lower()) if not graph_captcha_mem: # raise ValidationError(message='图形验证码错误') #TODO pass
def validate_captcha(self, field): captcha = field.data if self.email.data != '': email = self.email.data captcha_cache = zlcache.get(email) if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError('邮箱验证码错误!')
def validate_captcha(self,field): #validate_xxxx固定写法,xxxx就是要在次验证的上面定义的属性,field=captcha captcha = field.data email = self.email.data captcha_cache = zlcache.get(email) #从memecached中获取发给用的验证码 if not captcha_cache or captcha.lower() != captcha_cache.lower(): #不区分用户传过来的大小写 raise ValidationError("邮箱验证码错误")
def validate_graph_captcha(self, field): graph_captcha = field.data if graph_captcha != '1111': graph_captcha_mem = zlcache.get(graph_captcha.lower()) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误!')
def validate_captcha(self, field): print(field.data) captcha = field.data email = self.email.data captcha_cache = zlcache.get(email) if not captcha_cache and captcha.lower() != captcha_cache.lower(): raise ValidationError('邮箱验证码错误')
def validate_sms_captcha(self, field): sms_captcha = field.data telephone = self.telephone.data if sms_captcha != '1111': sms_captcha_mem = zlcache.get(telephone) if not sms_captcha_mem or sms_captcha_mem.lower( ) != sms_captcha.lower(): raise ValidationError(message='短信验证码输入错误!')
def validate_graph_captcha(self, field): graph_captcha = field.data try: graph_captcha_number = zlcache.get(graph_captcha.lower()) if not graph_captcha_number: raise ValidationError(message='图形验证码错误!') except memcache.Client.MemcachedKeyCharacterError: raise ValidationError(message='图形验证码错误!')
def validate_graph_captcha(self, field): from utils import zlcache graph_captcha = field.data graph_captcha_mem = zlcache.get(graph_captcha.lower()) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误!') else: zlcache.delete(graph_captcha.lower())
def validate_graph_captcha(self,field): graph_captcha=field.data # print("图形验证码是:",graph_captcha) if graph_captcha!="1111": graph_captcha_mem=zlcache.get(graph_captcha) # print("缓存里的图形验证码是",graph_captcha_mem) if not graph_captcha_mem: raise ValidationError(message="图形验证码错误")
def validate_graph_captcha(self, field): graph_captcha = field.data try: graph_captcha_mem = zlcache.get(graph_captcha.lower()) except: raise ValidationError(message='图形验证码不存在!') print(graph_captcha_mem, graph_captcha) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误!')
def validate_sms_captcha(self,field): sms_captcha=field.data # print("sms_captcha是",sms_captcha) telephone=self.telephone.data if sms_captcha!="1111": #测试用 sms_captcha_mem=zlcache.get(telephone) # print("sms_mem是",sms_captcha_mem) if not sms_captcha_mem or sms_captcha_mem.lower()!=sms_captcha.lower(): raise ValidationError(message="短信验证码验证错误")
def validate_captcha(self, field): # 自定义验证器,对captcha字段更深的验证,validate_filename captcha = field.data email = self.email.data print(email) captcha_cache = zlcache.get(email) print(captcha_cache) if not captcha_cache or captcha != captcha_cache: raise ValidationError('邮箱验证码错误!')
def validate_sms_captcha(self, field): # print("类变量: ", self.sms_captcha) sms_captcha = field.data print("前端传过来的验证码", sms_captcha) telephone = self.telephone.data sms_captcha_memcached = zlcache.get(telephone) print("memcached的验证码", sms_captcha_memcached) if not sms_captcha_memcached or sms_captcha_memcached.lower() != sms_captcha.lower(): raise ValidationError(message='手机验证码错误!(/front/forms/ -> Validate)')
def validate_email_captcha(self, field): captcha = field.data email = self.email.data try: captcha_cache = zlcache.get(email) except: raise ValidationError(message='邮箱验证码不存在!') if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError(message='邮箱验证码错误!')
def validate_sms_captcha(self, field): sms_captcha = field.data telephone = self.telephone.data sms_captcha_mem = zlcache.get(telephone) print('sms_captcha {}'.format(sms_captcha)) print('sms_captcha_mem {}'.format(sms_captcha_mem)) if not sms_captcha_mem or sms_captcha_mem.lower() != sms_captcha.lower( ): raise ValidationError(message='短信验证码错误')
def validate_graph_captcha(self, field): graph_captcha = field.data # graph_captcha_mem = zlcache.get(graph_captcha.lower()) # if not graph_captcha_mem: # raise ValidationError(message='图形验证码错误!') if graph_captcha != '1111': #这是自己写的测试代码,上面也是,这里这么写是因为真正的注册需要一个真正的手机号码来注册,比较麻烦 graph_captcha_mem = zlcache.get(graph_captcha.lower()) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误!')
def validate_captcha(self, field): #form要提交的验证码和邮箱 captcha = field.data email = self.email.data #缓存里面保存的邮箱对应的验证码 captcha_cache = zlcache.get(email) #如果缓存中没有这个验证码,或者缓存中的验证码跟form提交的验证码不相等(不区分大小写) # 两个有一个不成立,就抛异常 if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError('邮箱验证码错误!')
def validate_graph_captcha(self, field): graph_captcha = field.data # TODO 测试用 if graph_captcha != '1111': print('图形验证码不等于1111') # 从memcached中取graph_captcha graph_captcha_mem = zlcache.get(graph_captcha.lower()) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误!')
def validate_email_capt(self, field): captcha = field.data if captcha: email = self.email.data captcha_cache = zlcache.get(email) if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError('邮箱验证码错误') else: pass
def validate_sms_captcha(self, field): sms_captcha = field.data # print(sms_captcha) telephone = self.telephone.data try: sms_captcha_mumber = zlcache.get(telephone) if not sms_captcha_mumber or sms_captcha_mumber.lower( ) != sms_captcha.lower(): raise ValidationError(message='短信验证码错误!') except memcache.Client.MemcachedKeyCharacterError: raise ValidationError(message='短信验证码错误!')
def validate_sms_captcha(self,field): sms_captcha=field.data telephone=self.telephone.data # if sms_captcha!='1111': sms_captcha_mem=zlcache.get(telephone) print('缓存中的短信验证码:'+sms_captcha_mem) print('发送的验证码:'+sms_captcha) if not sms_captcha_mem or sms_captcha.lower() != sms_captcha_mem.lower(): print('短信验证码错误!!!!!!!!!!') raise ValidationError(message='短信验证码错误!')
def validate_sms_captcha(self, field): # 必须传入的参数self,field # 使用fields.data和使用self.sms_captcha.data是一样的 sms_captcha = field.data telephone = self.telephone.data if sms_captcha != '1111': sms_captcha_mem = zlcache.get(telephone) if not sms_captcha_mem or sms_captcha_mem.lower( ) != sms_captcha.lower(): raise ValidationError(message='短信验证码错误')
def graph_captcha(): text, image = Captcha.gene_graph_captcha() print(text.lower()) zlcache.set(text.lower(), text.lower()) print(zlcache.get(text.lower())) out = BytesIO() image.save(out, 'png') out.seek(0) resp = make_response(out.read()) resp.content_type = 'image/png' return resp
def validate_captcha(self, field): ''' 验证输入的验证码和memcahced的验证码是否保持一致 ''' captcha = field.data # 表单中传过来的验证码 email = self.email.data # 表单中传过来的邮箱 # 1. 先拿到验证码 captcha_cache = zlcache.get(email) # memcached中存的验证码 # 2. 判断memcached中存的验证码和表单传过来的验证码是否一致,如果一致就返回true if not captcha_cache or captcha.lower() != captcha_cache.lower(): raise ValidationError('邮箱验证码错误!')
def validate_graph_captcha(self, field): graph_captcha = field.data # 该判断为测试代码 # if graph_captcha != '1111': graph_captcha_mem = zlcache.get(graph_captcha.lower()) # print('username: {}'.format(self.username.data)) # print('password1: {}'.format(self.password1.data)) # print('password2: {}'.format(self.password2.data)) # print('telephone: {}'.format(self.telephone.data)) # print('sms_captcha: {}'.format(self.sms_captcha.data)) # print('graph_captcha: {}'.format(self.graph_captcha.data)) if not graph_captcha_mem: raise ValidationError(message='图形验证码错误')
def email_captcha(): email = request.args.get('email') if not email: return restful.params_error('请传递邮箱参数') source = list(string.ascii_letters) source.extend(map(lambda x: str(x), range(10))) captcha = "".join(random.sample(source, 6)) message = Message("Python邮箱验证码", recipients=[email], body="你的验证码是:%s" % captcha) # 给邮箱发送邮件 try: mail.send(message) except: return restful.server_error() # send_mail.delay("Python邮箱验证码",[email],"你的验证码是:%s" % captcha) zlcache.set(email, captcha) print(zlcache.get(email)) return restful.success()