Add real page templates and home and logout pages
This commit is contained in:
parent
fcaa68850e
commit
ede475f910
@ -3,6 +3,7 @@
|
||||
"address": "127.0.0.1",
|
||||
"port": "5000",
|
||||
"lexicon_data": "./lexicon",
|
||||
"static_root": "./static",
|
||||
"logging": {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
|
119
amanuensis/resources/page.css
Normal file
119
amanuensis/resources/page.css
Normal file
@ -0,0 +1,119 @@
|
||||
body {
|
||||
background-color: #eeeeee;
|
||||
line-height: 1.4;
|
||||
font-size: 16px;
|
||||
}
|
||||
div#wrapper {
|
||||
max-width: 800px;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 0 auto;
|
||||
}
|
||||
div#header {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
background-color: #ffffff;
|
||||
box-shadow: 2px 2px 10px #888888;
|
||||
border-radius: 5px;
|
||||
}
|
||||
div#header p, div#header h2 {
|
||||
margin: 5px;
|
||||
}
|
||||
div#sidebar {
|
||||
width: 200px;
|
||||
float:left;
|
||||
margin:5px;
|
||||
padding: 8px;
|
||||
text-align: center;
|
||||
background-color: #ffffff;
|
||||
box-shadow: 2px 2px 10px #888888;
|
||||
border-radius: 5px;
|
||||
}
|
||||
img#logo {
|
||||
max-width: 200px;
|
||||
}
|
||||
table {
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
}
|
||||
div#sidebar table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
div.citeblock table td:first-child + td a {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
div.misclinks table td a {
|
||||
justify-content: center;
|
||||
}
|
||||
table a {
|
||||
display: flex;
|
||||
padding: 3px;
|
||||
background-color: #dddddd;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
}
|
||||
div#sidebar table a {
|
||||
justify-content: center;
|
||||
}
|
||||
table a:hover {
|
||||
background-color: #cccccc;
|
||||
}
|
||||
div#sidebar table td {
|
||||
padding: 0px; margin: 3px 0;
|
||||
border-bottom: 8px solid transparent;
|
||||
}
|
||||
div#content {
|
||||
margin: 5px;
|
||||
}
|
||||
div.content-2col {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
left: 226px;
|
||||
max-width: 564px;
|
||||
}
|
||||
div.contentblock {
|
||||
background-color: #ffffff;
|
||||
box-shadow: 2px 2px 10px #888888;
|
||||
margin-bottom: 5px;
|
||||
padding: 10px;
|
||||
width: auto;
|
||||
border-radius: 5px;
|
||||
}
|
||||
div.contentblock h3 {
|
||||
margin: 0.3em 0;
|
||||
}
|
||||
a.phantom {
|
||||
color: #cc2200;
|
||||
}
|
||||
div.citeblock a.phantom {
|
||||
font-style: italic;
|
||||
}
|
||||
span.signature {
|
||||
text-align: right;
|
||||
}
|
||||
@media only screen and (max-width: 816px) {
|
||||
div#wrapper {
|
||||
padding: 5px;
|
||||
}
|
||||
div#header {
|
||||
max-width: 554;
|
||||
margin: 0 auto;
|
||||
}
|
||||
div#sidebar {
|
||||
max-width: 548;
|
||||
width: inherit;
|
||||
float: inherit;
|
||||
margin: 5px auto;
|
||||
}
|
||||
div#content {
|
||||
max-width: 564px;
|
||||
position: static;
|
||||
right: inherit;
|
||||
margin: 5px auto;
|
||||
}
|
||||
img#logo {
|
||||
max-width: inherit;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
@ -1,12 +1,24 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask_login import LoginManager
|
||||
|
||||
import config
|
||||
from server.auth import get_bp as get_auth_bp
|
||||
from server.home import get_bp as get_home_bp
|
||||
|
||||
app = Flask(__name__, template_folder="../templates")
|
||||
# Flask app init
|
||||
static_root = os.path.abspath(config.get("static_root"))
|
||||
app = Flask(__name__, template_folder="../templates", static_folder=static_root)
|
||||
app.secret_key = bytes.fromhex(config.get('secret_key'))
|
||||
|
||||
# Flask-Login init
|
||||
login = LoginManager(app)
|
||||
login.login_view = 'auth.login'
|
||||
|
||||
# Blueprint inits
|
||||
auth_bp = get_auth_bp(login)
|
||||
app.register_blueprint(auth_bp)
|
||||
|
||||
home_bp = get_home_bp()
|
||||
app.register_blueprint(home_bp)
|
||||
|
@ -1,8 +1,8 @@
|
||||
import flask
|
||||
from flask import Blueprint, render_template, redirect, url_for
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||||
from wtforms.validators import DataRequired
|
||||
from flask_login import current_user, login_user
|
||||
from flask_login import current_user, login_user, logout_user, login_required
|
||||
|
||||
import config
|
||||
import user
|
||||
@ -15,7 +15,7 @@ class LoginForm(FlaskForm):
|
||||
|
||||
def get_bp(login_manager):
|
||||
"""Create a blueprint for the auth functions"""
|
||||
bp = flask.Blueprint('auth', __name__, url_prefix='/auth')
|
||||
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(uid):
|
||||
@ -35,6 +35,12 @@ def get_bp(login_manager):
|
||||
name = u.get('username')
|
||||
else:
|
||||
name = "guest"
|
||||
return flask.render_template('auth/login.html', form=form, username=name)
|
||||
return render_template('auth/login.html', form=form, username=name)
|
||||
|
||||
@bp.route("/logout/", methods=['GET'])
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
return bp
|
||||
|
18
amanuensis/server/home.py
Normal file
18
amanuensis/server/home.py
Normal file
@ -0,0 +1,18 @@
|
||||
from flask import Blueprint, render_template, url_for
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
import config
|
||||
import user
|
||||
|
||||
def get_bp():
|
||||
"""Create a blueprint for pages outside of a specific lexicon"""
|
||||
bp = Blueprint('home', __name__, url_prefix='/home')
|
||||
|
||||
@bp.route('/', methods=['GET'])
|
||||
@login_required
|
||||
def home():
|
||||
return render_template(
|
||||
'home/home.html',
|
||||
sidebar_rows=[current_user.get('username'), current_user.get('displayname'), current_user.uid])
|
||||
|
||||
return bp
|
@ -1,12 +1,11 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<h1>Hello, {{username}}</h1>
|
||||
{% if current_user.is_authenticated %}{{ current_user.get('displayname') }}{% endif %}
|
||||
{% extends "page_1col.html" %}
|
||||
{% block title %}Login | Amanuensis{% endblock %}
|
||||
{% block header %}<h2>Login</h2>{% endblock %}
|
||||
{% block primary_content %}
|
||||
<h1>Log in</h1>
|
||||
<form action="" method="post" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<p>{{ form.username.label }}<br>{{ form.username(size=32) }}</p>
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
{% endblock %}
|
7
amanuensis/templates/home/home.html
Normal file
7
amanuensis/templates/home/home.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "page_2col.html" %}
|
||||
{% block title %}Home | Amanuensis{% endblock %}
|
||||
{% block header %}<h2>Amanuensis</h2>{% endblock %}
|
||||
{% block primary_content %}
|
||||
<p><a href="{{ url_for('home.home') }}">Home</a></p>
|
||||
<p><a href="{{ url_for('auth.logout') }}">Logout</a></p>
|
||||
{% endblock %}
|
22
amanuensis/templates/page.html
Normal file
22
amanuensis/templates/page.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename="page.css") }}">
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<div id="header">{% block header %}{% endblock %}</div>
|
||||
{% block sidebar %}{% endblock %}
|
||||
<div id="content" class="{% block content_class %}{% endblock %}">
|
||||
<div class="contentblock">
|
||||
{% block primary_content %}{% endblock %}</div>{% for content_block in additional_content %}
|
||||
<div class="contentblock">
|
||||
{{ content_block|safe }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
3
amanuensis/templates/page_1col.html
Normal file
3
amanuensis/templates/page_1col.html
Normal file
@ -0,0 +1,3 @@
|
||||
{% extends "page.html" %}
|
||||
{% block sidebar %}{% endblock %}
|
||||
{% block content_class %}content-1col{% endblock %}
|
8
amanuensis/templates/page_2col.html
Normal file
8
amanuensis/templates/page_2col.html
Normal file
@ -0,0 +1,8 @@
|
||||
{% extends "page.html" %}
|
||||
{% block sidebar %}<div id="sidebar">
|
||||
<table>{% for row in sidebar_rows %}
|
||||
<tr><td>{{ row|safe }}</td></tr>{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block content_class %}content-2col{% endblock %}
|
Loading…
Reference in New Issue
Block a user