-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
82 lines (54 loc) · 1.67 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
from flask import Flask, render_template, url_for, session, request, redirect
import flask_login
from home import home
from transcribe import transcribe
from review import review
from librarian import librarian
from tutorial import tutorial
from thanks import thanks
from citation import citation
from os import environ
# Enter Login Credentials:
# users = {'USERNAME': {'psw': 'PASSWORD'}}
username = environ.get("LIBRARIAN_USERNAME")
password = environ.get("LIBRARIAN_PASSWORD")
users = {username: {'psw': password}}
app = Flask(__name__)
app.secret_key = environ.get("APP_SECRET_KEY")
login_manager = flask_login.LoginManager()
login_manager.init_app(app)
class User(flask_login.UserMixin):
pass
@login_manager.user_loader
def user_loader(uname):
if uname not in users:
return
user = User()
user.id = uname
return user
@login_manager.request_loader
def request_loader(request):
uname = request.form.get('uname')
if uname not in users:
return
user = User()
user.id = uname
return user
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
uname = request.form['uname']
if request.form['psw'] == users[uname]['psw']:
user = User()
user.id = uname
flask_login.login_user(user)
return redirect(url_for('librarian.librarian_page'))
return 'Bad login, please refresh to try again.'
app.register_blueprint(librarian)
app.register_blueprint(home)
app.register_blueprint(transcribe)
app.register_blueprint(review)
app.register_blueprint(tutorial)
app.register_blueprint(thanks)
app.register_blueprint(citation)