From 577d4bc796c6ea07377183bfbe0fd2c031b4a875 Mon Sep 17 00:00:00 2001 From: Krittipoom Date: Tue, 3 Oct 2023 13:44:15 +0700 Subject: [PATCH] add guest user --- code/ddice_online_shop/settings.py | 4 ++++ code/ddice_online_shop/urls.py | 3 +++ code/main/views.py | 5 +++++ code/requirements.txt | 3 ++- code/static/css/main.css | 3 +-- code/templates/base.html | 9 +++------ 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/code/ddice_online_shop/settings.py b/code/ddice_online_shop/settings.py index b5ff437..f638f88 100644 --- a/code/ddice_online_shop/settings.py +++ b/code/ddice_online_shop/settings.py @@ -52,6 +52,8 @@ 'allauth', 'allauth.account', 'allauth.socialaccount', + + 'guest_user', ] CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4" @@ -155,6 +157,8 @@ 'django.contrib.auth.backends.ModelBackend', # `allauth` specific authentication methods, such as login by email 'allauth.account.auth_backends.AuthenticationBackend', + + 'guest_user.backends.GuestBackend', ] # STRIPE_PUBLIC_KEY = '' diff --git a/code/ddice_online_shop/urls.py b/code/ddice_online_shop/urls.py index a7be34e..d7cf97a 100644 --- a/code/ddice_online_shop/urls.py +++ b/code/ddice_online_shop/urls.py @@ -52,5 +52,8 @@ path("product/removeonefromcart/", views.remove_single_item_from_cart, name = "remove_one_from_cart"), path('accounts/', include('allauth.urls')), + + path("loginguest/", views.LoginGuestView, name='login_guest'), + path("convert/", include("guest_user.urls")), ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/code/main/views.py b/code/main/views.py index eb325a6..39ff043 100644 --- a/code/main/views.py +++ b/code/main/views.py @@ -8,6 +8,7 @@ from math import floor from django.conf import settings from django.views.generic import View +from guest_user.decorators import allow_guest_user from .get_first_request.get_all_computer_data import GetAllComputerData from .get_first_request.get_all_smartphone_data import GetAllSmartphoneData @@ -151,6 +152,10 @@ def SearchView(request): return render(request, "store/product_no_form.html", {'product_data': prod_data, 'fullstar': fullstar}) +@allow_guest_user +def LoginGuestView(request): + return redirect(request.META.get('HTTP_REFERER')) + @login_required def OrderSummaryView(request): try: diff --git a/code/requirements.txt b/code/requirements.txt index 3da4738..73da0f8 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -6,4 +6,5 @@ django-extensions==3.2.3 django-crispy-forms==2.0 crispy-bootstrap4==2022.1 django-allauth==0.57.0 -stripe==6.6.0 \ No newline at end of file +stripe==6.6.0 +django-guest-user==0.5.5 \ No newline at end of file diff --git a/code/static/css/main.css b/code/static/css/main.css index a473cb5..742c8dc 100644 --- a/code/static/css/main.css +++ b/code/static/css/main.css @@ -19,8 +19,7 @@ html { margin-top: 4rem; } #prod-card { - width:95%; - max-width: 40vw; + width:100%; } #prod-card:hover { scale: 1.07; diff --git a/code/templates/base.html b/code/templates/base.html index 505b322..c3a48ef 100644 --- a/code/templates/base.html +++ b/code/templates/base.html @@ -111,20 +111,17 @@ Account -