-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
119 lines (101 loc) · 3.15 KB
/
run.py
File metadata and controls
119 lines (101 loc) · 3.15 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from datetime import datetime
users_list = [
{
"userid":0,
"username":'admin',
"password":'admin',
"role":'admin'
}
]
comments = [
{
}
]
user = []
class Auth():
def __init__(self):
pass
def signup(self):
"""user register
Keyword Arguments:
role {user} -- [all users registereing will automatically be users] (default: {'user'})
Returns:
[message] -- [successful registered]
"""
print('Enter your username')
username = input()
self.username = username
name = [name for name in users_list if name['username'] == self.username]
if name:
return 'User already exist'
print('Enter your password')
password = input()
self.password = password
print('Please Password again')
confirm = input()
self.confirm = confirm
if self.password != self.confirm:
print('Passwords should match')
print("PLease try agAIN")
return self.signup()
self.role = 'user'
user_dict = {
"userid": len(users_list) + 1,
"username":self.username,
"password":self.password,
"role":self.role
}
users_list.append(user_dict)
print("Successsfully registered in")
return True
def login(self):
"""user login
Arguments:
username {nic} -- [unique username]
password {nicki} -- [secret key to account]
Returns:
success message
"""
print('Enter your username')
username= input()
self.username = username
print('Enter your password')
password = input()
self.password = password
self.timestamp = datetime.now()
passw = [passw for passw in users_list if passw['password'] == self.password
and passw['username'] == self.username]
if not passw:
print( 'Error logging in, check your credentials, try again')
return self.login()
self.logged_in_status = True
user.append(self.username)
print("logged in at {}".format(self.timestamp))
return True
def logout(self):
if self.logged_in_status:
self.logged_in_status = False
return 'Successfully logged out'
print("Please log in first")
return self.login()
return True
class Comment():
def create_comment(self):
self.added_by = user
print("Write your comment")
comment = input()
self.comment = comment
print("Your comment is {} and your name is {}".format(self.comment, user[0]))
a = Auth()
if a.signup():
print("Now log in")
if a.login():
print("Dear user what do you want do?")
print("Enter c to comment or l to logout")
resp = input()
if resp == 'c':
b = Comment()
b.create_comment()
if resp == 'l':
a.logout()
print("Sorry, invalid input,,quitting now")