-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.py
More file actions
39 lines (27 loc) · 969 Bytes
/
users.py
File metadata and controls
39 lines (27 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Dict, Optional
class UserMeta:
def __init__(self, email: str, name: str):
self.email = email
self.name = name
__id_pwd: Dict[int, str] = {}
__id_user_meta: Dict[int, UserMeta] = {}
def get_user_by_auth(email: str, password: str) -> Optional[UserMeta]:
for (id, user_meta) in __id_user_meta.items():
if user_meta.email == email:
if __id_pwd[id] != password:
return None
return user_meta
return None
def is_email_occupied(email: str) -> bool:
for (_, user_meta) in __id_user_meta.items():
if user_meta.email == email:
return True
return False
def add_user(email: str, name: str, password: str):
if is_email_occupied(email):
raise ValueError("User with this email exists")
id = len(__id_pwd)
__id_pwd[id] = password
__id_user_meta[id] = UserMeta(email, name)
def get_num_of_users():
return len(__id_user_meta)