Skip to content

Commit

Permalink
add guest user
Browse files Browse the repository at this point in the history
  • Loading branch information
kritserv committed Oct 3, 2023
1 parent d846fc1 commit 577d4bc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions code/ddice_online_shop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
'allauth',
'allauth.account',
'allauth.socialaccount',

'guest_user',
]

CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
Expand Down Expand Up @@ -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 = ''
Expand Down
3 changes: 3 additions & 0 deletions code/ddice_online_shop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
path("product/removeonefromcart/<str:title>", 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)
5 changes: 5 additions & 0 deletions code/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion code/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
stripe==6.6.0
django-guest-user==0.5.5
3 changes: 1 addition & 2 deletions code/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ html {
margin-top: 4rem;
}
#prod-card {
width:95%;
max-width: 40vw;
width:100%;
}
#prod-card:hover {
scale: 1.07;
Expand Down
9 changes: 3 additions & 6 deletions code/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,17 @@
</div>
Account
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
{% if request.user.is_authenticated %}
<li><a class="dropdown-item" href="/accounts/logout">Log out</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="/admin">Admin</a></li>
{% else %}
<li><a class="dropdown-item" href="/accounts/login">Login</a></li>
<li><a class="dropdown-item" href="/accounts/signup">Signup</a></li>
<li><a class="dropdown-item" href="/loginguest/">Guest Login (For test)</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="/admin">Admin</a></li>
<li><a class="dropdown-item" href="/admin">Admin Login</a></li>
{% endif %}
</ul>
</li>
Expand Down

0 comments on commit 577d4bc

Please sign in to comment.