Skip to content
Snippets Groups Projects
Commit 087333d9 authored by Mario Raciti's avatar Mario Raciti
Browse files

TMSS-521: Refactoring and code clean up

parent a875b0e5
No related branches found
No related tags found
1 merge request!327Resolve TMSS-521
......@@ -8,6 +8,7 @@ from lofar.common.datetimeutils import formatDatetime
from lofar.sas.tmss.tmss.tmssapp.adapters.parset import convert_to_parset
from drf_yasg.utils import swagger_auto_schema
from drf_yasg.openapi import Parameter
from rest_framework.authtoken.models import Token
from rest_framework.permissions import AllowAny
from rest_framework.decorators import authentication_classes, permission_classes
from django.apps import apps
......@@ -44,32 +45,12 @@ def index(request):
#return render(request, "../../../frontend/frontend_poc/build/index.html")
from django.contrib.auth import authenticate, login
from django.contrib.auth.views import LoginView as LiW
class LoginView(LiW):
def post(self, request, *args, **kwargs):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
# TODO: Keep this view or not? We provide a proof of auth to frontend with DRF TokenAuthentication: POST /token-auth/
auth = login(request, user)
return HttpResponse('Success!', content_type='text/plain')
else:
return HttpResponse('Invalid credentials!', content_type='text/plain')
from django.contrib.auth import logout
from rest_framework.authtoken.models import Token
# TODO: Deal with CSRF
def token_deauth(request, *args, **kwargs):
@api_view(['DELETE'])
def revoke_token_deauth(request, *args, **kwargs):
token = request.META['HTTP_AUTHORIZATION'].split(" ")[1]
# FIXME: request.user is None, need to find out a way to link token with user (Token.objects.filter(key=token, user=requests.user)
invalidate_token = Token.objects.filter(key=token)
invalidate_token.delete()
# logout(request)
return HttpResponse('Success logout!', content_type='text/plain')
return HttpResponse(status=204)
def task_specify_observation(request, pk=None):
......
......@@ -57,10 +57,9 @@ swagger_schema_view = get_schema_view(
# use re_path(r'<...>/?') to make trailing slash optional (double entries confuse Swagger)
urlpatterns = [
path('admin/', admin.site.urls),
path('login/', views.LoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
path('token-auth/', obtain_auth_token, name='token-auth'),
path('token-deauth/', views.token_deauth, name='token-deauth'),
path('token-auth/', obtain_auth_token, name='obtain-token-auth'),
path('token-deauth/', views.revoke_token_deauth, name='revoke-token-deauth'),
path('docs/', include_docs_urls(title='TMSS API')),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', swagger_schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', swagger_schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
......
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