aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/__init__.py9
-rw-r--r--apioforum/auth.py10
-rw-r--r--apioforum/templates/auth/login.html7
-rw-r--r--apioforum/templates/auth/register.html7
-rw-r--r--apioforum/templates/err/403.html8
-rw-r--r--apioforum/templates/err/404.html8
6 files changed, 43 insertions, 6 deletions
diff --git a/apioforum/__init__.py b/apioforum/__init__.py
index 60777fb..86e5ff9 100644
--- a/apioforum/__init__.py
+++ b/apioforum/__init__.py
@@ -1,7 +1,7 @@
# boilerplate boilerplate boilerplate
# yay
-from flask import Flask, request
+from flask import Flask, request, session, render_template
from .db import get_db
import os
@@ -66,6 +66,13 @@ def create_app():
def md_render(s):
return render(s)
+ @app.errorhandler(404)
+ def not_found(e):
+ return render_template('err/404.html'), 404
+ @app.errorhandler(403)
+ def forbidden(e):
+ return render_template('err/403.html'), 403
+
app.add_url_rule("/",endpoint="index")
return app
diff --git a/apioforum/auth.py b/apioforum/auth.py
index 39cf1f8..8864fc0 100644
--- a/apioforum/auth.py
+++ b/apioforum/auth.py
@@ -31,6 +31,9 @@ def login():
if err is None:
session.clear()
session['user'] = username
+ if 'keep_logged_in' in request.form:
+ session['keep_logged_in']=True
+ session.permanent = True
flash("logged in successfully")
return redirect(get_next())
@@ -65,8 +68,11 @@ def register():
(username,generate_password_hash(password))
)
db.commit()
- flash("successfully created account")
session['user'] = username
+ if 'keep_logged_in' in request.form:
+ session['keep_logged_in'] = True
+ session.permanent = True
+ flash("successfully created account")
return redirect(get_next())
flash(err)
@@ -82,6 +88,8 @@ def logout():
@bp.before_app_request
def load_user():
username = session.get("user")
+ if session.get("keep_logged_in",False):
+ session.permanent = True
if username is None:
g.user = None
g.user_info = None
diff --git a/apioforum/templates/auth/login.html b/apioforum/templates/auth/login.html
index 3e69134..89f490f 100644
--- a/apioforum/templates/auth/login.html
+++ b/apioforum/templates/auth/login.html
@@ -6,12 +6,15 @@
{% block content %}
<p>log in using an existing account here. if you don't already have an account, <a href="{{url_for('auth.register')}}">register</a> first instead.</p>
<form method="post">
- <label for="username">Username</label>
+ <label for="username">username</label>
<input name="username" id="username" required>
<br>
- <label for="password">Password</label>
+ <label for="password">password</label>
<input type="password" name="password" id="password" required>
<br>
+ <input type="checkbox" name="keep_logged_in" id="keep_logged_in">
+ <label for="keep_logged_in">keep me logged in</label>
+ <br>
<input type="submit" value="login">
</form>
{% endblock %}
diff --git a/apioforum/templates/auth/register.html b/apioforum/templates/auth/register.html
index 5d27b90..082a95b 100644
--- a/apioforum/templates/auth/register.html
+++ b/apioforum/templates/auth/register.html
@@ -6,12 +6,15 @@
{% block content %}
<p>create a new account here. if you already have an account, <a href="{{url_for('auth.login')}}">login</a> instead.</p>
<form method="post">
- <label for="username">Username</label>
+ <label for="username">username</label>
<input name="username" id="username" maxlength="20" required>
<br>
- <label for="password">Password</label>
+ <label for="password">password</label>
<input type="password" name="password" id="password" required>
<br>
+ <input type="checkbox" name="keep_logged_in" id="keep_logged_in">
+ <label for="keep_logged_in">keep me logged in</label>
+ <br>
<input type="submit" value="register">
</form>
{% endblock %}
diff --git a/apioforum/templates/err/403.html b/apioforum/templates/err/403.html
new file mode 100644
index 0000000..bae6857
--- /dev/null
+++ b/apioforum/templates/err/403.html
@@ -0,0 +1,8 @@
+{% extends 'base.html' %}
+{% block header %}
+<h1>{% block title %}403 forbidden{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<p>you don't have permission to access the requested page</p>
+{% endblock %}
diff --git a/apioforum/templates/err/404.html b/apioforum/templates/err/404.html
new file mode 100644
index 0000000..5b0030e
--- /dev/null
+++ b/apioforum/templates/err/404.html
@@ -0,0 +1,8 @@
+{% extends 'base.html' %}
+{% block header %}
+<h1>{% block title %}404 not found{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<p>the requested url was not found on the server. if you entered the url manually please check your spelling and try again</p>
+{% endblock %}