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,3 +91,6 @@ class AuthenticationFailed(TracimException):
91 91
 
92 92
 class BadUserPassword(TracimException):
93 93
     pass
94
+
95
+class UserNotExist(TracimException):
96
+    pass

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

@@ -6,7 +6,7 @@ import typing as typing
6 6
 
7 7
 from tracim.models.auth import User
8 8
 from sqlalchemy.orm.exc import NoResultFound
9
-from tracim.exceptions import BadUserPassword
9
+from tracim.exceptions import BadUserPassword, UserNotExist
10 10
 from tracim.exceptions import AuthenticationFailed
11 11
 from tracim.models.context_models import UserInContext
12 12
 
@@ -80,6 +80,8 @@ class UserApi(object):
80 80
         :param in_context:
81 81
         :return:
82 82
         """
83
+        if not self._user:
84
+            raise UserNotExist()
83 85
         return self._get_correct_user_type(self._user, in_context)
84 86
 
85 87
     def get_all(self) -> typing.Iterable[User]:
@@ -95,7 +97,11 @@ class UserApi(object):
95 97
         except:
96 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 106
         Authenticate user with email and password, raise AuthenticationFailed
101 107
         if uncorrect.