passphera-core 0.10.0__py3-none-any.whl → 0.11.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +0,0 @@
1
- from passphera_core.entities.generator import Generator
2
- from passphera_core.exceptions import InvalidAlgorithmException
@@ -1,78 +1,57 @@
1
1
  from datetime import datetime, timezone
2
2
  from uuid import UUID
3
3
 
4
- from passphera_core.entities import Generator, GeneratorConfig
5
- from passphera_core.interfaces import GeneratorRepository, GeneratorConfigRepository
4
+ from passphera_core.entities import Generator
5
+ from passphera_core.interfaces import GeneratorRepository
6
6
 
7
7
 
8
8
  class GetGeneratorUseCase:
9
9
  def __init__(self, generator_repository: GeneratorRepository):
10
10
  self.generator_repository: GeneratorRepository = generator_repository
11
11
 
12
- def execute(self, user_id: UUID) -> Generator:
13
- return self.generator_repository.find_by_user_id(user_id)
12
+ def execute(self, generator_id: UUID) -> Generator:
13
+ return self.generator_repository.get(generator_id)
14
14
 
15
15
 
16
- class GetGeneratorConfigPropertyUseCase:
17
- def __init__(self, generator_repository: GeneratorRepository, generator_config_repository: GeneratorConfigRepository):
16
+ class GetGeneratorPropertyUseCase:
17
+ def __init__(self, generator_repository: GeneratorRepository):
18
18
  self.generator_repository: GeneratorRepository = generator_repository
19
- self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
20
19
 
21
- def execute(self, user_id: UUID, field: str) -> str:
22
- generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
23
- generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
24
- return getattr(generator_config_entity, field)
20
+ def execute(self, generator_id: UUID, field: str) -> str:
21
+ generator_entity: Generator = self.generator_repository.get(generator_id)
22
+ return getattr(generator_entity, field)
25
23
 
26
24
 
27
- class UpdateGeneratorConfigUseCase:
28
- def __init__(
29
- self,
30
- generator_repository: GeneratorRepository,
31
- generator_config_repository: GeneratorConfigRepository,
32
- ):
25
+ class UpdateGeneratorPropertyUseCase:
26
+ def __init__(self, generator_repository: GeneratorRepository):
33
27
  self.generator_repository: GeneratorRepository = generator_repository
34
- self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
35
28
 
36
- def execute(self, user_id: UUID, field: str, value: str) -> None:
37
- generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
38
- generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
39
- setattr(generator_config_entity, field, value)
29
+ def execute(self, generator_id: UUID, field: str, value: str) -> None:
30
+ generator_entity: Generator = self.generator_repository.get(generator_id)
31
+ setattr(generator_entity, field, value)
40
32
  if field == 'algorithm':
41
- generator_config_entity.get_algorithm()
42
- generator_config_entity.updated_at = datetime.now(timezone.utc)
43
- self.generator_config_repository.update(generator_config_entity)
44
-
33
+ generator_entity.get_algorithm()
34
+ generator_entity.updated_at = datetime.now(timezone.utc)
35
+ self.generator_repository.update(generator_entity)
45
36
 
46
37
 
47
38
  class AddCharacterReplacementUseCase:
48
- def __init__(
49
- self,
50
- generator_repository: GeneratorRepository,
51
- generator_config_repository: GeneratorConfigRepository,
52
- ):
39
+ def __init__(self, generator_repository: GeneratorRepository):
53
40
  self.generator_repository: GeneratorRepository = generator_repository
54
- self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
55
41
 
56
- def execute(self, user_id: UUID, character: str, replacement: str) -> None:
57
- generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
58
- generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
59
- generator_config_entity.replace_character(character, replacement)
60
- generator_config_entity.updated_at = datetime.now(timezone.utc)
61
- self.generator_config_repository.update(generator_config_entity)
42
+ def execute(self, generator_id: UUID, character: str, replacement: str) -> None:
43
+ generator_entity: Generator = self.generator_repository.get(generator_id)
44
+ generator_entity.replace_character(character, replacement)
45
+ generator_entity.updated_at = datetime.now(timezone.utc)
46
+ self.generator_repository.update(generator_entity)
62
47
 
