Пример #1
0
 def validate_captcha(self, field):
     email = self.email.data
     captcha = field.data
     captcha_cache = xcache.get(email)
     #判断memcached中是否有对应的邮箱及验证码,小写进行比较,这样用户可以不区分大小写
     if not captcha_cache or captcha.lower() != captcha_cache.lower():
         raise ValidationError('邮箱验证码错误')
Пример #2
0
 def validate_sms_captcha(self, field):
     telephone = self.telephone.data
     sms_captcha = field.data
     xcache.set('13297554024', 'luck')
     sms_captcha_mem = xcache.get(telephone)
     print('用户输入的验证码:{}'.format(sms_captcha))
     print('服务器存储的验证码:{}'.format(sms_captcha_mem))
     if not sms_captcha_mem or sms_captcha_mem != sms_captcha:
         raise ValidationError(message='短信验证码错误')
Пример #3
0
 def validate_graph_captcha(self, field):
     graph_captcha = field.data
     #因为图形验证码存储的key和值都是一样的,所以我们只要判断key是否存在就行
     if not xcache.get(graph_captcha.lower()):
         raise ValidationError(message='图形验证码错误')