-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.py
73 lines (50 loc) · 2.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
from flask import Flask, redirect, render_template, request, session, url_for
from flask_sqlalchemy import SQLAlchemy
from crewverve.data import get_user_by_name
from crewverve.middleware import authenticate_handler
from crewverve.views import crewverve_bp
from crewverve.models import init_app
from admin.views import admin_bp
app = Flask(__name__)
# The SECRET_KEY is used to encrypt session data in (persistent) cookies.
# >>> import secrets; secrets.token_hex(32)
app.config['SECRET_KEY'] = '642918690903c342d812d16cd33a4de4c8692483462550c9ddcd4303621cc1b2'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///crewverve.db'
# app.config['EXPLAIN_TEMPLATE_LOADING'] = True
db = init_app(app)
app.register_blueprint(crewverve_bp)
app.register_blueprint(admin_bp)
app.app_context().push()
db.create_all()
@app.before_request
def before_request():
return authenticate_handler(None)
@app.route('/login', methods=['GET', 'POST'])
def login():
#------V01 Paloma-----------------------------------------------
error = None
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
user = get_user_by_name(username)
if user is None or not user.check_password(password):
error = 'Invalid username or password'
else:
# Note: Flask session. NOT SqlAlchemy...
session['CURRENT_USER'] = username
return redirect(url_for('crewverve.index'))
return render_template('login.html', error=error)
#------V01 Paloma-----------------------------------------------
@app.route('/logout', methods=['GET'])
def logout():
# Note: Flask session. NOT SqlAlchemy...
del session['CURRENT_USER']
return redirect(url_for('login'))
@app.route('/')
def index():
return redirect(url_for('crewverve.index'))
@app.route('/page-not-found')
def page_not_found():
return render_template('error.html', error_message="Page not found", error_description="This isn't the page you are looking for....")
if __name__ == '__main__':
app.run(debug=True)