63
48
 
64
49
  class ResetCharacterReplacementUseCase:
65
- def __init__(
66
- self,
67
- generator_repository: GeneratorRepository,
68
- generator_config_repository: GeneratorConfigRepository,
69
- ):
50
+ def __init__(self, generator_repository: GeneratorRepository,):
70
51
  self.generator_repository: GeneratorRepository = generator_repository
71
- self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
72
52
 
73
- def execute(self, user_id: UUID, character: str) -> None:
74
- generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
75
- generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
76
- generator_config_entity.reset_character(character)
77
- generator_config_entity.updated_at = datetime.now(timezone.utc)
78
- self.generator_config_repository.update(generator_config_entity)
53
+ def execute(self, generator_id: UUID, character: str) -> None:
54
+ generator_entity: Generator = self.generator_repository.get(generator_id)
55
+ generator_entity.reset_character(character)
56
+ generator_entity.updated_at = datetime.now(timezone.utc)
57
+ self.generator_repository.update(generator_entity)
@@ -1,9 +1,8 @@
1
- from datetime import datetime, timezone
2
1
  from uuid import UUID
3
2
 
4
- from passphera_core.entities import Password, Generator, User
5
- from passphera_core.exceptions import EntityNotFoundException
6
- from passphera_core.interfaces import PasswordRepository, GeneratorRepository, UserRepository
3
+ from passphera_core.entities import Password, Generator
4
+ from passphera_core.exceptions import DuplicatePasswordException, PasswordNotFoundException
5
+ from passphera_core.interfaces import PasswordRepository, GeneratorRepository
7
6
 
8
7
 
9
8
  class GeneratePasswordUseCase:
@@ -11,108 +10,77 @@ class GeneratePasswordUseCase:
11
10
  self,
12
11
  password_repository: PasswordRepository,
13
12
  generator_repository: GeneratorRepository,
14
- user_repository: UserRepository
15
13
  ):
16
14
  self.password_repository: PasswordRepository = password_repository
17
15
  self.generator_repository: GeneratorRepository = generator_repository
18
- self.user_repository: UserRepository = user_repository
19
16
 
20
- def execute(self, user_id: UUID, context: str, text: str) -> Password:
21
- user_entity: User = self.user_repository.find_by_id(user_id)
22
- generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator_id)
17
+ def execute(self, generator_id: UUID, context: str, text: str) -> Password:
18
+ password_entity: Password = self.password_repository.get_by_context(context)
19
+ if password_entity:
20
+ raise DuplicatePasswordException(password_entity)
21
+ generator_entity: Generator = self.generator_repository.get(generator_id)
23
22
  password: str = generator_entity.generate_password(text)
24
- password_entity: Password = Password(user_id=user_id, context=context, text=text, password=password)
23
+ password_entity: Password = Password(context=context, text=text, password=password)
25
24
  password_entity.encrypt()
26
25
  self.password_repository.save(password_entity)
27
- user_entity.add_password(password_entity.id)
28
- self.user_repository.update(user_entity)
29
26
  return password_entity
30
27
 
31
28
 
32
- class GetPasswordByIdUseCase:
29
+ class GetPasswordByContextUseCase:
33
30
  def __init__(self, password_repository: PasswordRepository):
34
31
  self.password_repository: PasswordRepository = password_repository
35
32
 
36
- def execute(self, password_id: UUID) -> Password:
37
- password_entity: Password = self.password_repository.find_by_id(password_id)
33
+ def execute(self, context: str) -> Password:
34
+ password_entity: Password = self.password_repository.get_by_context(context)
38
35
  if not password_entity:
39
- raise EntityNotFoundException(password_entity)
36
+ raise PasswordNotFoundException()
40
37
  return password_entity
41
38
 
42
39
 
