Browse Source

Linking to registration page + URL params autofill

* Added registrationCode url param to the registration page to autofill the code
* Added a link column to the admin registration code table for easy copying of registration links
master
Drew Short 5 years ago
parent
commit
2fb589342b
  1. 7
      app.py
  2. 19
      templates/admin.html

7
app.py

@ -10,7 +10,7 @@ from flask_login import LoginManager, login_required, login_user, logout_user, U
from flask_wtf import CSRFProtect
from db import get_db, get_registration_codes, add_registration_code, \
expire_registration_code, delete_registration_code
expire_registration_code, delete_registration_code, get_registered_users
from forms import RegistrationForm, LoginForm, RegistrationCodeForm, \
ExpireRegistrationCodeForm
@ -93,6 +93,8 @@ def registration():
form = RegistrationForm()
if form.validate_on_submit():
return redirect('/success')
if 'registrationCode' in request.values:
form.registration_code.data = request.values['registrationCode']
return render_template('register.html', form=form)
@ -101,7 +103,8 @@ def registration():
def admin_index():
context = {
'add_registration_code_form': RegistrationCodeForm(),
'registration_codes': get_registration_codes()
'registration_codes': get_registration_codes(),
'registered_users': get_registered_users()
}
return render_template('admin.html', **context)

19
templates/admin.html

@ -13,6 +13,7 @@
<th>Expiration Time</th>
<th>Usages</th>
<th>Max Usages</th>
<th>Registration Link</th>
<th>Expire</th>
</thead>
<tbody>
@ -23,6 +24,7 @@
<td>{{ registration_code.expiration_time|tojson|safe }}</td>
<td>{{ registration_code.usages|tojson|safe }}</td>
<td>{{ registration_code.max_usages|tojson|safe }}</td>
<td><a href="/register?registrationCode={{ registration_code.code }}">link</a>
<td>
<form method="POST" action="/admin/expire_registration_code">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
@ -40,6 +42,23 @@
</table>
</div>
<hr>
<div id="registeredUsers">
<table>
<thead>
<th>User</th>
<th>Registration Time</th>
</thead>
<tbody>
{% for registered_user in registered_users %}
<tr>
<td>{{ registered_user.username|tojson|safe }}</td>
<td>{{ registered_user.registration_time|tojson|safe }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<hr>
<form method="POST" action="/admin/add_registration_code">
{{ add_registration_code_form.csrf_token }}
{{ add_registration_code_form.expiration_time.label }} {{ add_registration_code_form.expiration_time() }}

Loading…
Cancel
Save