diff --git a/clients/views.py b/clients/views.py index 91ea44a..d28f1ee 100644 --- a/clients/views.py +++ b/clients/views.py @@ -1,3 +1,46 @@ -from django.shortcuts import render +from django.views.generic import CreateView, UpdateView +from django.urls import reverse_lazy -# Create your views here. +from .models import ClientProfile + +from localauth.mixins import LoginRequiredMixin + +class ClientRegistrationView(LoginRequiredMixin, CreateView): + model = ClientProfile + exclude = ["user"] + template_name = "clients/signup.html" + fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] + + def form_valid(self, form): + form.instance.user = self.request.user + return super().form_valid(form) + + def get_success_url(self): + return reverse_lazy("clients:profile") + + def get_initial(self): + try: + partner = self.request.user.partnerprofile + return { + "company": partner.company, + "vat_id": partner.vat_id, + "first_name": partner.first_name, + "last_name": partner.last_name, + "street": partner.street, + "city": partner.city, + "zip": partner.zip, + "state": partner.state, + "country": partner.country + } + + except: + return {} + +class ClientProfileView(LoginRequiredMixin, UpdateView): + model = ClientProfile + exclude = ["user"] + template_name = "clients/profile.html" + fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] + + def get_success_url(self): + return reverse_lazy("clients:profile") \ No newline at end of file diff --git a/localauth/forms.py b/localauth/forms.py index 591b16d..5d4c726 100644 --- a/localauth/forms.py +++ b/localauth/forms.py @@ -1,7 +1,11 @@ from django.contrib.auth.forms import UserCreationForm +from django import forms from .models import User +from partners.models import PartnerProfile +from clients.models import ClientProfile + class RegistrationForm(UserCreationForm): def __init__(self, *args, **kwargs): kwargs.pop("request") @@ -9,4 +13,13 @@ class RegistrationForm(UserCreationForm): class Meta: model = User - fields = ["email", "password1", "password2"] \ No newline at end of file + fields = ["email", "password1", "password2"] + +class VerificationForm(forms.Form): + def get_choices(): + for client in ClientProfile.objects.filter(verified=False): + yield ("C%i" % client.id, "C%i – %s" % (client.id, client.full_name)) + for partner in PartnerProfile.objects.filter(verified=False): + yield ("P%i" % partner.id, "P%i – %s" % (partner.id, partner.full_name)) + + profile = forms.ChoiceField(choices=get_choices) \ No newline at end of file diff --git a/localauth/models.py b/localauth/models.py index 45bb494..73d5cc4 100644 --- a/localauth/models.py +++ b/localauth/models.py @@ -71,6 +71,15 @@ class Profile(models.Model): zip = models.CharField(max_length=16) state = models.CharField(max_length=64) country = CountryField() + verified = models.BooleanField(default=False) + enabled = models.BooleanField(default=True) + + @property + def full_name(self): + if self.company: + return self.company + else: + return " ".join([self.first_name, self.last_name]) class Meta: abstract = True \ No newline at end of file diff --git a/localauth/urls.py b/localauth/urls.py index a0c90c5..63a3e69 100644 --- a/localauth/urls.py +++ b/localauth/urls.py @@ -1,6 +1,6 @@ from django.urls import path -from .views import LoginView, LogoutView, RegistrationView +from .views import LoginView, LogoutView, RegistrationView, VerificationView app_name = "localauth" @@ -8,4 +8,5 @@ urlpatterns = [ path('login/', LoginView.as_view(), name="login"), path('logout/', LogoutView.as_view(), name="logout"), path('register/', RegistrationView.as_view(), name="register"), + path('verify/', VerificationView.as_view(), name="verify"), ] \ No newline at end of file diff --git a/localauth/views.py b/localauth/views.py index 2a54972..99d0dd2 100644 --- a/localauth/views.py +++ b/localauth/views.py @@ -3,9 +3,15 @@ from django.http.response import HttpResponseRedirect from django.contrib.auth import login from django.shortcuts import resolve_url from django.conf import settings +from django.views.generic import FormView +from django.contrib import messages -from .forms import RegistrationForm +from .forms import RegistrationForm, VerificationForm from .models import User +from .mixins import SuperUserRequiredMixin + +from clients.models import ClientProfile +from partners.models import PartnerProfile class LoginView(Login): template_name = "localauth/register.html" @@ -18,9 +24,26 @@ class RegistrationView(Login): template_name = "localauth/register.html" def form_valid(self, form): - user = User.objects.create_user(form.cleaned_data["email"], form.cleaned_data["password1"]) + user = User.objects.create_user(form.cleaned_data["email"]) + user.set_password(form.cleaned_data["password1"]) login(self.request, user) + + messages.success(self.request, "Erfolgreich registriert!") return HttpResponseRedirect(self.get_success_url()) def get_default_redirect_url(self): - return resolve_url(self.next_page or settings.REGISTER_REDIRECT_URL) \ No newline at end of file + return resolve_url(self.next_page or settings.REGISTER_REDIRECT_URL) + +class VerificationView(SuperUserRequiredMixin, FormView): + form_class = VerificationForm + template_name = "localauth/verify.html" + + def form_valid(self, form): + pid = form.cleaned_data["profile"] + ptype = ClientProfile if profile.startswith("C") else PartnerProfile + pobj = ptype.objects.get(id=profile[1:]) + pobj.update(verified=True) + + messages.success(self.request, "Benutzer %s bestätigt!" % pobj.full_name) + + return HttpResponseRedirect(resolve_url("localauth:verify")) \ No newline at end of file diff --git a/localsettings.dist.py b/localsettings.dist.py index e69de29..82c13f3 100644 --- a/localsettings.dist.py +++ b/localsettings.dist.py @@ -0,0 +1,19 @@ +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'longsecretstring!' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ["*"] + +# PostgreSQL server settings + +DB_HOST = "postgresql.server" +DB_PORT = 5432 +DB_NAME = "postgresql_database" +DB_USER = "postgresql_username" +DB_PASS = "postgresql_password" + +# Email address of system administrator + +ADMIN_EMAIL = "recipient@example.com" \ No newline at end of file diff --git a/partners/urls.py b/partners/urls.py new file mode 100644 index 0000000..4ed0051 --- /dev/null +++ b/partners/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from .views import PartnerRegistrationView, PartnerProfileView + +app_name = "partners" + +urlpatterns = [ + path('register/', PartnerRegistrationView.as_view(), name="register"), + path('profile/', PartnerProfileView.as_view(), name="profile"), +] \ No newline at end of file diff --git a/partners/views.py b/partners/views.py index 18d4b60..1509d76 100644 --- a/partners/views.py +++ b/partners/views.py @@ -1,4 +1,5 @@ -from django.views.generic import CreateView +from django.views.generic import CreateView, UpdateView +from django.urls import reverse_lazy from .models import PartnerProfile @@ -6,4 +7,44 @@ from localauth.mixins import LoginRequiredMixin class PartnerRegistrationView(LoginRequiredMixin, CreateView): model = PartnerProfile - exclude = ["user"] \ No newline at end of file + exclude = ["user"] + template_name = "partners/signup.html" + fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] + + def form_valid(self, form): + form.instance.user = self.request.user + return super().form_valid(form) + + def get_success_url(self): + return reverse_lazy("partners:profile") + + def get_initial(self): + try: + client = self.request.user.clientprofile + + return { + "company": client.company, + "vat_id": client.vat_id, + "first_name": client.first_name, + "last_name": client.last_name, + "street": client.street, + "city": client.city, + "zip": client.zip, + "state": client.state, + "country": client.country + } + + except: + return {} + +class PartnerProfileView(LoginRequiredMixin, UpdateView): + model = PartnerProfile + exclude = ["user"] + template_name = "partners/profile.html" + fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] + + def get_success_url(self): + return reverse_lazy("partners:profile") + + def get_object(self, queryset=None): + return self.request.user.partnerprofile \ No newline at end of file diff --git a/payment/paypal/urls.py b/payment/paypal/urls.py index 690b131..c30a5ed 100644 --- a/payment/paypal/urls.py +++ b/payment/paypal/urls.py @@ -1,4 +1,6 @@ from django.urls import path +app_name = "paypal" + urlpatterns = [ ] diff --git a/payment/sepa/urls.py b/payment/sepa/urls.py index 05726e9..5a2a785 100644 --- a/payment/sepa/urls.py +++ b/payment/sepa/urls.py @@ -2,6 +2,8 @@ from django.urls import path from .views import SepaApplyPaymentView +app_name = "sepa" + urlpatterns = [ - path('apply/', SepaApplyPaymentView.as_view(), name="superuser_apply"), + path('apply/', SepaApplyPaymentView.as_view(), name="apply"), ] diff --git a/payment/urls.py b/payment/urls.py index 104bd3d..4eb3110 100644 --- a/payment/urls.py +++ b/payment/urls.py @@ -1,5 +1,7 @@ from django.urls import path, include +app_name = "payment" + urlpatterns = [ path('gateways/paypal/', include("payment.paypal.urls"), name="paypal"), path('gateways/sepa/', include("payment.sepa.urls"), name="sepa"), diff --git a/static/frontend/images/logo.png b/static/frontend/images/logo.png new file mode 100644 index 0000000..602fb82 Binary files /dev/null and b/static/frontend/images/logo.png differ diff --git a/templates/frontend/base.html b/templates/frontend/base.html index 2b3f39c..e9a79ed 100644 --- a/templates/frontend/base.html +++ b/templates/frontend/base.html @@ -13,7 +13,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -87,7 +87,9 @@
Sie haben Interesse, mit Ihrem Hotel an JourneyJoker teilzunehmen?
+Füllen Sie einfach folgendes Formular aus, um sich zu registrieren.
+Nach einer kurzen Überprüfung Ihrer Daten können Sie dann Ihre Unterkunft in unserem System anlegen und schon kann es losgehen!
+ +