本文整理汇总了Python中models.users.User.objects方法的典型用法代码示例。如果您正苦于以下问题:Python User.objects方法的具体用法?Python User.objects怎么用?Python User.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.User
的用法示例。
在下文中一共展示了User.objects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def get(self):
async_client = AsyncHTTPClient()
auth_code = self.get_argument("code", None)
if auth_code:
# 第一步 获取access_token
auth_token_url = self.__build_auth_token_url(auth_code)
token_response = yield async_client.fetch(auth_token_url)
access_token, refresh_token = self.__parse_token(token_response)
# 第二不 得到用户身份信息
auth_me_url = self.__build_auth_me_url(access_token)
open_response = yield async_client.fetch(auth_me_url)
openid = self.__parse_me(open_response)
# 第三布 获取用户基本信息
auth_user_url = self.__build_auth_user_url(access_token, openid)
user_info = yield async_client.fetch(auth_user_url)
user = self.__parse_user(user_info, access_token, refresh_token, openid)
# 确认用户是否已经登录过
try:
user = User.objects(type='qq', uid=openid)[0]
except Exception as ex:
app_log.exception(ex)
finally:
user.save()
self.set_secure_cookie('userid', str(user.id))
self.set_secure_cookie('type', 'qq')
self.redirect("/")
else:
# 登录失败,跳转到登录页面
self.redirect("/sigin")
示例2: login
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def login():
user_name = request.form['username'];
password = request.form['password'];
for user in User.objects(user_name=user_name):
if(user.password == password):
return json.dumps({"result_code":1, "result_message":"Login succeded"})
return json.dumps({"result_code":0, "result_message":"Login failed"})
示例3: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def get(self, id):
user = User.objects(id=id)[0]
books = Book.objects(likes__in=[user])
bgs = self.grouped(books)
kwargs = {
"page_heading": unicode(user.name),
"groups": self.get_groups(),
"user": user,
"books": books,
"bgs": bgs
}
self.render('user.html', **kwargs)
示例4: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def get(self):
if self.get_argument("openid.mode", None):
result = yield self.get_authenticated_user()
try:
user = User.objects(type='google', email=result['email'])[0]
except Exception as ex:
app_log.error(ex)
user = User(uid=str(uuid4()),
type='google',
email=result['email'],
name=result['name'],
avatar=getAvatar('email')
)
user.save()
self.set_secure_cookie('userid', str(user.id))
self.set_secure_cookie('type', 'google')
self.redirect("/")
else:
yield self.authenticate_redirect()
示例5: post
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def post(self):
email = self.get_argument('email').decode()
password = self.get_argument('password').decode()
try:
user = User.objects(email=email, password=password).first()
if not user:
self.redirect('/sigin')
except Exception as ex:
app_log.error(ex)
self.redirect('/sigin')
else:
self.set_secure_cookie('userid', str(user.id))
self.set_secure_cookie('admin', "True")
try:
next_url = self.get_argument('next')
if next_url:
self.redirect(next_url)
return
self.redirect('/')
except Exception as ex:
app_log.exception(ex)
self.redirect('/')
示例6: save_douban_user
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def save_douban_user(user):
try:
user = User.objects(type='douban', uid=user['uid'])[0]
except Exception, e:
app_log.error(e)
示例7: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import objects [as 别名]
def get(self):
self.set_header("Content-Type", "application/json; charset=UTF-8")
users = User.objects() \
.exclude("password").exclude("access_token").exclude("uid").exclude('password')
self.write(users.to_json())