From b22df32f042acb8ddfec7e321e8cb9c7f7e07622 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 3 Mar 2020 18:44:43 -0800 Subject: [PATCH] Spread CDC around forms a bit --- amanuensis/server/forms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amanuensis/server/forms.py b/amanuensis/server/forms.py index c7feb7d..5718a3b 100644 --- a/amanuensis/server/forms.py +++ b/amanuensis/server/forms.py @@ -5,7 +5,7 @@ from wtforms import ( from wtforms.validators import DataRequired, ValidationError, Optional from wtforms.widgets.html5 import NumberInput -from amanuensis.config import json_ro +from amanuensis.config import root from amanuensis.lexicon.manage import add_character from amanuensis.user import UserModel @@ -16,7 +16,7 @@ def user(exists=True): "not found" if exists else "already exists") should_exist = bool(exists) def validate_user(form, field): - with json_ro('user', 'index.json') as index: + with root.user.index() as index: if (field.data in index.keys()) != should_exist: raise ValidationError(template.format(field.data)) return validate_user @@ -27,7 +27,7 @@ def lexicon(exists=True): "not found" if exists else "already exists") should_exist = bool(exists) def validate_lexicon(form, field): - with json_ro('lexicon', 'index.json') as index: + with root.lexicon.index() as index: if (field.data in index.keys()) != should_exist: raise ValidationError(template.format(field.data)) return validate_lexicon @@ -36,7 +36,7 @@ def lexicon(exists=True): # Forms class LoginForm(FlaskForm): """/auth/login/""" - username = StringField('Username', validators=[DataRequired()]) + username = StringField('Username', validators=[DataRequired(), user(exists=True)]) password = PasswordField('Password', validators=[DataRequired()]) remember = BooleanField('Stay logged in') submit = SubmitField('Log in')