本文整理匯總了Python中webapp2_extras.appengine.auth.models.User.create_auth_token方法的典型用法代碼示例。如果您正苦於以下問題:Python User.create_auth_token方法的具體用法?Python User.create_auth_token怎麽用?Python User.create_auth_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webapp2_extras.appengine.auth.models.User
的用法示例。
在下文中一共展示了User.create_auth_token方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from webapp2_extras.appengine.auth.models import User [as 別名]
# 或者: from webapp2_extras.appengine.auth.models.User import create_auth_token [as 別名]
def post(self):
self.response.headers["Content-Type"] = "application/json"
email = self.request.get("email")
password = self.request.get("password")
try:
user = User.get_by_auth_password(email, password)
except:
self.response.write(resp.fail_pass())
return
if not user:
self.response.write(resp.fail_pass())
else:
token = User.create_auth_token(user.key.id())
self.response.write(
resp.success(
{
"Token": token,
"User": {
"firstname": user.firstname,
"lastname": user.lastname,
"email": user.auth_ids[0],
"id": user.key.id(),
},
}
)
)
示例2: post
# 需要導入模塊: from webapp2_extras.appengine.auth.models import User [as 別名]
# 或者: from webapp2_extras.appengine.auth.models.User import create_auth_token [as 別名]
def post(self):
self.response.headers['Content-Type'] = 'application/json'
firstname = self.request.get('firstname')
lastname = self.request.get('lastname')
email = self.request.get('email')
password = self.request.get('password')
work, info = User.create_user(
email,
firstname=firstname,
lastname=lastname,
password_raw=password
)
if not work:
self.response.write(resp.fail(
'email',
'Email address already exists'
))
else:
user = info
token = User.create_auth_token(user.key.id())
self.response.write(resp.success({
'Token' : token,
'User' : {
'firstname' : user.firstname,
'lastname' : user.lastname,
'email' : user.auth_ids[0],
'id' : user.key.id()
}
}))