本文整理汇总了Python中model.user.User.getUser方法的典型用法代码示例。如果您正苦于以下问题:Python User.getUser方法的具体用法?Python User.getUser怎么用?Python User.getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.getUser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import getUser [as 别名]
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)
示例2: register
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import getUser [as 别名]
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)
示例3: dispatch
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import getUser [as 别名]
def dispatch(self):
method=Controller.methodre.match(self.request.path)
if (method == None):
context='root' # Since we can't have a method called '/' :-)
else:
context=method.group(1)
cached=memcache.get(self.request.url)
view=None
if (cached==None):
# First try to find a view from Public
view=Public(self)
function=getattr(view,context,None)
allowcaching=True
# Second try to find a view from Protected
if (function==None):
allowcaching=False
check=getattr(Protected(self,None),context,None)
if (check!=None):
user = users.get_current_user()
if (user!=None):
view=Protected(self,user)
function=getattr(view,context,None)
else:
# Method is there, but we aren't logged in, redirect to login
self.redirect(users.create_login_url(self.request.uri))
return
# Third try to find a view from Private
if (function==None):
allowcaching=False
check=getattr(Private(self,None,None),context,None)
if (check!=None):
user = users.get_current_user()
if (user==None):
self.redirect(users.create_login_url(self.request.uri))
return
dbuser=User.getUser(user)
if (dbuser!=None and dbuser.verified==True):
view=Private(self,user,dbuser)
function=getattr(view,context,None)
else :
if (dbuser==None or dbuser.regcode==None or dbuser.regcode==''):
logging.info('User does not exist')
self.redirect("/register")
return
else:
logging.info('Unverified user')
self.redirect("/validate")
return
if (function==None):
self.redirect("/")
return
logging.info('Dispatching to view '+context)
cached=function()
content=view.getContentType()
if (allowcaching and cached!=None):
memcache.add(self.request.url,cached,120)
memcache.add("type."+self.request.url,content,120)
else:
logging.info('Using cached render for '+self.request.url)
content=memcache.get("type."+self.request.url)
self.response.headers['Content-Type'] = content
self.response.out.write(cached)
logging.info(users.create_logout_url(self.request.uri))
return