本文整理汇总了Python中models.user.User.find方法的典型用法代码示例。如果您正苦于以下问题:Python User.find方法的具体用法?Python User.find怎么用?Python User.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
class UserRoleController:
def __init__(self, connection):
self.connection = connection
from models.user import User
from models.role import Role
from models.user_role import UserRole
self.user = User(connection)
self.role = Role(connection)
self.user_role = UserRole(connection)
def find_by_user_id(self, user_id):
user_roles = self.user_role.find({'user_id': user_id})
print user_roles
ids = [ user_role['role_id'] for user_role in user_roles ]
if ADMIN_ROLE_ID in ids:
params = {}
else:
ids = [ user_role['role_id'] for user_role in user_roles if user_role['is_admin'] ]
params = {'ids': ids}
print params
return self.role.find(params)
def find_by_role_id(self, role_id):
user_roles = self.user_role.find({'role_id': role_id})
print user_roles
ids = [row['user_id'] for row in user_roles]
params = {'ids': ids}
print params
return self.user.find(params)
示例2: get_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
def get_user(id):
"""
Get user information
"""
user = User.find(id)
if not user:
msg = f"User not found."
raise exceptions.NotFound({"message": msg})
return user.serialize()
示例3: resolve
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
def resolve(self, authorization: http.Header, route: Route) -> AuthData:
"""
Describe
"""
if route.handler.__name__ in self.no_auth_list:
log.info(f"No auth handler")
return AuthData()
scheme, token = self.get_data_by_header(authorization)
if "Bearer" in scheme:
try:
payload = jwt.decode(token, self.secret, self.algorithms)
user_id = payload.get("user_id")
user = User.find(user_id)
if user is None:
msg = "Unauthorized, invalid token"
raise exceptions.HTTPException({"message": msg}, status_code=401)
return AuthData(user, None)
except jwt.DecodeError:
msg = "Unauthorized, invalid token"
raise exceptions.HTTPException({"message": msg}, status_code=401)
except jwt.ExpiredSignatureError:
msg = "Unauthorized, token expired"
raise exceptions.HTTPException({"message": msg}, status_code=401)
if "Token" in scheme:
if route.handler.__name__ in self.accept_token_list:
service = Service.where("token", token).first()
if service is None:
msg = "Unauthorized, invalid token"
raise exceptions.HTTPException({"message": msg}, status_code=401)
return AuthData(None, service)
msg = f"This endpoint is not available by Token, please use Bearer header"
raise exceptions.Forbidden({"message": msg})
示例4: delete_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
def delete_user(id):
"""
Delete a user
"""
user = User.find(id)
if not user:
msg = f"User not found."
raise exceptions.NotFound({"message": msg})
user.delete()
msg = "User deleted successfully."
log.info(f"{msg} - ID: {id}")
return {"message": msg}
示例5: update_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
def update_user(userData: UserType, id):
"""
Update user information
"""
user = User.find(id)
if not user:
msg = f"User not found."
raise exceptions.NotFound({"message": msg})
user.update(**userData)
msg = "User update successfully."
log.info(f"{msg} - ID: {id}")
return {"message": msg}
示例6: User
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
import sys
sys.path.insert(0, r'../..')
from models.connection import connection
from models.user import User
user = User(connection)
print user.find({'role_id':'3867c370-552f-43b8-bed9-6aa00ffc41b4'})
print user.find({'role_ids':['3867c370-552f-43b8-bed9-6aa00ffc41b4', 'ffffffff-ffff-ffff-ffff-ffffffffffff']})
print user.find({'role_ids':['3867c370-552f-43b8-bed9-6aa00ffc41b4', '435a6417-6c1f-4d7c-87dd-e8f6c0effc7a']})
print user.find({'ids':['b2fc88a6-7253-4850-8d5a-07639b1315aa', 'c8b5dbbe-edd1-4e78-b03a-63b0d779be85']})
print user.find({'ids':[]})
print user.find({})
print user.create({'id': '117043220775623860708',
'family_name': 'Ough',
'given_name': 'Alex',
'email': '[email protected]'
})
示例7: user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import find [as 别名]
def user(self):
u = User.find(id=self.user_id)
return u