diff --git a/mo/web/org_users.py b/mo/web/org_users.py index 3fc728ec0e5f767e18ffd247ecf141f8c941929e..a236bba1502378010337da9096247c6fb83d5ab8 100644 --- a/mo/web/org_users.py +++ b/mo/web/org_users.py @@ -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, ) diff --git a/mo/web/templates/org_org.html b/mo/web/templates/org_org.html index 3385df81f546e2978b649ac66d22f1b14563f241..d32c01e4fd450f2f9ead76c33c13b9cee0be1113 100644 --- a/mo/web/templates/org_org.html +++ b/mo/web/templates/org_org.html @@ -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> diff --git a/mo/web/templates/org_user.html b/mo/web/templates/org_user.html index 7bc9afbc642ddfcf200842b3a395ba3d8f4b51fc..98b09ce2b8bbaa34cfc7135e1d9c74a57ec01680 100644 --- a/mo/web/templates/org_user.html +++ b/mo/web/templates/org_user.html @@ -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() %}