Compare commits

...

8 commits

9 changed files with 109 additions and 38 deletions

View file

@ -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")

View file

@ -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()

View file

@ -20,6 +20,11 @@
<div id="app">
{% include 'includes/sidebar.html' %}
<div id="main">
<header class="mb-3">
<a href="#" class="burger-btn d-block d-xl-none">
<i class="bi bi-justify fs-3"></i>
</a>
</header>
<div class="page-heading">
<h3>
{% block page_title %}

View file

@ -1,23 +1,18 @@
{% load i18n %}
<div class="col-12">
<div class="form-group{% with classes=field.css_classes %}{% if classes %} {{ classes }}{% endif %}{% endwith %}{% if errors %} is-invalid{% endif %}">
<div class="form-group{% if field.field.required %} mandatory{% endif %}{% if errors %} is-invalid{% endif %}">
{% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %}
<label for="{{ field.auto_id }}" class="{{ label_class }}">
{{ field.label }}
{% if not field.field.required %}
<span class="optional">{% translate "Optional" %}</span>
{% endif %}
</label>
<label for="{{ field.auto_id }}" class="form-label">{{ field.label }}</label>
{% endif %}
{% if field.use_fieldset %}
<fieldset {% if field.help_text and field.auto_id and "aria-describedby" not in field.field.widget.attrs %} aria-describedby="{{ field.auto_id }}_helptext"{% endif %}>
{% endif %}
{{ field }}
{% if field.field.widget.input_type == "checkbox" and not field.field.widget.allow_multiple_selected %}
<label for="{{ field.auto_id }}">{{ field.label }}</label>
<label for="{{ field.auto_id }}" class="form-check-label form-label">{{ field.label }}</label>
{% endif %}
{% if field.use_fieldset %}</fieldset>{% endif %}
{% for text in field.errors %}<div class="text-danger">{{ text }}</div>{% endfor %}
{% for text in field.errors %}<div class="invalid-feedback">{{ text }}</div>{% endfor %}
{% if field.help_text %}
<small class="form-text text-muted"
{% if field.auto_id %}id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</small>

View file

@ -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 @@
<h4 class="card-title">{% translate "Account" %}</h4>
</div>
{% endblock %}
{% block card_content %}
<p>
{% 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 %}
</p>
<div class="table-responsive">
<table class="table table-lg">
<tbody>
<tr>
<th>{% translate "E-mail" %}</th>
<td>{{ request.user.email }}</td>
</tr>
<tr>
<th>{% translate "First name" %}</th>
<td>{{ request.user.first_name }}</td>
</tr>
<tr>
<th>{% translate "Last name" %}</th>
<td>{{ request.user.last_name }}</td>
</tr>
</tbody>
</table>
</div>
{% endblock card_content %}
{% block content %}
<section>
<div class="row match-height">
<div class="col-md-6 col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">{% translate "Profile" %}</h4>
</div>
<div class="card-content">
<div class="card-body">
<div class="table-responsive">
<table class="table table-lg">
<tbody>
<tr>
<th>{% translate "E-mail" %}</th>
<td>{{ request.user.email }}</td>
</tr>
<tr>
<th>{% translate "First name" %}</th>
<td>{{ request.user.first_name }}</td>
</tr>
<tr>
<th>{% translate "Last name" %}</th>
<td>{{ request.user.last_name }}</td>
</tr>
<tr>
<th>{% translate "Company" %}</th>
<td>{{ request.user.company }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6 col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">{% translate "Account" %}</h4>
</div>
<div class="card-content">
<div class="card-body">
<p>
{% blocktranslate trimmed %}
You are logged in with your VSHN user account. Change your password and other account data here:
{% endblocktranslate %}
</p>
<a href="{{ account_href }}"
class="btn btn-warning btn-lg icon icon-left">
<img src="{% static 'img/keycloak.svg' %}" style="height: 30px">
<span class="mx-1">{% translate "VSHN Account" %}</span>
</a>
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock content %}

View file

@ -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

View file

@ -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):

View file

@ -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`

View file

@ -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