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
"""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 @@ ...@@ -77,19 +77,32 @@
successSection.classList.remove('hidden'); successSection.classList.remove('hidden');
downloadLink.href = result.download_url; downloadLink.href = result.download_url;
downloadSection.classList.remove('hidden'); downloadSection.classList.remove('hidden');
} else if (response.status === 400 && result.status === 'error') { } else {
for (const [field, messages] of Object.entries(result.errors)) { errorList.innerHTML = '';
messages.forEach(message => {
const li = document.createElement('li'); if (response.status === 403) {
li.textContent = `${field}: ${message}`; const li = document.createElement('li');
errorList.appendChild(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'); errorSection.classList.remove('hidden');
} }
} catch (error) { } catch (error) {
const li = document.createElement('li'); 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); errorList.appendChild(li);
errorSection.classList.remove('hidden'); errorSection.classList.remove('hidden');
} }
......
"""Views for the file_validator app.""" """Views for the file_validator app."""
import csv import csv
import io import io
from typing import ClassVar
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.shortcuts import render from django.shortcuts import render
...@@ -29,7 +30,8 @@ def upload_page_view(request: HttpRequest) -> HttpResponse: ...@@ -29,7 +30,8 @@ def upload_page_view(request: HttpRequest) -> HttpResponse:
class CSVUploadAPIView(APIView): class CSVUploadAPIView(APIView):
"""API view for uploading a CSV file.""" """API view for uploading a CSV file."""
permission_classes = [IsAuthenticated]
permission_classes: ClassVar[list] = [IsAuthenticated]
def post(self, request: Request) -> Response: def post(self, request: Request) -> Response:
"""Handle CSV upload and validation.""" """Handle CSV upload and validation."""
......
...@@ -167,4 +167,4 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_REDIRECT_URI = "http://localhost:8000/complete/google- ...@@ -167,4 +167,4 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_REDIRECT_URI = "http://localhost:8000/complete/google-
SOCIAL_AUTH_JSONFIELD_ENABLED = True SOCIAL_AUTH_JSONFIELD_ENABLED = True
SOCIAL_AUTH_URL_NAMESPACE = 'social' SOCIAL_AUTH_URL_NAMESPACE = 'social'
LOGIN_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/"
SOCIAL_AUTH_ALLOW_DISCONNECT = True LOGOUT_REDIRECT_URL = "/"
\ No newline at end of file \ No newline at end of file
...@@ -20,11 +20,13 @@ ...@@ -20,11 +20,13 @@
<div class="flex items-center"> <!-- Login link --> <div class="flex items-center"> <!-- Login link -->
{% if user.is_authenticated %} {% if user.is_authenticated %}
<p class="text-white">Welcome, {{ user.username }}!</p> <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 'logout' %}" method="post" class="inline-block ml-4">
{# <form action="{% url 'social:disconnect' 'google-oauth2' %}" method="post">#} {% csrf_token %}
{# {% csrf_token %}#} <button type="submit"
{# <button type="submit">Logout</button>#} 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">
{# </form>#} Logout
</button>
</form>
{% else %} {% else %}
<a href="{% url "social:begin" "google-oauth2" %}" class="text-white hover:text-gray-300">Login</a> <a href="{% url "social:begin" "google-oauth2" %}" class="text-white hover:text-gray-300">Login</a>
{% endif %} {% endif %}
......
...@@ -9,6 +9,6 @@ urlpatterns = [ ...@@ -9,6 +9,6 @@ urlpatterns = [
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("file-validator/", include("sage_validation.file_validator.urls")), path("file-validator/", include("sage_validation.file_validator.urls")),
path("", index_view, name="index"), 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