43
- class GetPasswordByContextUseCase:
44
- def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
45
- self.password_repository: PasswordRepository = password_repository
46
- self.user_repository: UserRepository = user_repository
47
-
48
- def execute(self, user_id: UUID, context: str) -> Password:
49
- user_entity: User = self.user_repository.find_by_id(user_id)
50
- for password_id in user_entity.passwords_ids:
51
- password_entity: Password = self.password_repository.find_by_id(password_id)
52
- if password_entity.context == context:
53
- return password_entity
54
- raise EntityNotFoundException(Password())
55
-
56
-
57
40
  class UpdatePasswordUseCase:
58
41
  def __init__(
59
42
  self,
60
43
  password_repository: PasswordRepository,
61
44
  generator_repository: GeneratorRepository,
62
- user_repository: UserRepository
63
45
  ):
64
46
  self.password_repository: PasswordRepository = password_repository
65
47
  self.generator_repository: GeneratorRepository = generator_repository
66
- self.user_repository: UserRepository = user_repository
67
-
68
- def execute(self, user_id: UUID, context: str, text: str) -> Password:
69
- user_entity: User = self.user_repository.find_by_id(user_id)
70
- generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator_id)
71
- for password_id in user_entity.passwords_ids:
72
- password_entity: Password = self.password_repository.find_by_id(password_id)
73
- if password_entity.context == context:
74
- password_entity.password = generator_entity.generate_password(text)
75
- password_entity.encrypt()
76
- password_entity.updated_at = datetime.now(timezone.utc)
77
- self.password_repository.update(password_entity)
78
- return password_entity
79
- raise EntityNotFoundException(Password())
48
+
49
+ def execute(self, generator_id: UUID, context: str, text: str) -> Password:
50
+ password_entity: Password = self.password_repository.get_by_context(context)
51
+ if not password_entity:
52
+ raise PasswordNotFoundException()
53
+ generator_entity: Generator = self.generator_repository.get(generator_id)
54
+ password: str = generator_entity.generate_password(text)
55
+ password_entity.text = text
56
+ password_entity.password = password
57
+ password_entity.encrypt()
58
+ self.password_repository.update(password_entity)
59
+ return password_entity
80
60
 
81
61
 
82
62
  class DeletePasswordUseCase:
83
- def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
63
+ def __init__(self, password_repository: PasswordRepository):
84
64
  self.password_repository: PasswordRepository = password_repository
85
- self.user_repository: UserRepository = user_repository
86
65
 
87
- def execute(self, user_id: UUID, password_id: UUID) -> None:
88
- self.password_repository.delete(password_id)
89
- user_entity: User = self.user_repository.find_by_id(user_id)
90
- user_entity.delete_password(password_id)
91
- self.user_repository.update(user_entity)
66
+ def execute(self, context: str) -> None:
67
+ password_entity: Password = self.password_repository.get_by_context(context)
68
+ if not password_entity:
69
+ raise PasswordNotFoundException()
70
+ self.password_repository.delete(password_entity)
92
71
 
93
72
 
94
- class GetAllUserPasswordsUseCase:
95
- def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
73
+ class GetAllPasswordsUseCase:
74
+ def __init__(self, password_repository: PasswordRepository):
96
75
  self.password_repository: PasswordRepository = password_repository
97
- self.user_repository: UserRepository = user_repository
98
76
 
99
- def execute(self, user_id: UUID) -> list[Password]:
100
- user_entity: User = self.user_repository.find_by_id(user_id)
101
- passwords: list[Password] = []
102
- for password_id in user_entity.passwords_ids:
103
- password_entity: Password = self.password_repository.find_by_id(password_id)
104
- passwords.append(password_entity)
105
- return passwords
77
+ def execute(self) -> list[Password]:
78
+ return self.password_repository.list()
106
79
 
107
80
 
108
- class DeleteAllUserPasswordsUseCase:
109
- def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
81
+ class DeleteAllPasswordsUseCase:
82
+ def __init__(self, password_repository: PasswordRepository):
110
83
  self.password_repository: PasswordRepository = password_repository
