-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
87 lines (66 loc) · 2.41 KB
/
Copy pathapp.py
File metadata and controls
87 lines (66 loc) · 2.41 KB
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
from flask import Flask, redirect, render_template, request, session, send_from_directory, flash, url_for
from Server.randomstring import genString
from Server.JSONParser import makeQuestionnaire
import os
import shutil
from datetime import timedelta
from threading import Timer
app = Flask(__name__)
app.secret_key = os.environ.get('Flask_Secret_key')
list_of_Users = ['testusername260704Rishit']
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=2)
def deleteuser(id):
list_of_Users.remove(id)
os.rmtree(f'Users/{id}')
@app.route("/")
def main():
return redirect("/home")
@app.route("/home")
def home():
return render_template("Homepage.html")
@app.route('/feedback')
def feedback():
return render_template('feedback.html')
@app.route('/docs')
def docs():
return render_template('docs.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route("/new-questionnaire", methods = ['POST'])
def newRoom():
id = request.form.get('Username')
if id in list_of_Users:
flash('Please Enter Another Username\nWhat are the Chances!\nSomeone else is using that username')
return redirect(url_for('.home'))
if len(id) < 5:
flash('Whoops! Please enter an username at least 5 characters long.')
return redirect(url_for('.home'))
if len(id) > 20:
flash('Whoops! Please enter an username within 20 characters.')
return redirect(url_for('.home'))
session["id"] = id
session.permanent = True
if not os.path.isdir(f"users/{id}"):
os.mkdir(f"users/{id}")
list_of_Users.append(id)
t = Timer(2*3600, deleteuser, args=[session['id']])
t.start()
session["path"] = f'Users/{id}'
print(f"NEW USER: {id},\nPATH: {session['path']}")
shutil.copytree('HTML MAPPER', session["path"], dirs_exist_ok=True)
return render_template('main.html')
@app.route("/process-questionnaire", methods=['POST'])
def processQuestionnaire():
try:
data = request.form['data']
makeQuestionnaire(data)
return render_template("DownloadReady.html", path = session["path"])
# return render_template("DownloadReady.html", path = 'Users/RishitChakraborty')
except Exception as e:
return str(e)
@app.route('/Users/<path:filename>')
def serve_user_file(filename):
return send_from_directory('Users', filename)
if __name__=="__main__":
app.run(debug=True)