From 800318c2714685ed547f5c2326604f158f7f0904 Mon Sep 17 00:00:00 2001 From: HugoNeveux Date: Tue, 21 Apr 2020 20:13:01 +0200 Subject: [PATCH] Working register and login in store app with django modal forms --- PDMI/PDMI/settings.py | 11 +++++ PDMI/PDMI/urls.py | 2 +- PDMI/db.sqlite3 | Bin 131072 -> 131072 bytes PDMI/front/templates/front/index.html | 25 ----------- PDMI/store/forms.py | 14 ++++++ PDMI/store/templates/store/index.html | 5 +++ PDMI/store/templates/store/login.html | 41 +++++++++++++++++ PDMI/store/templates/store/modal.html | 5 +++ PDMI/store/templates/store/signup.html | 38 ++++++++++++++++ PDMI/store/templates/store/store-navbar.html | 45 +++++++++++++++---- PDMI/store/urls.py | 7 ++- PDMI/store/views.py | 15 ++++++- PDMI/templates/base/base.html | 5 ++- 13 files changed, 176 insertions(+), 37 deletions(-) create mode 100644 PDMI/store/forms.py create mode 100644 PDMI/store/templates/store/login.html create mode 100644 PDMI/store/templates/store/modal.html create mode 100644 PDMI/store/templates/store/signup.html diff --git a/PDMI/PDMI/settings.py b/PDMI/PDMI/settings.py index 0590648..c500787 100644 --- a/PDMI/PDMI/settings.py +++ b/PDMI/PDMI/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os +from django.urls import reverse_lazy # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -40,6 +41,8 @@ INSTALLED_APPS = [ 'store', 'doc', 'front', + 'bootstrap_modal_forms', + 'widget_tweaks', ] MIDDLEWARE = [ @@ -123,3 +126,11 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' + +# Logout redirect url + +LOGOUT_REDIRECT_URL = reverse_lazy('store_front_page') + +# Login redirect url + +LOGIN_REDIRECT_URL = reverse_lazy('store_front_page') diff --git a/PDMI/PDMI/urls.py b/PDMI/PDMI/urls.py index 3e378cd..df3e170 100644 --- a/PDMI/PDMI/urls.py +++ b/PDMI/PDMI/urls.py @@ -21,5 +21,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path('', include('front.urls'), name='front'), path('store/', include('store.urls'), name='store'), - path('doc/', include('doc.urls'), name='doc') + path('doc/', include('doc.urls'), name='doc'), ] diff --git a/PDMI/db.sqlite3 b/PDMI/db.sqlite3 index a6ce5f8932cb6f77ae656ec716f356f911c90102..3ecc0fcff5772d1d53fc86e4eda6479f407d2d98 100644 GIT binary patch delta 891 zcmaiy&u`LT9L8I46I6J0X7Mm}Gor?jLHo946thGItZBD)gOpNw*(kqCp@18ug_r<~ zH!m6wCLTR|S(X?RZ##Qf)WZ%tnB7eF2YAz>)97LGoAj{+D-F!Ve^$M8;T?BjupTT?31#iI9-H{4jbi;wW2!c#G`fGfb+_PxG>}VV2c6rNn zZNg2UFK=n+)xA$)9GgV_`-p#kcl6Fb*m;0X@J}Y<4V&y#3w5$&nI%*0*)#>~9kSV6 zAlfQvv}h&CX#&I5^0_o7h^!^Rl+7ozkTX7FZ9%N!YmSE(t9?apFR%?- zE6JIbOh|o2<|>6;y0%thZMJ6BWVk%QON>@2$wH&ppq=HymXf3Dtlp|AOj}cpQg_u5 zx@t4iE96)+FH2YOBTtz$Z>T=*Xlywk&(3&Myd;Xv9Ba0BQK^&C6~3?CbkGMh|Ob^bLQ}9 z42Llo3DHp+k_#6c>L@ruz|r27&5z*DZ8z`zA4}gJ+IC;|xcr9*kooOOU*_Y|LZ4jK!+Poz z-|yg4d^ic|sAg7MV?~A8b>2Pg9WNX+{yw{N@b&;bH#dobV+0&K?n7|%hCA*(`#paEyXyo* delta 124 zcmZo@;Am*zm>|t4HBrWyQEFqtB6*<|3~c;m4E!(ouki2YFXNxZ-@UOhiGOmLzKR+T z53@W+VrfZ6d}(oN5d#B*Fc2dHaaLwy#_5U~jKZ5Q>l+$uW_j>Oe$fGeO$S&6HnVK_ RBj0pj+W|%vpm@U{egGlEBd7oX diff --git a/PDMI/front/templates/front/index.html b/PDMI/front/templates/front/index.html index 167974b..6cad4f8 100644 --- a/PDMI/front/templates/front/index.html +++ b/PDMI/front/templates/front/index.html @@ -24,31 +24,6 @@
- - -
{% for i in '123'|make_list %}
diff --git a/PDMI/store/forms.py b/PDMI/store/forms.py new file mode 100644 index 0000000..4d86765 --- /dev/null +++ b/PDMI/store/forms.py @@ -0,0 +1,14 @@ +from django.contrib.auth.forms import UserCreationForm, AuthenticationForm +from django.contrib.auth.models import User +from bootstrap_modal_forms.mixins import PopRequestMixin, CreateUpdateAjaxMixin + +class CustomUserCreationForm(PopRequestMixin, CreateUpdateAjaxMixin, + UserCreationForm): + class Meta: + model = User + fields = ['username', 'email', 'password1', 'password2'] + +class CustomAuthenticationForm(AuthenticationForm): + class Meta: + model = User + fields = ['username', 'password'] diff --git a/PDMI/store/templates/store/index.html b/PDMI/store/templates/store/index.html index f464f87..6da5174 100644 --- a/PDMI/store/templates/store/index.html +++ b/PDMI/store/templates/store/index.html @@ -80,4 +80,9 @@
+ + + +{% include "store/modal.html" %} + {% endblock body %} diff --git a/PDMI/store/templates/store/login.html b/PDMI/store/templates/store/login.html new file mode 100644 index 0000000..853f63b --- /dev/null +++ b/PDMI/store/templates/store/login.html @@ -0,0 +1,41 @@ +{% load widget_tweaks %} + +
+ {% csrf_token %} + + + + + + + +
diff --git a/PDMI/store/templates/store/modal.html b/PDMI/store/templates/store/modal.html new file mode 100644 index 0000000..37f2fee --- /dev/null +++ b/PDMI/store/templates/store/modal.html @@ -0,0 +1,5 @@ + diff --git a/PDMI/store/templates/store/signup.html b/PDMI/store/templates/store/signup.html new file mode 100644 index 0000000..b729526 --- /dev/null +++ b/PDMI/store/templates/store/signup.html @@ -0,0 +1,38 @@ +{% load widget_tweaks %} + +
+ {% csrf_token %} + + + + + + + +
diff --git a/PDMI/store/templates/store/store-navbar.html b/PDMI/store/templates/store/store-navbar.html index 23b92eb..d908bca 100644 --- a/PDMI/store/templates/store/store-navbar.html +++ b/PDMI/store/templates/store/store-navbar.html @@ -1,11 +1,40 @@ {% extends "base/navbar.html" %} {% block 'navbar-right' %} - +{% if user.is_authenticated %} + +{% else %} + +{% endif %} {% endblock 'navbar-right' %} diff --git a/PDMI/store/urls.py b/PDMI/store/urls.py index f63c3c6..f531c91 100644 --- a/PDMI/store/urls.py +++ b/PDMI/store/urls.py @@ -15,7 +15,12 @@ Including another URLconf """ from django.urls import path from django.views.generic import TemplateView +from django.contrib.auth.views import LoginView, LogoutView +from . import views urlpatterns = [ - path('', TemplateView.as_view(template_name="store/index.html"), name='store_front_page'), + path('', TemplateView.as_view(template_name='store/index.html'), name='store_front_page'), + path('login/', views.CustomLoginView.as_view(), name='login'), + path('signup/', views.SignUpView.as_view(), name='signup'), + path('logout/', LogoutView.as_view()) ] diff --git a/PDMI/store/views.py b/PDMI/store/views.py index 91ea44a..eda8f31 100644 --- a/PDMI/store/views.py +++ b/PDMI/store/views.py @@ -1,3 +1,16 @@ from django.shortcuts import render +from django.urls import reverse_lazy +from bootstrap_modal_forms.generic import BSModalCreateView, BSModalLoginView +from .forms import CustomUserCreationForm, CustomAuthenticationForm -# Create your views here. +class SignUpView(BSModalCreateView): + form_class = CustomUserCreationForm + template_name = 'store/signup.html' + success_message = 'Success: Sign up succeeded. You can now Log in.' + success_url = reverse_lazy('store_front_page') + +class CustomLoginView(BSModalLoginView): + authentication_form = CustomAuthenticationForm + template_name = 'store/login.html' + success_message = 'Success: You were successfully logged in.' + extra_content = dict(success_url=reverse_lazy('index')) diff --git a/PDMI/templates/base/base.html b/PDMI/templates/base/base.html index 262d53b..1d5bf8f 100644 --- a/PDMI/templates/base/base.html +++ b/PDMI/templates/base/base.html @@ -15,7 +15,10 @@ integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> - + + + + {% block navbar %}