-
Notifications
You must be signed in to change notification settings - Fork 1
/
registration.py
139 lines (112 loc) · 4.29 KB
/
registration.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import database as db
import pages as page
import menus as menu
# -----------------------SIGNUP------------------------------------
# Creates a new user in DB. Made it a separate function so it can be easily changed for future
#regular plan = 1
#plus plan = 2
def create_user(uName, passw, fName, lName, plan):
tmpcon = db.sqlite3.connect('inCollege.db')
tmpcursor = tmpcon.cursor()
tmpcursor.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?)", (fName, lName, uName, passw, plan))
tmpcursor.execute("INSERT INTO settings VALUES (?, ?, ?, ?, ?)", (uName, "ON", "ON", "ON", "English"))
print("succesfully registered")
tmpcon.commit()
tmpcon.close()
# True if username is found, false if not found
def check_for_username(uName): # tested
tmpcon = db.sqlite3.connect('inCollege.db')
tmpcursor = tmpcon.cursor()
curs = tmpcursor.execute("SELECT * FROM users WHERE username = ?", (uName,))
if str(curs.fetchone()) == "None":
tmpcon.close()
return False
else:
tmpcon.close()
return True
# True if space, false if no space for users
def space_for_signup(): # tested
tmpcon = db.sqlite3.connect('inCollege.db')
tmpcursor = tmpcon.cursor()
curs = tmpcursor.execute('SELECT * FROM users;')
if len(curs.fetchall()) < 10:
tmpcon.close()
return True
else:
tmpcon.close()
return False
# checks is password is correct
def is_good_password(pw): # tested
has_capital = False
has_number = False
has_non_alphanum = False
if len(pw) < 8 or len(pw) > 12:
return False
for char in pw:
if char.isnumeric():
has_number = True
if not (char.isalnum()):
has_non_alphanum = True
if char.isupper():
has_capital = True
if has_number and has_capital and has_non_alphanum:
return True
else:
return False
def signup():
# check for space
if not space_for_signup():
print("\nUser limit exceeded")
# goTo homepage
page.homepage()
print("Default settings:\nInCollege Email -> ON"
"\nSMS -> ON"
"\nTargeted Advertising -> ON"
"\nLanguage -> English"
"\n If you wish to change it, please log in and modify in privacy Policy")
# enter input
firstName = input("\n\nEnter first name: ")
lastName = input("\nEnter last name: ")
username = input("\nEnter Username: ")
if check_for_username(username):
print("Account with this username already exists!")
signup() # added pagesVisited parameter here
password = input("\nEnter Password: ")
if not is_good_password(password):
while not is_good_password(password):
password = input("\nPassword must contain each of the following: "
"\nan uppercase letter, a non-alphanumeric character, and a number."
"\nPlease re-enter: ")
#standard or plus option
print("Select a plan. The standard plan is free. The Plus plan is $10/month\n"
"1. standard\n"
"2. plus\n")
plan = menu.user_input(2)
create_user(username, password, firstName, lastName, plan)
# goTo homepage
page.homepage()
# ---------------------------------LOGIN------------------------------------------------------------
# True if username and password for account is found, false if not found
def check_for_account(uName, password): # tested
tmpcon = db.sqlite3.connect('inCollege.db')
tmpcursor = tmpcon.cursor()
curs = tmpcursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (uName, password))
if str(curs.fetchone()) == "None":
tmpcon.close()
return False
else:
tmpcon.close()
return True
def login():
global username
# set the flag of log in to true
username = input("\nEnter Username: ")
password = input("\nEnter Password: ")
if check_for_account(username, password):
# goToMainPage
page.mainPage()
else:
# allow user to ask to go back
print("Invalid username or password. Please reenter!")
login()
# goback option