111
- self.user_repository: UserRepository = user_repository
112
-
113
- def execute(self, user_id: UUID) -> None:
114
- user_entity: User = self.user_repository.find_by_id(user_id)
115
- for password_id in user_entity.passwords_ids:
116
- self.password_repository.delete(password_id)
117
- user_entity.delete_password(password_id)
118
- self.user_repository.update(user_entity)
84
+
85
+ def execute(self) -> None:
86
+ self.password_repository.flush()
@@ -5,22 +5,19 @@ from uuid import UUID, uuid4
5
5
  from cryptography.fernet import Fernet
6
6
 
7
7
  from cipherspy.cipher import *
8
- from cipherspy.cipher.base_cipher import BaseCipherAlgorithm
8
+ from cipherspy.exceptions import InvalidAlgorithmException
9
9
  from cipherspy.utilities import generate_salt, derive_key
10
10
 
11
- from passphera_core import exceptions
12
-
13
11
 
14
12
  @dataclass
15
13
  class Password:
16
14
  id: UUID = field(default_factory=uuid4)
17
- user_id: UUID = field(default_factory=uuid4)
18
- created_at: datetime = field(default=datetime.now(timezone.utc))
19
- updated_at: datetime = field(default=datetime.now(timezone.utc))
15
+ created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
16
+ updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
20
17
  context: str = field(default_factory=str)
21
18
  text: str = field(default_factory=str)
22
19
  password: str = field(default_factory=str)
23
- salt: bytes = field(default_factory=bytes)
20
+ salt: bytes = field(default_factory=lambda: bytes)
24
21
 
25
22
  def encrypt(self) -> None:
26
23
  self.salt = generate_salt()
@@ -33,9 +30,10 @@ class Password:
33
30
 
34
31
 
35
32
  @dataclass
36
- class GeneratorConfig:
33
+ class Generator:
37
34
  id: UUID = field(default_factory=uuid4)
38
- generator_id: UUID = field(default_factory=uuid4)
35
+ created_at: datetime = field(default_factory=datetime.now)
36
+ updated_at: datetime = field(default_factory=datetime.now)
39
37
  shift: int = field(default=3)
40
38
  multiplier: int = field(default=3)
41
39
  key: str = field(default="hill")
@@ -56,7 +54,7 @@ class GeneratorConfig:
56
54
  :return: BaseCipherAlgorithm: The primary algorithm used for the cipher
57
55
  """
58
56
  if self.algorithm.lower() not in self._cipher_registry:
59
- raise exceptions.InvalidAlgorithmException(self.algorithm)
57
+ raise InvalidAlgorithmException(self.algorithm)
60
58
  return self._cipher_registry[self.algorithm.lower()]
61
59
 
62
60
  def replace_character(self, char: str, replacement: str) -> None:
@@ -77,53 +75,24 @@ class GeneratorConfig:
77
75
  """
78
76
  self.characters_replacements.pop(char, None)
79
77
 
80
-
81
- @dataclass
82
- class Generator:
83
- id: UUID = field(default_factory=uuid4)
84
- user_id: UUID = field(default_factory=uuid4)
85
- created_at: datetime = field(default_factory=datetime.now)
86
- updated_at: datetime = field(default_factory=datetime.now)
87
- config_id: UUID = field(default_factory=UUID)
88
- config: GeneratorConfig = field(default_factory=GeneratorConfig)
89
-
90
- def __post_init__(self):
91
- self.config = GeneratorConfig(generator_id=self.id)
92
-
93
78
  def apply_replacements(self, password: str) -> str:
94
79
  """
95
80
  Replace character from the ciphered password with character replacements from the generator configurations
81
+ :param password: The password to perform the action on it
96
82
  :return: str: The new ciphered password after character replacements
97
83
  """
98
- translation_table = str.maketrans(self.config.characters_replacements)
84
+ translation_table: dict[int, str] = str.maketrans(self.characters_replacements)
99
85
  return password.translate(translation_table)
100
86
 
101
87
  def generate_password(self, text: str) -> str:
102
88
  """
103
89
  Generate a strong password string using the raw password (add another layer of encryption to it)
90
+ :param text: The text to generate password from it
104
91
  :return: str: The generated ciphered password
105
92
  """
