def verify_code(self): timestemp = time.time() imgurl = 'http://api.chaxun.la/api/seccode/?0.{0}'.format(timestemp) if self.download(imgurl): captcha = Captcha() code_result = captcha.verification(filename='captcha.gif') self.verify = code_result.get('Result')
def validate(self): dbuser=User.getUser(self.user) if (dbuser==None): self.handler.redirect('/register') return if (dbuser.verified==True): self.handler.redirect('/list') return if (dbuser.regcode==None or dbuser.regcode==''): self.handler.redirect('/register') return values={} code=self.request.get('code') if (code!='' and dbuser.regcode==code): dbuser.verified=True dbuser.regcode='' dbuser.put() self.handler.redirect('/list') return values['user']=self.user values['email']=self.user.email() values['captcha']=Captcha.getCaptchaHtml() if (code!=''): values['reason']='Sorry, the entered code \"'+code+'\" does not match our records. Please try again.' return self.render('validate',values)
def register(self): dbuser=User.getUser(self.user) if (dbuser!=None and dbuser.verified!=None and dbuser.verified==True): self.handler.redirect('/list') return go=self.request.get('go') if (dbuser!=None and go!="true"): self.handler.redirect("/validate") return values={} values['user']=self.user values['email']=self.user.email() values['captcha']=Captcha.getCaptchaHtml() if (go=="true"): challenge = self.request.get('recaptcha_challenge_field') response = self.request.get('recaptcha_response_field') captcha = Captcha.validateCaptcha(challenge, response) if (not captcha.is_valid): self.handler.redirect("/register") logging.warn('Captcha result was false') return logging.warn('Captcha result was true') sha1=hashlib.sha1() sha1.update(str(random.randint(0,sys.maxint))) sha1.update(str(time.time())) sha1.update(self.user.email()) codehash=sha1.hexdigest() logging.info(codehash) #TODO: Send reg email here dbuser=User.get_or_insert(key_name=self.user.user_id()) dbuser.regcode=codehash dbuser.put() self.handler.redirect("/validate") return return self.render('register',values)