You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
import os |
|
import random |
|
import string |
|
from flask import current_app, Blueprint, render_template, session, redirect, url_for, request |
|
|
|
from data.document import Document |
|
|
|
bp = Blueprint('admin', __name__, url_prefix='/admin') |
|
|
|
@bp.before_app_request |
|
def authenticate(): |
|
print(request.path) |
|
if request.path == '/admin/login' or request.path.startswith('/doc/') or request.path == '/api/doc/build': |
|
return |
|
|
|
authenticated = session.get('authenticated') |
|
if not authenticated: |
|
return redirect(url_for('admin.login'), code=302) |
|
|
|
@bp.route('/') |
|
def index(): |
|
return render_template("admin/index.html", documents=Document.list()) |
|
|
|
@bp.route('/login', methods=['GET', 'POST']) |
|
def login(): |
|
correct_password = current_app.config['ADMIN_PASSWORD'] |
|
if request.method == 'POST': |
|
password = request.form.get('password') |
|
if password == correct_password: |
|
session.clear() |
|
session['authenticated'] = True |
|
return redirect(url_for('admin.index'), code=302) |
|
else: |
|
raise Exception("Incorrect password") |
|
else: |
|
return render_template("admin/login.html") |