106
- affine = AffineCipherAlgorithm(self.config.shift, self.config.multiplier)
107
- intermediate = affine.encrypt(f"{self.config.prefix}{text}{self.config.postfix}")
108
- main_algorithm = self.config.get_algorithm()
109
- password = main_algorithm.encrypt(intermediate)
93
+ main_algorithm: BaseCipherAlgorithm = self.get_algorithm()
94
+ secondary_algorithm: AffineCipherAlgorithm = AffineCipherAlgorithm(self.shift, self.multiplier)
95
+ intermediate: str = secondary_algorithm.encrypt(f"{self.prefix}{text}{self.postfix}")
96
+ password: str = main_algorithm.encrypt(intermediate)
110
97
  password = self.apply_replacements(password)
111
98
  return ''.join(c.upper() if c in text else c for c in password)
112
-
113
-
114
- @dataclass
115
- class User:
116
- id: UUID = field(default_factory=uuid4)
117
- created_at: datetime = field(default_factory=datetime.now)
118
- updated_at: datetime = field(default_factory=datetime.now)
119
- username: str = field(default_factory=str)
120
- email: str = field(default_factory=str)
121
- password: str = field(default_factory=str)
122
- generator_id: UUID = field(default_factory=UUID)
123
- passwords_ids: list[UUID] = field(default_factory=list[UUID])
124
-
125
- def add_password(self, password_id: UUID) -> None:
126
- self.passwords_ids.append(password_id)
127
-
128
- def delete_password(self, password_id: UUID) -> None:
129
- self.passwords_ids.remove(password_id)
@@ -1,49 +1,19 @@
1
- from typing import Union, Literal
1
+ from passphera_core.entities import Password
2
2
 
3
- from passphera_core.entities import Password, Generator, User
4
3
 
4
+ class PasswordNotFoundException(Exception):
5
+ def __init__(self) -> None:
6
+ super().__init__("Password not found")
5
7
 
6
- class InvalidAlgorithmException(Exception):
7
- def __init__(self, algorithm: str) -> None:
8
- self.algorithm = algorithm
9
- super().__init__(f"Invalid algorithm: '{algorithm}'")
10
8
 
11
-
12
- class EntityNotFoundException(Exception):
13
- def __init__(self, entity: Union[Password, Generator, User]) -> None:
14
- self.entity = entity
15
- entity_type = entity.__class__.__name__
16
- super().__init__(f"{entity_type} not found")
17
-
18
-
19
- class DuplicateEntityException(Exception):
20
- def __init__(
21
- self,
22
- entity: Union[Password, User],
23
- duplicate_field: Literal['context', 'email', 'username'] = None
24
- ) -> None:
25
- self.entity = entity
26
- self.duplicate_field = duplicate_field
27
- message = self._build_message(entity, duplicate_field)
9
+ class DuplicatePasswordException(Exception):
10
+ def __init__(self, password: Password) -> None:
11
+ self.password = password
12
+ message = self._build_message(password)
28
13
  super().__init__(message)
29
14
 
30
- def _build_message(self, entity: Union[Password, User], duplicate_field: str | None) -> str:
31
- if isinstance(entity, Password):
32
- return self._build_password_message(entity)
33
- elif isinstance(entity, User):
34
- return self._build_user_message(entity, duplicate_field)
35
- return "Duplicate entity detected"
36
-
37
15
  @staticmethod
38
- def _build_password_message(password: Password) -> str:
16
+ def _build_message(password: Password) -> str:
39
17
  if hasattr(password, 'context') and password.context:
40
18
  return f"Password for context '{password.context}' already exists"
41
19
  return "Duplicate password detected"
42
-
43
- @staticmethod
44
- def _build_user_message(user: User, duplicate_field: str) -> str:
45
- if duplicate_field == 'email':
46
- return f"User with email '{user.email}' already exists"
47
- elif duplicate_field == 'username':
48
- return f"User with username '{user.username}' already exists"
49
- return "Duplicate user detected"
@@ -1,7 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from uuid import UUID
3
3
 
