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

Tlačítko na pozvání zvacího emailu / resetování hesla v detailu soutěžícího/organizátora

Užitečné po změně emailu.
parent 1393a13f
No related branches found
No related tags found
1 merge request!56Editace emailu + zvací emaily
......@@ -7,6 +7,7 @@ from sqlalchemy import or_
from sqlalchemy.orm import joinedload, subqueryload
from wtforms import validators
from wtforms.fields.simple import SubmitField
from wtforms.validators import Required
......@@ -210,6 +211,20 @@ class FormRemoveRole(FlaskForm):
remove = wtforms.SubmitField('Odebrat roli')
class ResendInviteForm(FlaskForm):
resend_invite = SubmitField()
def do(self, user: db.User):
token = mo.users.ask_reset_password(user)
db.get_session().commit()
if user.last_login_at is None and mo.util.send_new_account_email(user, token):
flash('Uvítací e-mail s odkazem pro nastavení hesla odeslán na {}'.format(user.email), 'success')
elif mo.util.send_password_reset_email(user, token):
flash('E-mail s odkazem pro resetování hesla odeslán na {}'.format(user.email), 'success')
else:
flash('Problém při odesílání e-mailu s odkazem pro nastavení hesla', 'danger')
@app.route('/org/org/<int:id>/', methods=('GET', 'POST'))
def org_org(id: int):
sess = db.get_session()
......@@ -222,6 +237,13 @@ def org_org(id: int):
rr = g.gatekeeper.rights_generic()
can_assign_rights = rr.have_right(Right.assign_rights)
resend_invite_form: Optional[ResendInviteForm] = None
if rr.can_edit_user(user):
resend_invite_form = ResendInviteForm()
if resend_invite_form.validate_on_submit():
resend_invite_form.do(user)
return redirect(url_for('org_org', id=id))
form_add_role = FormAddRole()
form_remove_role = FormRemoveRole()
role_errors = []
......@@ -286,6 +308,7 @@ def org_org(id: int):
can_incarnate=g.user.is_admin,
roles_by_type=mo.rights.roles_by_type, role_errors=role_errors,
form_add_role=form_add_role, form_remove_role=form_remove_role,
resend_invite_form=resend_invite_form,
)
......@@ -300,6 +323,13 @@ def org_user(id: int):
rr = g.gatekeeper.rights_generic()
resend_invite_form: Optional[ResendInviteForm] = None
if rr.can_edit_user(user):
resend_invite_form = ResendInviteForm()
if resend_invite_form.validate_on_submit():
resend_invite_form.do(user)
return redirect(url_for('org_user', id=id))
participants = sess.query(db.Participant).filter_by(user_id=user.user_id)
participations = (
sess.query(db.Participation, db.Contest, db.Round)
......@@ -316,6 +346,7 @@ def org_user(id: int):
'org_user.html', user=user, can_edit=rr.can_edit_user(user),
can_incarnate=g.user.is_admin,
participants=participants, participations=participations,
resend_invite_form=resend_invite_form,
)
......
......@@ -15,20 +15,27 @@
<tr><td>Poznámka:<td style="white-space: pre;">{{ user.note }}
</table>
{% if can_edit %}
<div class="btn-group" role="group">
{% if can_edit %}
<a class="btn btn-primary" href="{{ url_for('org_org_edit', id=user.user_id) }}">Editovat</a>
{% endif %}
{% if resend_invite_form %}
<form method=POST class='btn-group' onsubmit='return confirm("Poslat organizátorovi e-mail s odkazem na vytvoření hesla?");'>
{{ resend_invite_form.csrf_token }}
<button class="btn btn-default" type='submit' name='resend_invite'>
{% if user.last_login_at %}Resetovat heslo{% else %}Znovu poslat zvací e-mail{% endif %}
</button>
</form>
{% endif %}
{% if g.user.is_admin %}
<a class="btn btn-default" href="{{ log_url('user', user.user_id) }}">Historie</a>
{% endif %}
</div>
{% endif %}
{% if can_incarnate %}
<form action="{{ url_for('incarnate', id=user.user_id) }}" method=POST class='btn-group'>
<button class="btn btn-default" type='Submit'>Převtělit se</button>
</form>
{% endif %}
</div>
{% if user.is_org or user.is_admin %}
<h3>Role</h3>
......
......@@ -10,25 +10,32 @@
{% if user.is_admin %}<tr><td>Správce:<td>ano{% endif %}
{% if user.is_org %}<tr><td>Organizátor:<td>ano{% endif %}
<tr><td>Účet založen:<td>{{ user.created_at|timeformat }}
<tr><td>Poslední přihlášení:<td>{{ user.last_login_at|timeformat }}
<tr><td>Poslední přihlášení:{% if user.last_login_at %}<td>{{ user.last_login_at|timeformat }}{% else %}<td class="error"><i>Zatím nepřihlášen</i>{% endif %}
{% if user.reset_at %}<tr><td>Reset hesla:<td>{{ user.reset_at|timeformat }}{% endif %}
<tr><td>Poznámka:<td style="white-space: pre;">{{ user.note }}
</table>
{% if can_edit %}
<div class="btn-group" role="group">
{% if can_edit %}
<a class="btn btn-primary" href="{{ url_for('org_user_edit', id=user.user_id) }}">Editovat</a>
{% endif %}
{% if resend_invite_form %}
<form method=POST class='btn-group' onsubmit='return confirm("Poslat účastníkovi e-mail s odkazem na vytvoření hesla?");'>
{{ resend_invite_form.csrf_token }}
<button class="btn btn-default" type='submit' name='resend_invite'>
{% if user.last_login_at %}Resetovat heslo{% else %}Znovu poslat zvací e-mail{% endif %}
</button>
</form>
{% endif %}
{% if g.user.is_admin %}
<a class="btn btn-default" href="{{ log_url('user', user.user_id) }}">Historie</a>
{% endif %}
</div>
{% endif %}
{% if can_incarnate %}
<form action="{{ url_for('incarnate', id=user.user_id) }}" method=POST class='btn-group'>
<button class="btn btn-default" type='Submit'>Převtělit se</button>
</form>
{% endif %}
</div>
<h3>Registrace v ročnících</h3>
{% if participants.count() %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment