Skip to content
Snippets Groups Projects
Commit b7456861 authored by Neda Moeini's avatar Neda Moeini
Browse files

Add logout functionality

parent fc025137
No related branches found
No related tags found
1 merge request!4Feature/activity log
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
"""URL configuration for the accounts' app."""
from django.contrib.auth.views import LogoutView
from django.urls import path
urlpatterns = [
path("logout/", LogoutView.as_view(), name="logout"),
]
......@@ -77,19 +77,32 @@
successSection.classList.remove('hidden');
downloadLink.href = result.download_url;
downloadSection.classList.remove('hidden');
} else if (response.status === 400 && result.status === 'error') {
for (const [field, messages] of Object.entries(result.errors)) {
messages.forEach(message => {
const li = document.createElement('li');
li.textContent = `${field}: ${message}`;
errorList.appendChild(li);
});
} else {
errorList.innerHTML = '';
if (response.status === 403) {
const li = document.createElement('li');
li.textContent = 'You are not authorized to perform this action.';
errorList.appendChild(li);
} else if (response.status === 400 && result.status === 'error') {
for (const [field, messages] of Object.entries(result.errors)) {
messages.forEach(message => {
const li = document.createElement('li');
li.textContent = `${field}: ${message}`;
errorList.appendChild(li);
});
}
} else {
const li = document.createElement('li');
li.textContent = 'An unexpected error occurred. Please try again.';
errorList.appendChild(li);
}
errorSection.classList.remove('hidden');
}
} catch (error) {
const li = document.createElement('li');
li.textContent = 'An unexpected error occurred. Please try again.';
li.textContent = 'Failed to connect to the server. Please check your internet connection.';
errorList.appendChild(li);
errorSection.classList.remove('hidden');
}
......
"""Views for the file_validator app."""
import csv
import io
from typing import ClassVar
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
......@@ -29,7 +30,8 @@ def upload_page_view(request: HttpRequest) -> HttpResponse:
class CSVUploadAPIView(APIView):
"""API view for uploading a CSV file."""
permission_classes = [IsAuthenticated]
permission_classes: ClassVar[list] = [IsAuthenticated]
def post(self, request: Request) -> Response:
"""Handle CSV upload and validation."""
......
......@@ -167,4 +167,4 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_REDIRECT_URI = "http://localhost:8000/complete/google-
SOCIAL_AUTH_JSONFIELD_ENABLED = True
SOCIAL_AUTH_URL_NAMESPACE = 'social'
LOGIN_REDIRECT_URL = "/"
SOCIAL_AUTH_ALLOW_DISCONNECT = True
\ No newline at end of file
LOGOUT_REDIRECT_URL = "/"
\ No newline at end of file
......@@ -20,11 +20,13 @@
<div class="flex items-center"> <!-- Login link -->
{% if user.is_authenticated %}
<p class="text-white">Welcome, {{ user.username }}!</p>
{# <a href="{% url 'social:disconnect' 'google-oauth2' %}" class="text-white hover:text-gray-300">Logout</a>#}
{# <form action="{% url 'social:disconnect' 'google-oauth2' %}" method="post">#}
{# {% csrf_token %}#}
{# <button type="submit">Logout</button>#}
{# </form>#}
<form action="{% url 'logout' %}" method="post" class="inline-block ml-4">
{% csrf_token %}
<button type="submit"
class="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 focus:outline-none focus:ring focus:ring-red-400">
Logout
</button>
</form>
{% else %}
<a href="{% url "social:begin" "google-oauth2" %}" class="text-white hover:text-gray-300">Login</a>
{% endif %}
......
......@@ -9,6 +9,6 @@ urlpatterns = [
path("admin/", admin.site.urls),
path("file-validator/", include("sage_validation.file_validator.urls")),
path("", index_view, name="index"),
path("", include("social_django.urls", namespace="social"))
path("", include("social_django.urls", namespace="social")),
path("accounts/", include("sage_validation.accounts.urls")),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment