diff --git a/src/servala/core/models/organization.py b/src/servala/core/models/organization.py index fec3fa4..0419175 100644 --- a/src/servala/core/models/organization.py +++ b/src/servala/core/models/organization.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.db import models from django.utils.translation import gettext_lazy as _ @@ -33,6 +34,18 @@ class Organization(ServalaModelMixin, models.Model): user=user, organization=self, role=OrganizationRole.OWNER ) + @classmethod + def create_organization(cls, instance, owner): + try: + instance.origin + except Exception: + instance.origin = OrganizationOrigin.objects.get( + pk=settings.SERVALA_DEFAULT_ORIGIN + ) + instance.save() + instance.set_owner(owner) + return instance + class Meta: verbose_name = _("Organization") verbose_name_plural = _("Organizations") diff --git a/src/servala/frontend/forms/auth.py b/src/servala/frontend/forms/auth.py new file mode 100644 index 0000000..3bd8a89 --- /dev/null +++ b/src/servala/frontend/forms/auth.py @@ -0,0 +1,11 @@ +from django.forms import Form + +from servala.core.models.user import User + + +class ServalaSignupForm(Form): + company = User._meta.get_field("company").formfield() + + def signup(self, request, user): + user.company = self.cleaned_data.get("company") + user.save() diff --git a/src/servala/frontend/templates/frontend/base.html b/src/servala/frontend/templates/frontend/base.html index 80dd44e..4aa4da7 100644 --- a/src/servala/frontend/templates/frontend/base.html +++ b/src/servala/frontend/templates/frontend/base.html @@ -20,6 +20,11 @@
{% include 'includes/sidebar.html' %}
+
+ + + +

{% block page_title %} diff --git a/src/servala/frontend/templates/frontend/forms/vertical_field.html b/src/servala/frontend/templates/frontend/forms/vertical_field.html index 22562d0..a2457d9 100644 --- a/src/servala/frontend/templates/frontend/forms/vertical_field.html +++ b/src/servala/frontend/templates/frontend/forms/vertical_field.html @@ -1,23 +1,18 @@ {% load i18n %}
-
+
{% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %} - + {% endif %} {% if field.use_fieldset %}
{% endif %} {{ field }} {% if field.field.widget.input_type == "checkbox" and not field.field.widget.allow_multiple_selected %} - + {% endif %} {% if field.use_fieldset %}
{% endif %} - {% for text in field.errors %}
{{ text }}
{% endfor %} + {% for text in field.errors %}
{{ text }}
{% endfor %} {% if field.help_text %} {{ field.help_text|safe }} diff --git a/src/servala/frontend/templates/frontend/profile.html b/src/servala/frontend/templates/frontend/profile.html index a14d730..9532e96 100644 --- a/src/servala/frontend/templates/frontend/profile.html +++ b/src/servala/frontend/templates/frontend/profile.html @@ -1,5 +1,5 @@ {% extends "frontend/base.html" %} -{% load i18n %} +{% load i18n static %} {% block html_title %} {% block page_title %} {% translate "Profile" %} @@ -10,28 +10,63 @@

{% translate "Account" %}

{% endblock %} -{% block card_content %} -

- {% blocktranslate trimmed %} - You are logged in with your VSHN user account. You will be able to change your password and other settings here in the future. - {% endblocktranslate %} -

-
- - - - - - - - - - - - - - - -
{% translate "E-mail" %}{{ request.user.email }}
{% translate "First name" %}{{ request.user.first_name }}
{% translate "Last name" %}{{ request.user.last_name }}
-
-{% endblock card_content %} +{% block content %} +
+
+
+
+
+

{% translate "Profile" %}

+
+
+
+
+ + + + + + + + + + + + + + + + + + + +
{% translate "E-mail" %}{{ request.user.email }}
{% translate "First name" %}{{ request.user.first_name }}
{% translate "Last name" %}{{ request.user.last_name }}
{% translate "Company" %}{{ request.user.company }}
+
+
+
+
+
+
+
+
+

{% translate "Account" %}

+
+
+
+

+ {% blocktranslate trimmed %} + You are logged in with your VSHN user account. Change your password and other account data here: + {% endblocktranslate %} +

+ + + {% translate "VSHN Account" %} + +
+
+
+
+
+
+{% endblock content %} diff --git a/src/servala/frontend/views/generic.py b/src/servala/frontend/views/generic.py index 8b0271e..3b2196b 100644 --- a/src/servala/frontend/views/generic.py +++ b/src/servala/frontend/views/generic.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.views.generic import TemplateView @@ -7,3 +8,14 @@ class IndexView(TemplateView): class ProfileView(TemplateView): template_name = "frontend/profile.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + keycloak_server_url = settings.SOCIALACCOUNT_PROVIDERS["openid_connect"][ + "APPS" + ][0]["settings"]["server_url"] + account_url = keycloak_server_url.replace( + "/.well-known/openid-configuration", "/account" + ) + context["account_href"] = account_url + return context diff --git a/src/servala/frontend/views/organization.py b/src/servala/frontend/views/organization.py index 9bc1397..020d28b 100644 --- a/src/servala/frontend/views/organization.py +++ b/src/servala/frontend/views/organization.py @@ -8,8 +8,7 @@ class OrganizationCreateView(FormView): template_name = "frontend/organizations/create.html" def form_valid(self, form): - form.save() - form.instance.set_owner(self.request.user) + form.instance.create_organization(form.instance, owner=self.request.user) return super().form_valid(form) def get_success_url(self): diff --git a/src/servala/settings.py b/src/servala/settings.py index 36d7673..0df8059 100644 --- a/src/servala/settings.py +++ b/src/servala/settings.py @@ -164,6 +164,7 @@ ACCOUNT_USER_MODEL_USERNAME_FIELD = None ACCOUNT_UNIQUE_EMAIL = True ACCOUNT_LOGIN_METHODS = {"email"} ACCOUNT_SIGNUP_FIELDS = ["email*", "password1*", "password2*"] +ACCOUNT_SIGNUP_FORM_CLASS = "servala.frontend.forms.auth.ServalaSignupForm" AUTHENTICATION_BACKENDS = [ # Needed to login by username in Django admin, regardless of `allauth` diff --git a/src/servala/urls.py b/src/servala/urls.py index d1d40ec..c37e288 100644 --- a/src/servala/urls.py +++ b/src/servala/urls.py @@ -14,12 +14,12 @@ admin.site.index_title = _("Dashboard") admin.site.login = secure_admin_login(admin.site.login) urlpatterns = [ - path("admin/", admin.site.urls), path("", include((urls, "servala.frontend"), namespace="frontend")), # This adds the allauth urls to the project: # - accounts/keycloak/login/ # - accounts/keycloak/login/callback/ path("accounts/", include("allauth.urls")), + path("admin/", admin.site.urls), ] # Serve static and media files in development