4
- from passphera_core.entities import Password, Generator, GeneratorConfig, User
4
+ from passphera_core.entities import Password, Generator
5
5
 
6
6
 
7
7
  class PasswordRepository(ABC):
@@ -10,71 +10,35 @@ class PasswordRepository(ABC):
10
10
  pass
11
11
 
12
12
  @abstractmethod
13
- def update(self, password: Password) -> None:
14
- pass
15
-
16
- @abstractmethod
17
- def delete(self, password_id: UUID) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def find_by_id(self, password_id: UUID) -> Password:
22
- pass
23
-
24
-
25
- class GeneratorRepository(ABC):
26
- @abstractmethod
27
- def save(self, generator: Generator) -> None:
28
- pass
29
-
30
- @abstractmethod
31
- def update(self, generator: Generator) -> None:
13
+ def get_by_context(self, context: str) -> Password:
32
14
  pass
33
15
 
34
16
  @abstractmethod
35
- def find_by_id(self, generator_id: UUID) -> Generator:
36
- pass
37
-
38
- @abstractmethod
39
- def find_by_user_id(self, user_id: UUID) -> Generator:
40
- pass
41
-
42
-
43
- class GeneratorConfigRepository(ABC):
44
- @abstractmethod
45
- def save(self, generator_config: GeneratorConfig) -> None:
46
- pass
47
-
48
- @abstractmethod
49
- def update(self, generator_config: GeneratorConfig) -> None:
17
+ def update(self, password: Password) -> None:
50
18
  pass
51
19
 
52
20
  @abstractmethod
53
- def find_by_id(self, generator_config_id: UUID) -> GeneratorConfig:
21
+ def delete(self, password: Password) -> None:
54
22
  pass
55
23
 
56
24
  @abstractmethod
57
- def find_by_generator_id(self, generator_id: UUID) -> GeneratorConfig:
25
+ def list(self) -> list[Password]:
58
26
  pass
59
27
 
60
-
61
- class UserRepository(ABC):
62
28
  @abstractmethod
63
- def save(self, user: User) -> None:
29
+ def flush(self) -> None:
64
30
  pass
65
31
 
66
- @abstractmethod
67
- def update(self, user: User) -> None:
68
- pass
69
32
 
33
+ class GeneratorRepository(ABC):
70
34
  @abstractmethod
71
- def find_by_id(self, user_id: UUID) -> User:
35
+ def save(self, generator: Generator) -> None:
72
36
  pass
73
37
 
74
38
  @abstractmethod
75
- def find_by_username(self, username: str) -> User:
39
+ def get(self, generator_id: UUID) -> Generator:
76
40
  pass
77
41
 
78
42
  @abstractmethod
79
- def find_by_email(self, email: str) -> User:
43
+ def update(self, generator: Generator) -> None:
80
44
  pass
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: passphera-core
3
- Version: 0.10.0
3
+ Version: 0.11.1
4
4
  Summary: The core system of passphera project
5
5
  Home-page: https://github.com/passphera/core
6
6
  Author: Fathi Abdelmalek
7
7
  Author-email: abdelmalek.fathi.2001@gmail.com
