-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·180 lines (148 loc) · 5.29 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
171
172
173
174
175
176
177
178
179
180
from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify, send_file, Response
from login import *
import time, datetime, base64, pytz
from database import *
from markit import *
from qr import *
BASE_DIR = os.path.abspath("../../")
app = Flask(__name__)
flag=True
app.secret_key = os.urandom(24)
try:
@app.route('/')
def home():
return render_template("index.html")
@app.route('/about')
def about():
return render_template("about.html")
@app.route('/connect')
def connect():
return render_template("connect.html")
@app.route('/donate')
def donate():
return render_template("donate.html")
@app.route('/signout')
def signout():
try:
del session['user']
except Exception as e:
print("No Session found")
return redirect("/")
@app.route('/files',methods=['GET', 'POST'])
def files():
try:
if session['user']=='admin':
return render_template('files.html',files=get_file_list(BASE_DIR))
except Exception as e:
print('false login')
return redirect('/')
@app.route('/download/<path:filename>')
def download_file(filename):
try:
if session['user']=='admin':
pass
else:
return 'FUCK YOU!!'
except Exception as e:
return 'FUCK YOU!!'
file_path = os.path.join(BASE_DIR, filename)
if os.path.exists(file_path):
return send_file(file_path, as_attachment=True)
else:
return "File not found", 404
# Function to list files and directories
def get_file_list(directory):
file_list = []
for root, dirs, files in os.walk(directory):
relative_path = os.path.relpath(root, BASE_DIR)
if relative_path == ".":
relative_path = "Root Directory"
file_list.append({'type': 'folder', 'name': relative_path})
for file in files:
file_list.append({'type': 'file', 'name': os.path.join(relative_path, file)})
return file_list
@app.route('/admin',methods=['POST','GET'])
def admin():
try:
if session['user']=='admin':
return render_template('admin.html')
except Exception as e:
print('false login')
return redirect('/')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
email = request.form['username']
password = request.form['password']
if email=='admin' and password=='admin123':
session['user']="admin"
return redirect('admin')
# Validate credentials
elif db_login(email,password):
session['user']=email
flash('Login successful!', 'success')
return redirect(url_for('dashboard'))
else:
flash('Invalid credentials. Try again.', 'danger')
return render_template('login.html')
@app.route('/dashboard')
def dashboard():
return render_template("dashboard.html")
@app.route('/signup',methods=['POST','GET'])
def signup():
if request.method == 'POST':
email = request.form['username']
password = request.form['password']
# Validate credentials
if login_and_save_data(email,password):
session['user']=email
flash('Registration successful!', 'success')
return redirect(url_for('dashboard'))
else:
flash('Invalid credentials. Try again.', 'danger')
return render_template("signup.html")
@app.route('/scan')
def scan():
if flag:
return render_template('scan.html', title="Scan QR Code")
else:
return 'Contact Admin Service Forbidden!!'
@app.route('/')
def index():
return render_template('index.html')
UPLOAD_FOLDER = os.path.abspath(os.path.dirname(__file__)) # Root directory
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
@app.route("/upload", methods=["POST"])
def upload_image():
try:
if session['user']:
pass
else:
return
except Exception as e:
return
if "image" not in request.files:
return "No image file found", 400
ist = pytz.timezone('Asia/Kolkata')
t=datetime.datetime.now(ist).strftime("%Y%m%d%H%M%S")
image = request.files["image"]
t=f"qr_{t}.jpg"
image_path = os.path.join(app.config["UPLOAD_FOLDER"],t)
image.save(image_path)
qr_id=scan_it(t)
sid=get_sid(session['user'],get_pass(session['user']))
testing=mark_attendance(sid,qr_id,get_stu(session['user']))
print(testing)
# if(testing):
l=start_mark(qr_id)
session['qr']=qr_id
session['responsi']=l
flash("Attendance marked!!")
# else:
# session['qr']=qr_id
# session['responsi']=testing
return "Image saved successfully", 200
except Exception as e:
print(e)
if __name__=="__main__":
app.run(debug=False, port=6969, host='0.0.0.0')