Savepoint

Signed-off-by: Georg <georg@lysergic.dev>
This commit is contained in:
Georg Pfuetzenreuter 2021-09-02 01:47:37 +02:00
parent 840265c745
commit d5f5ac7bd2
Signed by: Georg
GPG Key ID: 1DAF57F49F8E8F22
6 changed files with 141 additions and 17 deletions

View File

@ -1,5 +1,5 @@
from flask import Flask, render_template, url_for, request, redirect, flash 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_register import ircregister
#from irc_verify import ircverify #from irc_verify import ircverify
@ -23,13 +23,30 @@ def kiwinick():
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
form = RegistrationForm() optionform = OptionForm()
if request.method == 'POST': registerform = RegistrationForm()
if optionform.validate_on_submit():
option = request.form['options']
print(option)
print(form.option.data)
if option == 'mail-old':
return "<script>window.location.replace('/register1')</script>", 200
#return "<script>window.location.href = '/register1'</script>", 200
elif option == 'mail-new':
return "<script>window.location.replace('/register2')</script>", 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') username = request.form.get('username')
email = request.form.get('email') email = request.form.get('email')
password = request.form.get('password') 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) response = ircregister(username, password, email)
if response == "433": if response == "433":
flash("IRC username already taken. Please select a different username") flash("IRC username already taken. Please select a different username")
@ -42,7 +59,8 @@ def register():
elif response == "ssoerr": elif response == "ssoerr":
flash("Sorry, we messed up. Please contact an administrator.") 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']) #@app.route('/verify', methods=['GET', 'POST'])
#def verify(): #def verify():

View File

@ -1,7 +1,10 @@
from flask_wtf import FlaskForm 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 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): class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=1, max=32)]) username = StringField('Username', validators=[DataRequired(), Length(min=1, max=32)])

View File

@ -100,7 +100,6 @@ def ircregister(username, password, email):
return "ssoerr" return "ssoerr"
if status == 409: # likely already occupied username or email address 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.") print("ERROR: Keycloak indicated that the resource already exists or \"some other coonflict when processing the request\" occured.")
return "ssoerr"
return "409" return "409"
#to-do: parse response JSON to inform the user whether it's the username OR the email address causing the culprit #to-do: parse response JSON to inform the user whether it's the username OR the email address causing the culprit
if status == 415: if status == 415:

View File

@ -26,19 +26,25 @@
└─┘ ┘ │ ──┘ ┘ │ └─┘ ┘ │ ──┘ ┘ │
<form method="POST" action="/register"> <form method="POST" action="/register">
{{ form.hidden_tag() }} {{ optionform.hidden_tag() }}
{{ optionform.option }}
{{ optionform.submit }}
</form>
<form method="POST" action="/register1">
{{ registerform.hidden_tag() }}
<fieldset> <fieldset>
<legend>Sign Up</legend> <legend>Sign Up</legend>
{{ form.username.label }} {{ registerform.username.label }}
{{ form.username }} {{ registerform.username }}
{{ form.email.label }} {{ registerform.email.label }}
{{ form.email }} {{ registerform.email }}
{{ form.password.label }} {{ registerform.password.label }}
{{ form.password }} {{ registerform.password }}
{{ form.confirm_password.label }} {{ registerform.confirm_password.label }}
{{ form.confirm_password }} {{ registerform.confirm_password }}
</fieldset> </fieldset>
{{ form.submit }} {{ registerform.submit }}
</form> </form>
If you already have an account please login to the IRC using SASL. If you already have an account please login to the IRC using SASL.

50
templates/register1.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
<style>
body {
background-color: black;
color: white;
}
</style>
</head>
<body>
{% for message in get_flashed_messages() %}
{{ message }}
{% endfor %}
<pre>
┬ ┌┬┐ ┬─┐ ┬─┐ ┬─┐ ┌┐┐ ┬─┐
│ │ │─│ │─ │┬┘ │ │─┤
┘─┘ └┴┘ │─┘ ┴─┘ │└┘ ┘ ┘ │
┌─┐ ┬─┐ ┐─┐ ┬─┐
│ │─┤ └─┐ │─┤
└─┘ ┘ │ ──┘ ┘ │
<form method="POST" action="/register">
{{ optionform.hidden_tag() }}
{{ optionform.option }}
{{ optionform.submit }}
</form>
<form method="POST" action="/register1">
{{ registerform.hidden_tag() }}
<fieldset>
<legend>Sign Up</legend>
{{ registerform.username.label }}
{{ registerform.username }}
{{ registerform.email.label }}
{{ registerform.email }}
{{ registerform.password.label }}
{{ registerform.password }}
{{ registerform.confirm_password.label }}
{{ registerform.confirm_password }}
</fieldset>
{{ registerform.submit }}
</form>
If you already have an account please login to the IRC using SASL.

48
templates/register2.html Normal file
View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
<style>
body {
background-color: black;
color: white;
}
</style>
</head>
<body>
{% for message in get_flashed_messages() %}
{{ message }}
{% endfor %}
<pre>
┬ ┌┬┐ ┬─┐ ┬─┐ ┬─┐ ┌┐┐ ┬─┐
│ │ │─│ │─ │┬┘ │ │─┤
┘─┘ └┴┘ │─┘ ┴─┘ │└┘ ┘ ┘ │
┌─┐ ┬─┐ ┐─┐ ┬─┐
│ │─┤ └─┐ │─┤
└─┘ ┘ │ ──┘ ┘ │
<form method="POST" action="/register">
{{ optionform.hidden_tag() }}
{{ optionform.option }}
{{ optionform.submit }}
</form>
<form method="POST" action="/register1">
{{ registerform.hidden_tag() }}
<fieldset>
<legend>Sign Up</legend>
{{ registerform.username.label }}
{{ registerform.username }}
{{ registerform.password.label }}
{{ registerform.password }}
{{ registerform.confirm_password.label }}
{{ registerform.confirm_password }}
</fieldset>
{{ registerform.submit }}
</form>
If you already have an account please login to the IRC using SASL.