Browse Source

few fixes for user api

Guénaël Muller 6 years ago
parent
commit
fb971b31a1
2 changed files with 11 additions and 2 deletions
  1. 3 0
      tracim/exceptions.py
  2. 8 2
      tracim/lib/core/user.py

+ 3 - 0
tracim/exceptions.py View File

91
 
91
 
92
 class BadUserPassword(TracimException):
92
 class BadUserPassword(TracimException):
93
     pass
93
     pass
94
+
95
+class UserNotExist(TracimException):
96
+    pass

+ 8 - 2
tracim/lib/core/user.py View File

6
 
6
 
7
 from tracim.models.auth import User
7
 from tracim.models.auth import User
8
 from sqlalchemy.orm.exc import NoResultFound
8
 from sqlalchemy.orm.exc import NoResultFound
9
-from tracim.exceptions import BadUserPassword
9
+from tracim.exceptions import BadUserPassword, UserNotExist
10
 from tracim.exceptions import AuthenticationFailed
10
 from tracim.exceptions import AuthenticationFailed
11
 from tracim.models.context_models import UserInContext
11
 from tracim.models.context_models import UserInContext
12
 
12
 
80
         :param in_context:
80
         :param in_context:
81
         :return:
81
         :return:
82
         """
82
         """
83
+        if not self._user:
84
+            raise UserNotExist()
83
         return self._get_correct_user_type(self._user, in_context)
85
         return self._get_correct_user_type(self._user, in_context)
84
 
86
 
85
     def get_all(self) -> typing.Iterable[User]:
87
     def get_all(self) -> typing.Iterable[User]:
95
         except:
97
         except:
96
             return False
98
             return False
97
 
99
 
98
-    def authenticate_user(self, email, password, in_context=False) -> User:
100
+    def authenticate_user(self,
101
+                          email: str,
102
+                          password: str,
103
+                          in_context=False
104
+        ) -> typing.Union[User, UserInContext]:
99
         """
105
         """
100
         Authenticate user with email and password, raise AuthenticationFailed
106
         Authenticate user with email and password, raise AuthenticationFailed
101
         if uncorrect.
107
         if uncorrect.