Skip to content
Snippets Groups Projects
Commit b4e04a20 authored by sistason's avatar sistason
Browse files

Use flash with categories, replacing error-strings

parent 10e37c17
Branches
Tags
No related merge requests found
...@@ -172,14 +172,17 @@ def signup_submit(invite_id, token): ...@@ -172,14 +172,17 @@ def signup_submit(invite_id, token):
if not invite or not secrets.compare_digest(invite.token, token): if not invite or not secrets.compare_digest(invite.token, token):
abort(404) abort(404)
if request.form['password1'] != request.form['password2']: if request.form['password1'] != request.form['password2']:
return render_template('signup/start.html', error=_('Passwords do not match')) flash(_('Passwords do not match'), 'error')
return render_template('signup/start.html')
signup_delay = signup_ratelimit.get_delay(request.form['mail']) signup_delay = signup_ratelimit.get_delay(request.form['mail'])
host_delay = host_ratelimit.get_delay() host_delay = host_ratelimit.get_delay()
if signup_delay and signup_delay > host_delay: if signup_delay and signup_delay > host_delay:
return render_template('signup/start.html', error=_('Too many signup requests with this mail address! Please wait %(delay)s.', flash(_('Too many signup requests with this mail address! Please wait %(delay)s.',
delay=format_delay(signup_delay))) delay=format_delay(signup_delay)), 'error')
return render_template('signup/start.html')
if host_delay: if host_delay:
return render_template('signup/start.html', error=_('Too many requests! Please wait %(delay)s.', delay=format_delay(host_delay))) flash(_('Too many requests! Please wait %(delay)s.', delay=format_delay(host_delay)), 'error')
return render_template('signup/start.html')
host_ratelimit.log() host_ratelimit.log()
signup = InviteSignup(invite=invite, loginname=request.form['loginname'], signup = InviteSignup(invite=invite, loginname=request.form['loginname'],
displayname=request.form['displayname'], displayname=request.form['displayname'],
...@@ -187,11 +190,13 @@ def signup_submit(invite_id, token): ...@@ -187,11 +190,13 @@ def signup_submit(invite_id, token):
password=request.form['password1']) password=request.form['password1'])
valid, msg = signup.validate() valid, msg = signup.validate()
if not valid: if not valid:
return render_template('signup/start.html', error=msg) flash(msg, 'error')
return render_template('signup/start.html')
db.session.add(signup) db.session.add(signup)
db.session.commit() db.session.commit()
sent = sendmail(signup.mail, 'Confirm your mail address', 'signup/mail.txt', signup=signup) sent = sendmail(signup.mail, 'Confirm your mail address', 'signup/mail.txt', signup=signup)
if not sent: if not sent:
return render_template('signup/start.html', error=_('Could not send mail')) flash(_('Could not send mail'), 'error')
return render_template('signup/start.html')
signup_ratelimit.log(request.form['mail']) signup_ratelimit.log(request.form['mail'])
return render_template('signup/submitted.html', signup=signup) return render_template('signup/submitted.html', signup=signup)
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
<div class="col-12"> <div class="col-12">
<h2 class="text-center">{{_('Complete Registration')}}</h2> <h2 class="text-center">{{_('Complete Registration')}}</h2>
</div> </div>
{% if error %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endif %}
<div class="form-group col-12"> <div class="form-group col-12">
<label for="user-password1">{{_('Please enter your password to complete the account registration')}}</label> <label for="user-password1">{{_('Please enter your password to complete the account registration')}}</label>
<input type="password" class="form-control" id="user-password1" name="password" required="required"> <input type="password" class="form-control" id="user-password1" name="password" required="required">
......
...@@ -5,11 +5,6 @@ ...@@ -5,11 +5,6 @@
<div class="col-12"> <div class="col-12">
<h2 class="text-center">{{_('Account Registration')}}</h2> <h2 class="text-center">{{_('Account Registration')}}</h2>
</div> </div>
{% if error %}
<div class="form-group col-12">
<div class="alert alert-danger" role="alert">{{ error }}</div>
</div>
{% endif %}
<div class="form-group col-12"> <div class="form-group col-12">
<label for="user-loginname">{{_('Login Name')}}</label> <label for="user-loginname">{{_('Login Name')}}</label>
<div class="js-only-input-group"> <div class="js-only-input-group">
......
...@@ -46,14 +46,17 @@ def signup_check(): ...@@ -46,14 +46,17 @@ def signup_check():
@signup_enabled @signup_enabled
def signup_submit(): def signup_submit():
if request.form['password1'] != request.form['password2']: if request.form['password1'] != request.form['password2']:
return render_template('signup/start.html', error=_('Passwords do not match')) flash(_('Passwords do not match'), 'error')
return render_template('signup/start.html')
signup_delay = signup_ratelimit.get_delay(request.form['mail']) signup_delay = signup_ratelimit.get_delay(request.form['mail'])
host_delay = host_ratelimit.get_delay() host_delay = host_ratelimit.get_delay()
if signup_delay and signup_delay > host_delay: if signup_delay and signup_delay > host_delay:
return render_template('signup/start.html', error=_('Too many signup requests with this mail address! Please wait %(delay)s.', flash(_('Too many signup requests with this mail address! Please wait %(delay)s.',
delay=format_delay(signup_delay))) delay=format_delay(signup_delay)), 'error')
return render_template('signup/start.html')
if host_delay: if host_delay:
return render_template('signup/start.html', error=_('Too many requests! Please wait %(delay)s.', delay=format_delay(host_delay))) flash(_('Too many requests! Please wait %(delay)s.', delay=format_delay(host_delay)), 'error')
return render_template('signup/start.html')
host_ratelimit.log() host_ratelimit.log()
signup = Signup(loginname=request.form['loginname'], signup = Signup(loginname=request.form['loginname'],
displayname=request.form['displayname'], displayname=request.form['displayname'],
...@@ -64,12 +67,14 @@ def signup_submit(): ...@@ -64,12 +67,14 @@ def signup_submit():
signup.set_password(request.form['password1']) signup.set_password(request.form['password1'])
valid, msg = signup.validate() valid, msg = signup.validate()
if not valid: if not valid:
return render_template('signup/start.html', error=msg) flash(msg, 'error')
return render_template('signup/start.html')
db.session.add(signup) db.session.add(signup)
db.session.commit() db.session.commit()
sent = sendmail(signup.mail, 'Confirm your mail address', 'signup/mail.txt', signup=signup) sent = sendmail(signup.mail, 'Confirm your mail address', 'signup/mail.txt', signup=signup)
if not sent: if not sent:
return render_template('signup/start.html', error=_('Could not send mail')) flash(_('Could not send mail'), 'error')
return render_template('signup/start.html')
signup_ratelimit.log(request.form['mail']) signup_ratelimit.log(request.form['mail'])
return render_template('signup/submitted.html', signup=signup) return render_template('signup/submitted.html', signup=signup)
...@@ -91,16 +96,19 @@ def signup_confirm_submit(signup_id, token): ...@@ -91,16 +96,19 @@ def signup_confirm_submit(signup_id, token):
confirm_delay = confirm_ratelimit.get_delay(token) confirm_delay = confirm_ratelimit.get_delay(token)
host_delay = host_ratelimit.get_delay() host_delay = host_ratelimit.get_delay()
if confirm_delay and confirm_delay > host_delay: if confirm_delay and confirm_delay > host_delay:
return render_template('signup/confirm.html', signup=signup, error=_('Too many failed attempts! Please wait %(delay)s.', delay=format_delay(confirm_delay))) flash(_('Too many failed attempts! Please wait %(delay)s.', delay=format_delay(confirm_delay)), 'error')
return render_template('signup/confirm.html', signup=signup)
if host_delay: if host_delay:
return render_template('signup/confirm.html', signup=signup, error=_('Too many requests! Please wait %(delay)s.', delay=format_delay(host_delay))) return render_template('signup/confirm.html', signup=signup)
if not signup.password.verify(request.form['password']): if not signup.password.verify(request.form['password']):
host_ratelimit.log() host_ratelimit.log()
confirm_ratelimit.log(token) confirm_ratelimit.log(token)
return render_template('signup/confirm.html', signup=signup, error=_('Wrong password')) flash(_('Wrong password'), 'error')
return render_template('signup/confirm.html', signup=signup)
user, msg = signup.finish(request.form['password']) user, msg = signup.finish(request.form['password'])
if user is None: if user is None:
return render_template('signup/confirm.html', signup=signup, error=msg) flash(msg, 'error')
return render_template('signup/confirm.html', signup=signup)
db.session.commit() db.session.commit()
set_session(user, skip_mfa=True) set_session(user, skip_mfa=True)
flash(_('Your account was successfully created')) flash(_('Your account was successfully created'))
......
...@@ -117,9 +117,9 @@ ...@@ -117,9 +117,9 @@
{% block main %} {% block main %}
<main role="main" class="container mt-3"> <main role="main" class="container mt-3">
<div class="row"> <div class="row">
{% for message in get_flashed_messages() %} {% for category, message in get_flashed_messages(with_categories=true) %}
<div class="col-12"> <div class="col-12">
<div class="alert alert-primary" role="alert">{{ message }}</div> <div class="alert alert-{{ 'danger' if category == 'error' else 'warning' if category == 'warning' else 'primary' }}" role="alert">{{ message }}</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-lg-6 col-md-10 px-0"> <div class="col-lg-6 col-md-10 px-0">
<div class="row"> <div class="row">
{% for message in get_flashed_messages() %} {% for category, message in get_flashed_messages(with_categories=true) %}
<div class="col-12"> <div class="col-12">
<div class="alert alert-primary" role="alert">{{ message }}</div> <div class="alert alert-{{ 'danger' if category == 'error' else 'warning' if category == 'warning' else 'primary' }}" role="alert">{{ message }}</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment