|
@@ -4,16 +4,24 @@ import threading
|
4
|
4
|
import transaction
|
5
|
5
|
import typing as typing
|
6
|
6
|
|
|
7
|
+from sqlalchemy.orm import Session
|
|
8
|
+
|
|
9
|
+from tracim import CFG
|
7
|
10
|
from tracim.models.auth import User
|
8
|
11
|
from sqlalchemy.orm.exc import NoResultFound
|
9
|
|
-from tracim.exceptions import BadUserPassword, UserNotExist
|
|
12
|
+from tracim.exceptions import WrongUserPassword, UserNotExist
|
10
|
13
|
from tracim.exceptions import AuthenticationFailed
|
11
|
14
|
from tracim.models.context_models import UserInContext
|
12
|
15
|
|
13
|
16
|
|
14
|
17
|
class UserApi(object):
|
15
|
18
|
|
16
|
|
- def __init__(self, current_user: typing.Optional[User], session, config):
|
|
19
|
+ def __init__(
|
|
20
|
+ self,
|
|
21
|
+ current_user: typing.Optional[User],
|
|
22
|
+ session: Session,
|
|
23
|
+ config: CFG,
|
|
24
|
+ ) -> None:
|
17
|
25
|
self._session = session
|
18
|
26
|
self._user = current_user
|
19
|
27
|
self._config = config
|
|
@@ -65,7 +73,7 @@ class UserApi(object):
|
65
|
73
|
|
66
|
74
|
# Check methods
|
67
|
75
|
|
68
|
|
- def user_with_email_exists(self, email: str):
|
|
76
|
+ def user_with_email_exists(self, email: str) -> bool:
|
69
|
77
|
try:
|
70
|
78
|
self.get_one_by_email(email)
|
71
|
79
|
return True
|
|
@@ -86,9 +94,9 @@ class UserApi(object):
|
86
|
94
|
if user.validate_password(password):
|
87
|
95
|
return user
|
88
|
96
|
else:
|
89
|
|
- raise BadUserPassword()
|
90
|
|
- except (BadUserPassword, NoResultFound):
|
91
|
|
- raise AuthenticationFailed
|
|
97
|
+ raise WrongUserPassword()
|
|
98
|
+ except (WrongUserPassword, NoResultFound):
|
|
99
|
+ raise AuthenticationFailed()
|
92
|
100
|
|
93
|
101
|
# Actions
|
94
|
102
|
|
|
@@ -99,7 +107,7 @@ class UserApi(object):
|
99
|
107
|
email: str=None,
|
100
|
108
|
do_save=True,
|
101
|
109
|
timezone: str='',
|
102
|
|
- ):
|
|
110
|
+ ) -> None:
|
103
|
111
|
if name is not None:
|
104
|
112
|
user.display_name = name
|
105
|
113
|
|