From 7f513d05b2d7206f47fb24f2f5a48fa823c3bba0 Mon Sep 17 00:00:00 2001 From: marcsello Date: Sat, 28 Nov 2020 00:44:52 +0100 Subject: [PATCH] Fixed asking for username --- src/app.py | 4 ++-- src/templates/security/register_user.html | 1 + src/utils/__init__.py | 2 +- src/utils/security.py | 17 ++++++++++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/app.py b/src/app.py index fddc355..1ec11c5 100644 --- a/src/app.py +++ b/src/app.py @@ -8,7 +8,7 @@ from healthcheck import HealthCheck from flask_cors import CORS from utils import Config -from utils import health_database_status, security, user_datastore +from utils import health_database_status, init_security_real_good from views import ItemView, ProfileView, UploadView, IndexView from models import db @@ -39,7 +39,7 @@ app.config.from_object(Config) health = HealthCheck() db.init_app(app) -security.init_app(app, user_datastore) +init_security_real_good(app) CORS(app) for view in [ItemView, ProfileView, UploadView, IndexView]: diff --git a/src/templates/security/register_user.html b/src/templates/security/register_user.html index 35d1d64..79ad3f0 100644 --- a/src/templates/security/register_user.html +++ b/src/templates/security/register_user.html @@ -7,6 +7,7 @@
{{ register_user_form.hidden_tag() }} + {{ render_field_with_errors(register_user_form.name) }} {{ render_field_with_errors(register_user_form.email) }} {{ render_field_with_errors(register_user_form.password) }} {% if register_user_form.password_confirm %} diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 0bbc965..2d3f11c 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,3 +1,3 @@ from .healthchecks import health_database_status -from .security import security, user_datastore +from .security import security, init_security_real_good from .config import Config \ No newline at end of file diff --git a/src/utils/security.py b/src/utils/security.py index 9de9b8e..3602824 100644 --- a/src/utils/security.py +++ b/src/utils/security.py @@ -1,5 +1,11 @@ #!/usr/bin/env python3 +from flask_security import Security, SQLAlchemyUserDatastore +from flask_security.forms import RegisterForm, Required +from wtforms import StringField + +from models import db, User, Role + """ Flask-Security """ @@ -9,9 +15,14 @@ __copyright__ = "Copyright 2020, UnstableVortex Team" __module_name__ = "security" __version__text__ = "1" -from flask_security import Security, SQLAlchemyUserDatastore -from models import db, User, Role +class ExtendedRegisterForm(RegisterForm): + name = StringField('Username', [Required()]) + user_datastore = SQLAlchemyUserDatastore(db, User, Role) -security = Security() +security = Security() # Will be initiated at init_app + + +def init_security_real_good(app): + security.init_app(app, datastore=user_datastore, register_form=ExtendedRegisterForm)