From a414ce14920d55a5c48ec4111957c680625d6182 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 1 Jul 2022 18:21:29 +0200 Subject: implement account registration --- development.ini | 2 + fietsboek/__init__.py | 4 ++ fietsboek/models/user.py | 4 +- fietsboek/routes.py | 1 + fietsboek/static/fietsboek.js | 7 +++ fietsboek/templates/create_account.jinja2 | 45 +++++++++++++++++++ fietsboek/templates/layout.jinja2 | 5 +++ fietsboek/views/account.py | 72 +++++++++++++++++++++++++++++++ fietsboek/views/default.py | 5 +++ 9 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 fietsboek/templates/create_account.jinja2 create mode 100644 fietsboek/views/account.py diff --git a/development.ini b/development.ini index 153e684..a93c838 100644 --- a/development.ini +++ b/development.ini @@ -27,6 +27,8 @@ retry.attempts = 3 email.from = fietsboek@kingdread.de email.smtp_url = debug://localhost:1025 +enable_account_registration = true + session_key = hklurha7ildshgfljhrbuajelghug # By default, the toolbar only appears for clients from IP addresses diff --git a/fietsboek/__init__.py b/fietsboek/__init__.py index 1688dde..80b6c7d 100644 --- a/fietsboek/__init__.py +++ b/fietsboek/__init__.py @@ -4,6 +4,7 @@ For more information, see the README or the included documentation. """ from pyramid.config import Configurator from pyramid.session import SignedCookieSessionFactory +from pyramid.settings import asbool from .security import SecurityPolicy @@ -15,6 +16,9 @@ def main(global_config, **settings): if 'session_key' not in settings: raise ValueError("Please set a session signing key (session_key) in your settings!") + settings['enable_account_registration'] = asbool( + settings.get('enable_account_registration', 'false')) + my_session_factory = SignedCookieSessionFactory(settings['session_key']) with Configurator(settings=settings) as config: config.include('pyramid_jinja2') diff --git a/fietsboek/models/user.py b/fietsboek/models/user.py index 1c6475e..cc06225 100644 --- a/fietsboek/models/user.py +++ b/fietsboek/models/user.py @@ -91,8 +91,8 @@ class User(Base): password = Column(LargeBinary) salt = Column(LargeBinary) email = Column(Text) - is_admin = Column(Boolean) - is_verified = Column(Boolean) + is_admin = Column(Boolean, default=False) + is_verified = Column(Boolean, default=False) tracks = relationship('Track', back_populates='owner') tagged_tracks = relationship('Track', secondary='track_people_assoc', diff --git a/fietsboek/routes.py b/fietsboek/routes.py index 34917b6..b0ee3c4 100644 --- a/fietsboek/routes.py +++ b/fietsboek/routes.py @@ -8,6 +8,7 @@ def includeme(config): config.add_route('password-reset', '/password-reset') config.add_route('use-token', '/token/{uuid}') + config.add_route('create-account', '/create-account') config.add_route('upload', '/upload') config.add_route('preview', '/preview/{id}.gpx') diff --git a/fietsboek/static/fietsboek.js b/fietsboek/static/fietsboek.js index 26a0902..5a26cbc 100644 --- a/fietsboek/static/fietsboek.js +++ b/fietsboek/static/fietsboek.js @@ -40,6 +40,13 @@ function checkPasswordValidity(main, repeat) { } } +function checkNameValidity(name) { + let name_field = document.querySelector(name); + if (name_field.value.length == 0) { + name_field.setCustomValidity('Needs a name'); + } +} + document.addEventListener('DOMContentLoaded', function(event) { /* Enable the "Add tag" button */ let $ = (selector) => document.querySelector(selector); diff --git a/fietsboek/templates/create_account.jinja2 b/fietsboek/templates/create_account.jinja2 new file mode 100644 index 0000000..cf52203 --- /dev/null +++ b/fietsboek/templates/create_account.jinja2 @@ -0,0 +1,45 @@ +{% extends "layout.jinja2" %} +{% block content %} +
+

{{ _("page.create_account.title") }}

+
+
+ +
+ +
+ {{ _("page.create_account.email_invalid") }} +
+
+
+
+ +
+ +
+ {{ _("page.create_account.name_invalid") }} +
+
+
+
+ +
+ +
+ {{ _("page.create_account.password_invalid") }} +
+
+
+
+ +
+ +
+ {{ _("page.create_account.password_must_match") }} +
+
+
+ +
+
+{% endblock %} diff --git a/fietsboek/templates/layout.jinja2 b/fietsboek/templates/layout.jinja2 index 4c6b1cc..6caf666 100644 --- a/fietsboek/templates/layout.jinja2 +++ b/fietsboek/templates/layout.jinja2 @@ -42,6 +42,11 @@ + {% if request.registry.settings.get('enable_account_registration') %} + + {% endif %} {% else %}