Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

added the logout functionality #4

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/djangoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# path for login
path(route='login', view=views.login_user, name='login'),

path(route='logout', view=views.logout_request, name='logout'),
# path for dealer reviews view

# path for add a review view
Expand Down
12 changes: 6 additions & 6 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
logger = logging.getLogger(__name__)


# Create your views here.

# Create a `login_request` view to handle sign in request
@csrf_exempt
def login_user(request):
# Get username and password from request.POST dictionary
Expand All @@ -38,9 +35,12 @@ def login_user(request):
data = {"userName": username, "status": "Authenticated"}
return JsonResponse(data)

# Create a `logout_request` view to handle sign out request
# def logout_request(request):
# ...
def logout_request(request):
logout(request)
data = {"userName":""}
return JsonResponse(data)



# Create a `registration` view to handle sign up request
# @csrf_exempt
Expand Down
1 change: 1 addition & 0 deletions server/djangoproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
path('about/', TemplateView.as_view(template_name="About.html")),
path('contact/', TemplateView.as_view(template_name="Contact.html")),
path('login/', TemplateView.as_view(template_name="index.html")),
path('logout/', TemplateView.as_view(template_name="index.html")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
15 changes: 14 additions & 1 deletion server/templates/Home.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}" />
<script>
const logout = async (e) => {
//Include the code for logout here.
let logout_url = window.location.origin + "/djangoapp/logout";
const res = await fetch(logout_url, {
method: "GET",
});
const json = await res.json();
if (json) {
let username = sessionStorage.getItem("username");
sessionStorage.removeItem("username");
window.location.href = window.location.origin;
window.location.reload();
alert("Logging out " + username + "...");
} else {
alert("The user could not be logged out.");
}
};

let checkSession = () => {
Expand Down