Skip to content
Snippets Groups Projects
Commit 1393a13f authored by Jiří Setnička's avatar Jiří Setnička
Browse files

Editace emailů uživatelů

Emaily soutěžících může editovat každý organizátor, který se dostane na
stránku Soutěžící (teď zatím všichni). Email organizátora může editovat
správce.

Issue #117
parent 5d014c42
Branches
No related tags found
1 merge request!56Editace emailu + zvací emaily
This commit is part of merge request !56. Comments created here will be created in the context of that merge request.
......@@ -322,14 +322,10 @@ def org_user(id: int):
class UserEditForm(FlaskForm):
first_name = wtforms.StringField("Jméno", validators=[Required()], render_kw={'autofocus': True})
last_name = wtforms.StringField("Příjmení", validators=[Required()])
email = wtforms.StringField("E-mail", validators=[Required()])
note = wtforms.TextAreaField("Poznámka")
submit = wtforms.SubmitField("Uložit")
class NewUserForm(UserEditForm):
email = wtforms.StringField("E-mail", validators=[Required()])
submit = wtforms.SubmitField("Vytvořit")
def validate_email(form, field):
try:
field.data = mo.users.normalize_email(field.data)
......@@ -357,9 +353,18 @@ def org_user_edit(id: int):
raise werkzeug.exceptions.Forbidden()
form = UserEditForm(obj=user)
if (user.is_org or user.is_admin) and not g.user.is_admin:
# emaily u organizátorů může editovat jen správce
del form.email
if form.validate_on_submit():
form.populate_obj(user)
check = True
if mo.users.user_by_email(form.email.data) is not None:
flash('Zadaný e-mail nelze použít, existuje jiný účet s tímto e-mailem', 'danger')
check = False
if check:
form.populate_obj(user)
if sess.is_modified(user):
changes = db.get_object_changes(user)
......@@ -392,7 +397,8 @@ def org_user_new():
elif not rr.have_right(Right.add_users):
raise werkzeug.exceptions.Forbidden()
form = NewUserForm()
form = UserEditForm()
form.submit.label.text = 'Vytvořit'
if form.validate_on_submit():
check = True
......
......@@ -18,7 +18,7 @@
<h3>Editace údajů</h3>
<p>E-mail nelze editovat. Pro jeho změnu kontaktujte někoho ze správců.</p>
{% if not form.email %}<p>E-mail u organizátora nelze editovat. Pro jeho změnu kontaktujte někoho ze správců.</p>{% endif %}
{{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }}
......
......@@ -3,7 +3,7 @@
{% block title %}Nový {% if is_org %}organizátor{% else %}soutěžící{% endif %}{% endblock %}
{% block body %}
<p>Na zadanou e-mailovou adresu dorazí e-mail pro nastavení hesla. E-mailovou adresu po vytvoření účtu již nelze měnit.</p>
<p>Na zadanou e-mailovou adresu dorazí e-mail pro nastavení hesla.</p>
{{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment