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 a6ce5f8..3ecc0fc 100644 Binary files a/PDMI/db.sqlite3 and b/PDMI/db.sqlite3 differ 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 %}