From d5f5ac7bd254ac591b4bbeb606565ac22e2ce35c Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 2 Sep 2021 01:47:37 +0200 Subject: Savepoint Signed-off-by: Georg --- flaskapp.py | 28 ++++++++++++++++++++++----- forms.py | 5 ++++- irc_register.py | 1 - templates/register.html | 26 +++++++++++++++---------- templates/register1.html | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ templates/register2.html | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 17 deletions(-) create mode 100644 templates/register1.html create mode 100644 templates/register2.html diff --git a/flaskapp.py b/flaskapp.py index c8ce2d3..440b407 100644 --- a/flaskapp.py +++ b/flaskapp.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, url_for, request, redirect, flash -from forms import RegistrationForm +from forms import RegistrationForm, OptionForm from irc_register import ircregister #from irc_verify import ircverify @@ -23,13 +23,30 @@ def kiwinick(): @app.route('/register', methods=['GET', 'POST']) def register(): - form = RegistrationForm() - if request.method == 'POST': + optionform = OptionForm() + registerform = RegistrationForm() + if optionform.validate_on_submit(): + option = request.form['options'] + print(option) + print(form.option.data) + if option == 'mail-old': + return "", 200 + #return "", 200 + elif option == 'mail-new': + return "", 200 + + return render_template('register.html', title='Register', optionform=optionform, registerform=registerform) +@app.route('/register1', methods=['GET', 'POST']) +def register1(): + optionform = OptionForm() + registerform = RegistrationForm() + if request.method == 'POST': username = request.form.get('username') email = request.form.get('email') password = request.form.get('password') -# email = request.form.get('email') add password arg to ircregisterfunction + option = request.form['options'] + print(option) response = ircregister(username, password, email) if response == "433": flash("IRC username already taken. Please select a different username") @@ -42,7 +59,8 @@ def register(): elif response == "ssoerr": flash("Sorry, we messed up. Please contact an administrator.") - return render_template('register.html', title='Register', form=form) + return render_template('register1.html', title='Register', optionform=optionform, registerform=registerform) + #@app.route('/verify', methods=['GET', 'POST']) #def verify(): diff --git a/forms.py b/forms.py index 6e55f64..5a86e6e 100644 --- a/forms.py +++ b/forms.py @@ -1,7 +1,10 @@ from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, SubmitField +from wtforms import StringField, PasswordField, SubmitField, RadioField from wtforms.validators import DataRequired, Length, EqualTo, Email +class OptionForm(FlaskForm): + option = RadioField('Label', choices=[('mail-old','I want to use an existing email address.'),('mail-new','I want to create and use a new email address.')]) + submit = SubmitField('Save preference') class RegistrationForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(min=1, max=32)]) diff --git a/irc_register.py b/irc_register.py index 0492a86..62734a3 100644 --- a/irc_register.py +++ b/irc_register.py @@ -100,7 +100,6 @@ def ircregister(username, password, email): return "ssoerr" if status == 409: # likely already occupied username or email address print("ERROR: Keycloak indicated that the resource already exists or \"some other coonflict when processing the request\" occured.") - return "ssoerr" return "409" #to-do: parse response JSON to inform the user whether it's the username OR the email address causing the culprit if status == 415: diff --git a/templates/register.html b/templates/register.html index 9c535e3..1de1f38 100644 --- a/templates/register.html +++ b/templates/register.html @@ -26,19 +26,25 @@ └─┘ ┘ │ ──┘ ┘ │
- {{ form.hidden_tag() }} + {{ optionform.hidden_tag() }} + {{ optionform.option }} + {{ optionform.submit }} +
+ +
+ {{ registerform.hidden_tag() }}
Sign Up - {{ form.username.label }} - {{ form.username }} - {{ form.email.label }} - {{ form.email }} - {{ form.password.label }} - {{ form.password }} - {{ form.confirm_password.label }} - {{ form.confirm_password }} + {{ registerform.username.label }} + {{ registerform.username }} + {{ registerform.email.label }} + {{ registerform.email }} + {{ registerform.password.label }} + {{ registerform.password }} + {{ registerform.confirm_password.label }} + {{ registerform.confirm_password }}
- {{ form.submit }} + {{ registerform.submit }}
If you already have an account please login to the IRC using SASL. diff --git a/templates/register1.html b/templates/register1.html new file mode 100644 index 0000000..1de1f38 --- /dev/null +++ b/templates/register1.html @@ -0,0 +1,50 @@ + + + + + + Register + + + + + {% for message in get_flashed_messages() %} + {{ message }} + {% endfor %} +
+┬   ┌┬┐ ┬─┐ ┬─┐ ┬─┐ ┌┐┐ ┬─┐
+│    │  │─│ │─  │┬┘  │  │─┤
+┘─┘ └┴┘ │─┘ ┴─┘ │└┘  ┘  ┘ │
+
+┌─┐ ┬─┐ ┐─┐ ┬─┐
+│   │─┤ └─┐ │─┤
+└─┘ ┘ │ ──┘ ┘ │
+
+
+ {{ optionform.hidden_tag() }} + {{ optionform.option }} + {{ optionform.submit }} +
+ +
+ {{ registerform.hidden_tag() }} +
+ Sign Up + {{ registerform.username.label }} + {{ registerform.username }} + {{ registerform.email.label }} + {{ registerform.email }} + {{ registerform.password.label }} + {{ registerform.password }} + {{ registerform.confirm_password.label }} + {{ registerform.confirm_password }} +
+ {{ registerform.submit }} +
+ +If you already have an account please login to the IRC using SASL. diff --git a/templates/register2.html b/templates/register2.html new file mode 100644 index 0000000..4de3760 --- /dev/null +++ b/templates/register2.html @@ -0,0 +1,48 @@ + + + + + + Register + + + + + {% for message in get_flashed_messages() %} + {{ message }} + {% endfor %} +
+┬   ┌┬┐ ┬─┐ ┬─┐ ┬─┐ ┌┐┐ ┬─┐
+│    │  │─│ │─  │┬┘  │  │─┤
+┘─┘ └┴┘ │─┘ ┴─┘ │└┘  ┘  ┘ │
+
+┌─┐ ┬─┐ ┐─┐ ┬─┐
+│   │─┤ └─┐ │─┤
+└─┘ ┘ │ ──┘ ┘ │
+
+
+ {{ optionform.hidden_tag() }} + {{ optionform.option }} + {{ optionform.submit }} +
+ +
+ {{ registerform.hidden_tag() }} +
+ Sign Up + {{ registerform.username.label }} + {{ registerform.username }} + {{ registerform.password.label }} + {{ registerform.password }} + {{ registerform.confirm_password.label }} + {{ registerform.confirm_password }} +
+ {{ registerform.submit }} +
+ +If you already have an account please login to the IRC using SASL. -- cgit v1.2.3