diff --git a/amanuensis/lexicon/manage.py b/amanuensis/lexicon/manage.py index e927578..64b3abf 100644 --- a/amanuensis/lexicon/manage.py +++ b/amanuensis/lexicon/manage.py @@ -116,6 +116,16 @@ def get_all_lexicons(): return lexes +def get_user_lexicons(user): + """ + Loads each lexicon that the given user is a player in + """ + return [ + lexicon + for lexicon in get_all_lexicons() + if user.id in lexicon.join.joined] + + def valid_add(lex, player, password=None): """ Checks whether the given player can join a lexicon diff --git a/amanuensis/server/home.py b/amanuensis/server/home.py index b904252..728f6cf 100644 --- a/amanuensis/server/home.py +++ b/amanuensis/server/home.py @@ -1,9 +1,9 @@ from flask import Blueprint, render_template, redirect, url_for -from flask_login import login_required +from flask_login import login_required, current_user from amanuensis.config import json_ro, json_rw from amanuensis.lexicon import LexiconModel -from amanuensis.lexicon.manage import create_lexicon +from amanuensis.lexicon.manage import create_lexicon, get_user_lexicons from amanuensis.server.forms import LexiconCreateForm from amanuensis.server.helpers import admin_required from amanuensis.user import UserModel @@ -15,7 +15,10 @@ def get_bp(): @bp.route('/', methods=['GET']) def home(): - return render_template('home/home.html') + lexicons = [] + if current_user.is_authenticated: + lexicons = get_user_lexicons(current_user) + return render_template('home/home.html', lexicons=lexicons) @bp.route('/admin/', methods=['GET']) @login_required diff --git a/amanuensis/templates/home/home.html b/amanuensis/templates/home/home.html index 5b2b82f..ee4f172 100644 --- a/amanuensis/templates/home/home.html +++ b/amanuensis/templates/home/home.html @@ -12,7 +12,6 @@ {% endfor %} {% if current_user.is_authenticated %} -{% set lexicons = current_user.lexicons_in() %}

Your games

{% if lexicons %} {% for lexicon in lexicons %} diff --git a/amanuensis/templates/lexicon/contents.html b/amanuensis/templates/lexicon/contents.html index a1cb784..d9455e4 100644 --- a/amanuensis/templates/lexicon/contents.html +++ b/amanuensis/templates/lexicon/contents.html @@ -6,7 +6,5 @@

Index

-{% set lexicons = current_user.lexicons_in() %} - {% endblock %} {% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/templates/lexicon/rules.html b/amanuensis/templates/lexicon/rules.html index 37c8d94..c9823ce 100644 --- a/amanuensis/templates/lexicon/rules.html +++ b/amanuensis/templates/lexicon/rules.html @@ -6,7 +6,5 @@

Rules

-{% set lexicons = current_user.lexicons_in() %} - {% endblock %} {% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/templates/lexicon/statistics.html b/amanuensis/templates/lexicon/statistics.html index 4c220f7..feacb86 100644 --- a/amanuensis/templates/lexicon/statistics.html +++ b/amanuensis/templates/lexicon/statistics.html @@ -6,7 +6,5 @@

Statistics

-{% set lexicons = current_user.lexicons_in() %} - {% endblock %} {% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/user.py b/amanuensis/user.py index dd16cc7..e8a79fc 100644 --- a/amanuensis/user.py +++ b/amanuensis/user.py @@ -10,7 +10,7 @@ from amanuensis.errors import ( ArgumentError, MissingConfigError, IndexMismatchError) from amanuensis.config import prepend, json_ro, json_rw from amanuensis.resources import get_stream -from amanuensis.lexicon.manage import get_all_lexicons + class UserModel(UserMixin): @staticmethod @@ -64,13 +64,6 @@ class UserModel(UserMixin): with json_ro(self.config_path) as j: return check_password_hash(j['password'], pw) - def lexicons_in(self): - return [ - lex - for lex in get_all_lexicons() - if self.id in lex.join.joined - ] - def valid_username(username): """ @@ -82,6 +75,7 @@ def valid_username(username): is_a_guid = re.match(r"^[A-Za-z0-9]{32}$", username) return length_and_characters and not is_a_guid + def valid_email(email): """Vaguely RFC2822 email verifier""" atom = r"[0-9A-Za-z!#$%&'*+-/=?^_`{|}~]{1,}" @@ -89,6 +83,7 @@ def valid_email(email): addrspec = "^" + dotatom + "@" + dotatom + "$" return re.match(addrspec, email) + def create_user(username, displayname, email): """ Creates a new user