本文整理汇总了Python中tracim_backend.lib.core.user.UserApi.get_user_with_context方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.get_user_with_context方法的具体用法?Python UserApi.get_user_with_context怎么用?Python UserApi.get_user_with_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.user.UserApi
的用法示例。
在下文中一共展示了UserApi.get_user_with_context方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def create_user(self, context, request: TracimRequest, hapic_data=None):
"""
Create new user
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
gapi = GroupApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
groups = [gapi.get_one_with_name(hapic_data.body.profile)]
password = hapic_data.body.password
if not password and hapic_data.body.email_notification:
password = password_generator()
user = uapi.create_user(
auth_type=AuthType.UNKNOWN,
email=hapic_data.body.email,
password=password,
timezone=hapic_data.body.timezone,
lang=hapic_data.body.lang,
name=hapic_data.body.public_name,
do_notify=hapic_data.body.email_notification,
groups=groups,
do_save=True
)
return uapi.get_user_with_context(user)
示例2: account
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def account(self, context, request: TracimRequest, hapic_data=None):
"""
Get user infos.
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
return uapi.get_user_with_context(request.current_user)
示例3: whoami
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def whoami(self, context, request: TracimRequest, hapic_data=None):
"""
Return current logged-in user.
If user is not authenticated or the session has expired, a 401 is returned.
This is the recommanded way to check if the user is already authenticated
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
request.current_user,
session=request.dbsession,
config=app_config,
)
user = uapi.get_current_user() # User
return uapi.get_user_with_context(user)
示例4: users
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def users(self, context, request: TracimRequest, hapic_data=None):
"""
Get all users
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
users = uapi.get_all()
context_users = [
uapi.get_user_with_context(user) for user in users
]
return context_users
示例5: set_account_email
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def set_account_email(self, context, request: TracimRequest, hapic_data=None):
"""
Set user Email
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
user = uapi.set_email(
request.current_user,
hapic_data.body.loggedin_user_password,
hapic_data.body.email,
do_save=True
)
return uapi.get_user_with_context(user)
示例6: set_account_infos
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def set_account_infos(self, context, request: TracimRequest, hapic_data=None):
"""
Set user info data
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
user = uapi.update(
request.current_user,
name=hapic_data.body.public_name,
timezone=hapic_data.body.timezone,
lang=hapic_data.body.lang,
do_save=True
)
return uapi.get_user_with_context(user)
示例7: account_known_members
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def account_known_members(self, context, request: TracimRequest, hapic_data=None):
"""
Get known users list
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
show_deactivated=False,
)
users = uapi.get_known_user(
acp=hapic_data.query.acp,
exclude_user_ids=hapic_data.query.exclude_user_ids,
exclude_workspace_ids=hapic_data.query.exclude_workspace_ids,
)
context_users = [
uapi.get_user_with_context(user) for user in users
]
return context_users
示例8: login
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def login(self, context, request: TracimRequest, hapic_data=None):
"""
Logs the user into the system.
In case of success, the JSON returned is the user profile.
In that case, a cookie is created with a session_key and an expiration date.
Eg. : `session_key=932d2ad68f3a094c2d4da563ccb921e6479729f5b5f707eba91d4194979df20831be48a0; expires=Mon, 22-Oct-2018 19:37:02 GMT; Path=/; SameSite=Lax`
"""
login = hapic_data.body
app_config = request.registry.settings['CFG'] # type: CFG
uapi = UserApi(
None,
session=request.dbsession,
config=app_config,
)
ldap_connector = None
if AuthType.LDAP in app_config.AUTH_TYPES:
ldap_connector = get_ldap_connector(request)
user = uapi.authenticate(login.email, login.password, ldap_connector)
remember(request, user.user_id)
return uapi.get_user_with_context(user)
示例9: test_unit__get_user_with_context__nominal_case
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_user_with_context [as 别名]
def test_unit__get_user_with_context__nominal_case(self):
user = User(
email='[email protected]',
display_name='Admin',
is_active=True,
)
api = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
new_user = api.get_user_with_context(user)
assert isinstance(new_user, UserInContext)
assert new_user.user == user
assert new_user.profile == 'nobody'
assert new_user.user_id == user.user_id
assert new_user.email == '[email protected]'
assert new_user.display_name == 'Admin'
assert new_user.is_active is True
# TODO - G.M - 03-05-2018 - [avatar][calendar] Should test this
# with true value when those param will be available.
assert new_user.avatar_url is None
assert new_user.calendar_url is None