-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
75 lines (60 loc) · 1.82 KB
/
auth.py
File metadata and controls
75 lines (60 loc) · 1.82 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import utils.input
import users
import actions
session = None
def register(email: str = None):
global session
name = (
utils.input.prompt(
"First Name: ", lambda i: i.isalpha() and len(i) < 16,
"Please use alphabetical decent name."
),
utils.input.prompt(
"Last Name: ", lambda i: i.isalpha() and len(i) < 16,
"Please use alphabetical decent name."
)
)
if email is None:
email = utils.input.prompt_email()
phone = utils.input.prompt(
"Mobile Phone (+20): ", r'^01[0125][0-9]{8}$',
"Please use an Egyptian mobile phone number (ex. 015xxxxxxxx)."
)
password = utils.input.prompt(
"Password: ", r'^[^\f\n]{8,}$',
"The password must be 8 characters."
)
# TODO: review behaviour, may be return to the menu instead?
while input("Confirm Password: ") != password:
print("Passwords don't match.")
try:
users.add(email, password, name, phone)
session = email
print("Registered successfully.")
actions.menu()
except Exception as exception:
print(exception) # TODO: handle better
menu()
def login():
global session
email = utils.input.prompt_email()
password = users.find_password(email)
if password is None:
print("You are not registered, forwarding...")
register(email)
return
attempts = 3
while attempts > 0:
if input("Password: ") == password:
session = email
print("Logged in successfully.")
break
print("Wrong password.")
attempts -= 1
if session is not None:
actions.menu()
else:
menu()
def menu():
print("Authorization:-")
utils.input.select(('Register', register), ('Login', login))