diff --git a/app.py b/app.py index 0ac759f..eed745d 100644 --- a/app.py +++ b/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) diff --git a/templates/admin.html b/templates/admin.html index 6d90cf9..52a2b5c 100644 --- a/templates/admin.html +++ b/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() }}