forked from divya-rathi/CAMs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
170 lines (151 loc) · 6.07 KB
/
app.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import firebase as firebase
from flask import *
import os
import pyrebase
config = {
"apiKey" : "AIzaSyAIsSHOuNkfoGuUrJ5xQM2t6jNVT5TlHx8",
"authDomain" : "cams-da440.firebaseapp.com",
"databaseURL" : "https://cams-da440.firebaseio.com",
"projectId" : "cams-da440",
"storageBucket" : "cams-da440.appspot.com",
"messagingSenderId" : "592415369968"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
app = Flask(__name__)
global active,credentials
active = None
#Firebase
from firebase import firebase
firebase = firebase.FirebaseApplication('https://cams-da440.firebaseio.com/', None)
credentials = firebase.get('/credentials', None)
cutoff = firebase.get('/Cutoff', None)
applications = firebase.get('/application', None)
@app.route('/', methods=['POST', 'GET'])
def home():
global active
return render_template('home.html', u= active, cf = cutoff)
@app.route('/login', methods=['POST', 'GET'])
def login():
credentials = firebase.get('/credentials', None)
if request.method == 'POST':
temp = -1
username = request.form['uname']
password = request.form['pass']
for i in credentials:
if username in credentials[i]['EmailId'] and password in credentials[i]['Password']:
temp += 1
print("Yes")
session['logged_in'] = True
global active
active = username
if active == 'admin@gmail.com': ##admin
applications = firebase.get('/application', None)
return render_template('home_admin.html', u = active, cutoff = cutoff, form = applications)
else:
print("logged")
return redirect("/")
if temp == -1:
return render_template('login.html', msg = "Invalid Credentials")
else:
return render_template('login.html')
@app.route('/register',methods=['POST', 'GET'])
def register():
if request.method =='POST':
username = request.form['uname']
password = request.form['pass'] ## DO IT here
for i in credentials:
if username in credentials[i]['EmailId']:
flash('User with this email already exits :/ ')
return render_template('register.html')
else:
lenOfCred = len(credentials)
userId = "CAMS"
if lenOfCred <= 9:
k = "000" +str(lenOfCred)
elif lenOfCred >= 10 and lenOfCred <= 99:
k = "00" +str(lenOfCred)
elif lenOfCred >=100 and lenOfCred <= 999:
k = "0" + str(lenOfCred)
db.child("credentials").child(userId + k).set({"EmailId": username, "Password": password})
global crendentials
crendentials = firebase.get('/credentials', None)
flash('Successfully Registered:) Go ahead and login')
return render_template('register.html')
return render_template('register.html')
@app.route('/home_admin',methods=['POST','GET'])
def home_admin():
global active
if request.method == 'POST':
choose = request.form['tab']
if choose == 'Add College Details':
print('works')
if choose == 'View & Register Students':
print('works')
if choose == 'Create CutOff List':
print('works')
if choose == 'View Final Selected Students':
print('works')
return render_template('home_admin.html')
@app.route('/removeStud/<string:d_id>',methods=['POST','GET'])
def removeStud(d_id):
#print(d_id)
db.child("application").child(d_id).update({'Status': 'Rejected'})
applications = firebase.get('/application', None)
cutoff = firebase.get('/Cutoff', None)
return render_template('home_admin.html', u = active, cutoff = cutoff, form = applications)
@app.route('/addStud/<string:d_id>',methods=['POST','GET'])
def addStud(d_id):
#print(d_id)
db.child("application").child(d_id).update({'Status': 'Accepted'})
applications = firebase.get('/application', None)
cutoff = firebase.get('/Cutoff', None)
return render_template('home_admin.html', u = active, cutoff = cutoff, form = applications)
@app.route('/application',methods=['POST', 'GET'])
def application():
global active
cutoff = firebase.get('/Cutoff', None)
credentials = firebase.get('/credentials', None)
if active != None:
for i in credentials:
if active in credentials[i]['EmailId']:
idno = i
break
applications = firebase.get('/application', None)
if applications != None:
for i in applications:
if i == idno:
return render_template('congrats.html')
if request.method == 'POST':
username = request.form['studname']
perc12 = request.form['studPerc']
branch = request.form.get("branch", None)
db.child("application").child(idno).set({"EmailId":active , "Name":username, "12thPercentage": perc12, "BranchChosen": branch})
return render_template('congrats.html')
return render_template('application.html', emailId = active, stream = cutoff)
return render_template('login.html')
@app.route('/dashboard',methods=['POST', 'GET'])
def dashboard():
cutoff = firebase.get('/Cutoff', None)
applications = firebase.get('/application', None)
credentials = firebase.get('/credentials', None)
global active
if active == 'admin@gmail.com': ##admin
return render_template('home_admin.html', u = active, cutoff = cutoff, form = applications)
return render_template('student_dashboard.html', u= active, cid = credentials, form = applications)
@app.route('/circulars',methods=['POST', 'GET'])
def circulars():
return render_template("circulars.html")
@app.route('/error')
def err():
flash("Wrong password entered")
return home()
@app.route("/logout")
def logout():
session['logged_in'] = False
global active
active = None
return home()
if __name__ == "__main__":
app.secret_key = os.urandom(12)
app.run(debug=True)