forked from divya-rathi/CAMs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
119 lines (105 loc) · 3.85 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
from flask import Flask
from flask import * #Flask, flash, redirect, render_template, request, session, abort
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)
@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():
if request.method == 'POST':
temp = -1
username = request.form['uname']
print(username)
password = request.form['pass']
print(password)
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
return render_template('home_admin.html', u = active)
else:
return render_template('home.html', u = active, cf = cutoff)
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():
if request.method == 'POST':
choose = request.form['tab']
if choose == 'Add College Details':
print('works')
if choose == 'Register Students':
print('works')
if choose == 'View Selected Students List':
print('works')
if choose == 'Add Cut-Offs List':
print('works')
@app.route('/application',methods=['POST', 'GET'])
def application():
return render_template('application.html')
@app.route('/dashboard',methods=['POST', 'GET'])
def dashboard():
global active
return render_template('student_dashboard.html', u= active)
@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)