-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.py
executable file
·62 lines (45 loc) · 1.29 KB
/
serve.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
import os
from flask import (
Flask,
render_template,
request,
redirect,
session
)
from models import NewUser, LoginUser
from database import create_user, get_user, get_scenarios_for_user
app = Flask(__name__, template_folder='static', static_folder='static')
@app.route("/")
def serve_main_page():
"""Serve the main page"""
return render_template('index.html')
@app.route('/signup', methods=['POST'])
def signup():
form = request.form
new_user = NewUser(form)
uuid = create_user(new_user)
if uuid is None:
return redirect('/')
session['uuid'] = uuid
return redirect('/home')
@app.route('/login', methods=['POST'])
def login():
form = request.form
user = LoginUser(form)
uuids = get_user(user)
if uuids is None or len(uuids) != 1:
return redirect('/')
session['uuid'] = uuids[0]
return redirect('/home')
@app.route('/home')
def home():
uuid = session['uuid']
import pdb
pdb.set_trace()
scenarios = get_scenarios_for_user(uuid)
return render_template('profile.html', scenarios=scenarios)
if __name__ == "__main__":
app.config['SESSION_TYPE'] = 'redis'
app.config['SECRET_KEY'] = 'super secret key'
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)