From 07136ef2836489124cc3f6178405b8d5aea6164e Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 11 May 2022 13:05:18 -0500 Subject: [PATCH] Resolves #30 --- app/accounts.py | 18 +++++++++++++++++- app/forms.py | 14 +++++++++++++- app/templates/accounts/edit_email.html.j2 | 21 +++++++++++++++++++++ app/templates/partials/_account.html.j2 | 6 ++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/templates/accounts/edit_email.html.j2 diff --git a/app/accounts.py b/app/accounts.py index 6f08098..173d16e 100644 --- a/app/accounts.py +++ b/app/accounts.py @@ -18,7 +18,7 @@ from app.models import ( ) from app.schemas import AccountSchema from app import gm_level, log_audit -from app.forms import EditGMLevelForm +from app.forms import EditGMLevelForm, EditEmailForm accounts_blueprint = Blueprint('accounts', __name__) @@ -69,6 +69,22 @@ def edit_gm_level(id): return render_template('accounts/edit_gm_level.html.j2', form=form, username=account_data.username) +@accounts_blueprint.route('/edit_email/', methods=('GET', 'POST')) +@login_required +@gm_level(8) +def edit_email(id): + account_data = Account.query.filter(Account.id == id).first() + form = EditEmailForm() + if form.validate_on_submit(): + log_audit(f"Changed ({account_data.id}){account_data.username}'s Email from {account_data.email} to {form.email.data}") + account_data.email = form.email.data + account_data.save() + return redirect(url_for('accounts.view', id=account_data.id)) + + form.email.data = account_data.email + return render_template('accounts/edit_email.html.j2', form=form, username=account_data.username) + + @accounts_blueprint.route('/lock/', methods=['GET']) @login_required @gm_level(3) diff --git a/app/forms.py b/app/forms.py index e265aee..df34a83 100644 --- a/app/forms.py +++ b/app/forms.py @@ -119,7 +119,7 @@ class EditPlayKeyForm(FlaskForm): class EditGMLevelForm(FlaskForm): - gm_level = IntegerField( + email = IntegerField( 'GM Level', widget=NumberInput(min=0, max=9) ) @@ -127,6 +127,18 @@ class EditGMLevelForm(FlaskForm): submit = SubmitField('Submit') +class EditEmailForm(FlaskForm): + email = StringField( + 'E-Mail', + validators=[ + Optional(), + validators.Email('Invalid email address'), + unique_email_validator, + ] + ) + submit = SubmitField('Submit') + + class ResolveBugReportForm(FlaskForm): resolution = StringField( diff --git a/app/templates/accounts/edit_email.html.j2 b/app/templates/accounts/edit_email.html.j2 new file mode 100644 index 0000000..945f9c0 --- /dev/null +++ b/app/templates/accounts/edit_email.html.j2 @@ -0,0 +1,21 @@ +{% extends 'base.html.j2' %} + +{% block title %} + Edit E-mail for User {{ username }} +{% endblock title %} + +{% block content_before %} + Edit E-mail for User {{ username }} +{% endblock content_before %} + +{% block content %} +
+ {{ form.csrf_token }} +
+
+ {{ helper.render_field(form.email) }} + {{ helper.render_submit_field(form.submit) }} +
+
+
+{% endblock content %} diff --git a/app/templates/partials/_account.html.j2 b/app/templates/partials/_account.html.j2 index a2f65d9..790873a 100644 --- a/app/templates/partials/_account.html.j2 +++ b/app/templates/partials/_account.html.j2 @@ -23,6 +23,12 @@
{{ account_data.email }} + {% if current_user.gm_level >= 8 and not(current_user.gm_level == 8 and account_data.gm_level == 8)%} + + Edit + + {% endif %}
{% endif %}