本文整理匯總了Python中www.models.User.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get_by_id方法的具體用法?Python User.get_by_id怎麽用?Python User.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類www.models.User
的用法示例。
在下文中一共展示了User.get_by_id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import get_by_id [as 別名]
def post(self):
parameters = self.request.POST
parameters = utils.pythonize(dict(parameters))
email = parameters.get("email")
password = parameters.get("password_raw")
data = {}
data["errors"] = {}
if email:
if not re.match(r"[^@][email protected][^@]+\.[^@]+", email):
data["errors"]["email"] = "This value must be a valid email address"
else:
data["errors"]["email"] = 'This value is required'
if password:
if len(password) < 8:
data["errors"]["password"] = "This value must be at least 8 characters"
else:
data["errors"]["password"] = "This value is required"
if data["errors"]:
self.write_json(json.dumps(data))
return
user = None
try:
email = email.lower()
user = self.auth.get_user_by_password(email, password)
except InvalidAuthIdError:
data["errors"]["email"]= "No user exists with this email."
self.write_json(json.dumps(data))
return
except InvalidPasswordError:
data["errors"]["password"]= "This password is incorrect."
self.write_json(json.dumps(data))
return
user = User.get_by_id(user['user_id'])
if not user:
# this should never happen, but just to be safe
data["redirect"] = self.uri_for('authenticate')
elif user.has_roles(['ADMINISTRATOR', 'STAFF']):
data["redirect"] = self.uri_for('admin_home')
elif user.has_role('HACKER'):
data["redirect"]= self.uri_for('register')
else:
data["errors"]["email"] = "Sorry, but you cannot authenticate here"
self.auth.unset_session()
self.write_json(json.dumps(data))