|
1 | 1 | from typing import Dict, List, Tuple
|
2 | 2 |
|
3 |
| -from craftship.auth.domain import model |
4 |
| -from craftship.auth.services import unit_of_work |
5 |
| -from craftship.auth.adapters import email_sender |
6 |
| -from craftship.auth import config |
7 |
| -from craftship.auth import utils |
8 |
| -from craftship.core.exceptions import ApoloException |
| 3 | +from src.auth.domain import model |
| 4 | +from src.auth.services import unit_of_work |
| 5 | +from src.auth.adapters import email_sender |
| 6 | +from src.auth import config |
| 7 | +from src.auth import utils |
9 | 8 |
|
| 9 | +from src.core.exceptions import ServerException |
10 | 10 |
|
11 |
| -class UnknownUser(ApoloException): |
| 11 | + |
| 12 | +class UnknownUser(ServerException): |
12 | 13 | def __init__(self, access_key: str):
|
13 | 14 | super().__init__(f"Access key {access_key} does not exist")
|
14 | 15 |
|
15 | 16 |
|
16 |
| -class UserAlreadyExists(ApoloException): |
| 17 | +class UserAlreadyExists(ServerException): |
17 | 18 | def __init__(self, access_key: str):
|
18 | 19 | super().__init__(f"Access key {access_key} already exists")
|
19 | 20 |
|
20 | 21 |
|
21 |
| -class InvalidEmail(ApoloException): |
| 22 | +class InvalidEmail(ServerException): |
22 | 23 | def __init__(self, email: str):
|
23 | 24 | super().__init__(f"Email {email} not valid")
|
24 | 25 |
|
25 | 26 |
|
26 |
| -class WrongCredentials(ApoloException): |
| 27 | +class WrongCredentials(ServerException): |
27 | 28 | def __init__(self):
|
28 | 29 | super().__init__("Username or password invalid")
|
29 | 30 |
|
30 | 31 |
|
31 |
| -class RoleAlreadyExists(ApoloException): |
| 32 | +class RoleAlreadyExists(ServerException): |
32 | 33 | def __init__(self, code: str):
|
33 | 34 | super().__init__(f"Role with code {code} already exists")
|
34 | 35 |
|
35 | 36 |
|
36 |
| -class RoleNotFound(ApoloException): |
| 37 | +class RoleNotFound(ServerException): |
37 | 38 | def __init__(self, code: str):
|
38 | 39 | super().__init__(f"Role with code {code} not found")
|
39 | 40 |
|
40 | 41 |
|
41 |
| -class NotAllowed(ApoloException): |
| 42 | +class NotAllowed(ServerException): |
42 | 43 | def __init__(self, access_key: str, action: str, resource: str):
|
43 | 44 | super().__init__(
|
44 | 45 | f"User {access_key} not allowed to perform action {action} on "
|
@@ -88,6 +89,7 @@ def create_user(
|
88 | 89 | if user:
|
89 | 90 | raise UserAlreadyExists(access_key)
|
90 | 91 |
|
| 92 | + # TODO here we should be passing configs to domain layer |
91 | 93 | user = model.User(access_key, name, email, password)
|
92 | 94 | if not user.is_email_valid():
|
93 | 95 | raise InvalidEmail(email)
|
@@ -121,6 +123,7 @@ def reset_password(
|
121 | 123 | user = uow.users.get(access_key)
|
122 | 124 | if not user:
|
123 | 125 | raise UnknownUser(access_key)
|
| 126 | + # TODO: this should be inside adapters instead of domain |
124 | 127 | email_html = user.generate_reset_pwd_email(client_url=client_url)
|
125 | 128 | email_sender.send_email(
|
126 | 129 | email_to=user.email,
|
|
0 commit comments