Exemplo n.º 1
0
 def _get_current_user_email(self) -> str:
     try:
         if not self.environ["http_authenticator.username"]:
             raise UserNotFoundInTracimRequest("No current user has been found in the context")
     except UserNotFoundInTracimRequest as exc:
         raise NotAuthenticated("User not found") from exc
     return self.environ["http_authenticator.username"]
Exemplo n.º 2
0
 def _get_current_user_email(self) -> str:
     try:
         if not self.environ["http_authenticator.username"]:
             raise UserNotFoundInTracimRequest(
                 "You request a current user "
                 "but the context not permit to found one")
     except UserNotFoundInTracimRequest as exc:
         raise NotAuthenticated("User not found") from exc
     return self.environ["http_authenticator.username"]
Exemplo n.º 3
0
 def _get_current_user_id(self) -> int:
     try:
         if not self.authenticated_userid:
             raise UserNotFoundInTracimRequest(
                 "You request a current user "
                 "but the context not permit to found one")
     except UserNotFoundInTracimRequest as exc:
         raise NotAuthenticated("User not found") from exc
     return self.authenticated_userid
Exemplo n.º 4
0
    def current_user(self) -> User:
        # INFO - G.M - 24-03-2020 - load authenticate mecanism by calling authenticated_userid.
        # this will prefetch self._current_user value.
        try:
            if not self.authenticated_userid:
                raise UserNotFoundInTracimRequest(
                    "No current user has been found in the context")
        except UserNotFoundInTracimRequest as exc:
            raise NotAuthenticated("User not found") from exc

        current_user = self._current_user
        return current_user
Exemplo n.º 5
0
 def _get_auth_safe_user(
         self,
         request: 'TracimRequest',
 ) -> User:
     """
     Get current pyramid authenticated user from request
     :param request: pyramid request
     :return: current authenticated user
     """
     app_config = request.registry.settings['CFG']
     uapi = UserApi(None, session=request.dbsession, config=app_config)
     login = ''
     try:
         login = request.authenticated_userid
         if not login:
             raise UserNotFoundInTracimRequest('You request a current user but the context not permit to found one')  # nopep8
         user = uapi.get_one(login)
         if not user.is_active:
             raise UserAuthenticatedIsNotActive('User {} is not active'.format(login))
     except (UserDoesNotExist, UserNotFoundInTracimRequest) as exc:
         raise NotAuthenticated('User {} not found'.format(login)) from exc
     return user
Exemplo n.º 6
0
 def _get_current_webdav_username(self) -> str:
     if not self.environ.get("http_authenticator.username"):
         raise NotAuthenticated("User not found")
     return self.environ["http_authenticator.username"]