8
- Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Development Status :: 4 - Beta
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python
@@ -0,0 +1,11 @@
1
+ passphera_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ passphera_core/entities.py,sha256=n93z53GfQdiVRekyzRQ-xZQNKhfbA7WvWkUmtK7ZXWA,4241
3
+ passphera_core/exceptions.py,sha256=Xir2lYIH7QYHfjDQu8WJ9qIhCvP-mYcPWYN2LbbbDj8,640
4
+ passphera_core/interfaces.py,sha256=HF4g115Rz1sp9-cRDpdOqkZ1ixhrNg1WI2UNftuEykI,911
5
+ passphera_core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ passphera_core/application/generator.py,sha256=ljbPw3nRy6KOsF0B_zkILJqx2uMcSgT66YKJBHxvDwo,2491
7
+ passphera_core/application/password.py,sha256=Y_XnoTGS6QHeIPHDCvfj8cscaMyDkflYexE8dkLVUW0,3496
8
+ passphera_core-0.11.1.dist-info/METADATA,sha256=ixkf06A0-FBsGpy6HTUT5qxpyx892mQ6VxluK7VREGc,868
9
+ passphera_core-0.11.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ passphera_core-0.11.1.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
11
+ passphera_core-0.11.1.dist-info/RECORD,,
@@ -1,56 +0,0 @@
1
- from uuid import UUID
2
-
3
- from passphera_core.entities import User, Generator
4
- from passphera_core.exceptions import DuplicateEntityException
5
- from passphera_core.interfaces import UserRepository, GeneratorRepository
6
-
7
-
8
- class RegisterUserUseCase:
9
- def __init__(self, user_repository: UserRepository, generator_repository: GeneratorRepository):
10
- self.user_repository: UserRepository = user_repository
11
- self.generator_repository: GeneratorRepository = generator_repository
12
-
13
- def execute(self, user: User) -> User:
14
- if self.user_repository.find_by_email(user.email):
15
- raise DuplicateEntityException(user, 'email')
16
- if self.user_repository.find_by_username(user.username):
17
- raise DuplicateEntityException(user, 'username')
18
- user_entity: User = User(**user.__dict__)
19
- generator_entity: Generator = Generator(user_id=user_entity.id)
20
- self.generator_repository.save(generator_entity)
21
- user_entity.generator_id = generator_entity.id
22
- self.user_repository.save(user_entity)
23
- return user_entity
24
-
25
-
26
- class GetUserByIdUseCase:
27
- def __init__(self, user_repository: UserRepository):
28
- self.user_repository: UserRepository = user_repository
29
-
30
- def execute(self, id: UUID) -> User:
31
- user = self.user_repository.find_by_id(id)
32
- if not user:
33
- raise ValueError(f'User not found')
34
- return user
35
-
36
-
37
- class GetUserByUsernameUseCase:
38
- def __init__(self, user_repository: UserRepository):
39
- self.user_repository = user_repository
40
-
41
- def execute(self, username: str) -> User:
42
- user = self.user_repository.find_by_username(username)
43
- if not user:
44
- raise ValueError(f'User not found')
45
- return user
46
-
47
-
48
- class GetUserByEmailUseCase:
49
- def __init__(self, user_repository: UserRepository):
50
- self.user_repository = user_repository
51
-
52
- def execute(self, email: str) -> User:
53
- user = self.user_repository.find_by_email(email)
54
- if not user:
55
- raise ValueError(f'User not found')
56
- return user
@@ -1,12 +0,0 @@
1
- passphera_core/__init__.py,sha256=0kEfHV5WvMWDoFn1qCeuD52WsgaX4sQ4V9P48cnFKb8,120
2
- passphera_core/entities.py,sha256=vzD6NMA--kUI9DZ39wHCkniRI-bimxMTpE1gh5mzr3k,5180
3
- passphera_core/exceptions.py,sha256=5NvV6LW4Pdok6gRxvM0cN3q6JEKgaCYAX8qGr2eqX2w,1890
4
- passphera_core/interfaces.py,sha256=plI-jQ7cOKFtcL1Dh5UVfmPbJY525h57l44On9BQfac,1782
5
- passphera_core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- passphera_core/application/generator.py,sha256=ABUigLMtP52CHpTKIZmwNb0pgGeL4s_WgrpxLr1M9zw,3896
7
- passphera_core/application/password.py,sha256=osy04J0MD5cZQA47RKH9KqA-P52MB3bWSEr1oirtORM,5533
8
- passphera_core/application/user.py,sha256=yKIDxUi56I__KFhRViiTSxEsakFvssynazr3vHX7vqw,2069
9
- passphera_core-0.10.0.dist-info/METADATA,sha256=4kQXy2_AgAVos1pEZYB_bLEYAKn8Pen68CVmF51__zM,869
10
- passphera_core-0.10.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
11
- passphera_core-0.10.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
12
- passphera_core-0.10.0.dist-info/RECORD,,