From daab0f063d9b0c34ca115b2496f7c050d3d20215 Mon Sep 17 00:00:00 2001 From: TuxCoder Date: Wed, 27 May 2020 21:16:14 +0200 Subject: [PATCH] add registration form --- lenticular_cloud/form/auth.py | 9 ++++++++- lenticular_cloud/model.py | 7 +++++++ lenticular_cloud/views/auth.py | 18 ++++++++++++++++-- templates/auth/login.html.j2 | 2 ++ templates/auth/sign_up.html.j2 | 11 +++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 templates/auth/sign_up.html.j2 diff --git a/lenticular_cloud/form/auth.py b/lenticular_cloud/form/auth.py index 5f2ef6c..104fd1d 100644 --- a/lenticular_cloud/form/auth.py +++ b/lenticular_cloud/form/auth.py @@ -4,13 +4,14 @@ from wtforms import StringField, SubmitField, TextField, \ TextAreaField, PasswordField, IntegerField, FloatField, \ DateTimeField, DateField, FormField, BooleanField, \ SelectField, Form as NoCsrfForm, SelectMultipleField +from wtforms.fields.html5 import EmailField from wtforms.widgets.html5 import NumberInput, DateInput from wtforms.validators import DataRequired, NumberRange, Optional, NoneOf, Length from datetime import datetime class LoginForm(FlaskForm): - name = StringField(gettext('User Name'), validators=[DataRequired()]) + name = StringField(gettext('Username'), validators=[DataRequired()]) submit = SubmitField(gettext('Login')) @@ -35,3 +36,9 @@ class ConsentForm(FlaskForm): remember = BooleanField(gettext('remember me')) submit = SubmitField() + +class RegistrationForm(FlaskForm): + username = StringField(gettext('Username'), validators=[DataRequired()]) + password = PasswordField(gettext('Password'), validators=[DataRequired()]) + alternative_email = EmailField(gettext('Alternative Email')) + submit = SubmitField() diff --git a/lenticular_cloud/model.py b/lenticular_cloud/model.py index b1e2571..3defc62 100644 --- a/lenticular_cloud/model.py +++ b/lenticular_cloud/model.py @@ -318,3 +318,10 @@ class Group(EntryBase): object_classes = ["top"] fullname = AttrDef("cn") + + +class UserSignUp(db.Model): + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String, nullable=False) + password = db.Column(db.String, nullable=False) + alternative_email = db.Column(db.String) diff --git a/lenticular_cloud/views/auth.py b/lenticular_cloud/views/auth.py index 65cdfff..c15c55c 100644 --- a/lenticular_cloud/views/auth.py +++ b/lenticular_cloud/views/auth.py @@ -13,9 +13,10 @@ import logging from urllib.parse import urlparse from base64 import b64decode, b64encode import http +import crypt -from ..model import db, User, SecurityUser -from ..form.auth import ConsentForm, LoginForm +from ..model import db, User, SecurityUser, UserSignUp +from ..form.auth import ConsentForm, LoginForm, RegistrationForm from ..auth_providers import AUTH_PROVIDER_LIST @@ -118,3 +119,16 @@ def logout(): return redirect(resp.redirect_to) + +@auth_views.route("/sign_up", methods=["GET", "POST"]) +def sign_up(): + form = RegistrationForm() + if form.validate_on_submit(): + user = UserSignUp() + user.username = form.data['username'] + user.password = crypt.crypt(form.data['password']) + user.alternative_email = form.data['alternative_email'] + db.session.add(user) + db.session.commit() + + return render_template('auth/sign_up.html.j2', form=form) diff --git a/templates/auth/login.html.j2 b/templates/auth/login.html.j2 index 11516c7..2b8e5d1 100644 --- a/templates/auth/login.html.j2 +++ b/templates/auth/login.html.j2 @@ -7,5 +7,7 @@ {{ render_form(form) }} +Sign Up + {% endblock %} diff --git a/templates/auth/sign_up.html.j2 b/templates/auth/sign_up.html.j2 new file mode 100644 index 0000000..5a19695 --- /dev/null +++ b/templates/auth/sign_up.html.j2 @@ -0,0 +1,11 @@ + +{% extends 'auth/base.html.j2' %} + +{% block title %}{{ gettext('Sign Up') }}{% endblock %} + +{% block content %} + +{{ render_form(form) }} + +{% endblock %} +