forked from ankita-and-rohit/StudentPortal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniversityPortal.py
141 lines (119 loc) · 4.52 KB
/
UniversityPortal.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
140
141
from pickle import NONE
from flask import Flask, redirect, render_template, request, redirect, url_for
import sqlite3
app = Flask(__name__)
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
def db_con():
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
def init():
cur.execute("""CREATE TABLE IF NOT EXISTS accounts (
id integer primary key,
email text,
pass text);""")
def check_duplicate(email):
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
query = f"SELECT * FROM Student WHERE email='{email}';"
conn.row_factory = sqlite3.Row
cur.execute(query)
data = cur.fetchall()
if(data):
return True
else:
return False
def add_account(fname, mname, lname, dob, phone, gender, home, email, pwd, program):
try:
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
cur.execute("INSERT INTO Student (Program_ID, First_Name, Middle_Name, Last_Name, Date_Of_Birth, Home_Address, Email, Password, Phone, Gender) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(program, fname, mname, lname, dob, home, email, pwd, phone, gender))
conn.commit()
except:
print("Error!")
def delete_user(id):
try:
db_con()
cur.execute("DELETE FROM accounts WHERE id = " + str(id))
conn.commit()
except:
pass
def fetchAllUsers():
db_con()
conn.row_factory = sqlite3.Row
cur.execute("SELECT * FROM users")
datas = cur.fetchall()
return datas
#init()
#add_account("paulaldrichnievas@gmail.com", "pass123")
#delete_user(1)
#add_account("Paul", "Ramisan", "Nievas", "2022-5-4", "669-274-6179", "Male", "123, 9543, CA", "abc@gmail.com", "asd", 1)
@app.route('/')
def index():
return render_template("login.html")
@app.route('/login', methods=['GET', 'POST'])
def login():
error=None
if request.method == 'POST':
email = request.form['email']
password = request.form['pwd']
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
query = f"SELECT * FROM Student WHERE Email='{email}' AND Password='{password}';"
conn.row_factory = sqlite3.Row
cur.execute(query)
info = cur.fetchone()
if(info):
print((info))
return render_template("dashboard.html", info=info)
else:
error = "Invalid credentials!"
return render_template("login.html", error=error)
@app.route('/applynow/', defaults={'msg':None, 'error':None})
@app.route('/applynow/<msg>/<error>')
def applynow(msg, error):
conn = sqlite3.connect('UniversityPortal.db')
cur = conn.cursor()
cur.execute("SELECT * FROM Program")
programs = cur.fetchall()
return render_template("register.html",programs=programs, msg=msg, error=error)
@app.route('/apply', methods=['GET', 'POST'])
def apply():
msg=None
if request.method == 'POST':
#Name
fname = request.form['fname']
mname = request.form['mname']
lname = request.form['lname']
#DOB-Phone-Gender
dob = request.form['dob']
phone = request.form['phone']
gender = request.form['gender']
#Home Address
street = request.form['street']
city = request.form['city']
state = request.form['state']
zip = request.form['zip']
country = request.form['country']
home = street +", "+ city +", "+state+" "+zip+", "+country
#Email-Password
email = request.form['email']
pwd = request.form['pwd']
cpwd = request.form['cpwd']
#Program
program = request.form['program']
if(not check_duplicate(email)):
if pwd != cpwd:
msg = "Password do not matched! Please try again."
return redirect(url_for("applynow", msg=msg, error='True'))
else:
add_account(fname, mname, lname, dob, phone, gender, home, email, pwd, program)
msg = "Account has been registered successfully!"
return redirect(url_for("applynow", msg=msg, error='False'))
else:
msg = "Account already exist!"
return redirect(url_for("applynow", msg=msg, error='True'))
if __name__ == '__main__':
app.run(debug=True)