mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-07-22 05:29:46 +03:00
Add endpoint for UserAuthenticationStatus
This commit is contained in:
parent
eb9e6eb05a
commit
77231029e6
|
@ -2,7 +2,7 @@ from django.conf.urls import url
|
|||
|
||||
from rest_auth.views import (
|
||||
LoginView, LogoutView, UserDetailsView, PasswordChangeView,
|
||||
PasswordResetView, PasswordResetConfirmView
|
||||
PasswordResetView, PasswordResetConfirmView, UserAuthenticationStatusView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -15,6 +15,8 @@ urlpatterns = [
|
|||
# URLs that require a user to be logged in with a valid session / token.
|
||||
url(r'^logout/$', LogoutView.as_view(), name='rest_logout'),
|
||||
url(r'^user/$', UserDetailsView.as_view(), name='rest_user_details'),
|
||||
url(r'^user/status/$', UserAuthenticationStatusView.as_view(),
|
||||
name='rest_auth_status'),
|
||||
url(r'^password/change/$', PasswordChangeView.as_view(),
|
||||
name='rest_password_change'),
|
||||
]
|
||||
|
|
|
@ -153,6 +153,26 @@ class UserDetailsView(RetrieveUpdateAPIView):
|
|||
return get_user_model().objects.none()
|
||||
|
||||
|
||||
class UserAuthenticationStatusView(APIView):
|
||||
"""
|
||||
Checks is_authenticated attribute for User attached to request.
|
||||
Accepts GET method.
|
||||
|
||||
Returns True/False indicator for if user is authenticated.
|
||||
"""
|
||||
authentication_classes = ()
|
||||
permission_classes = ()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if hasattr(request, "user") and request.user.is_authenticated:
|
||||
return Response(
|
||||
{"authenticated": True}, status=status.HTTP_200_OK
|
||||
)
|
||||
|
||||
return Response(
|
||||
{"authenticated": False}, status=status.HTTP_401_UNAUTHORIZED
|
||||
)
|
||||
|
||||
class PasswordResetView(GenericAPIView):
|
||||
"""
|
||||
Calls Django Auth PasswordResetForm save method.
|
||||
|
|
Loading…
Reference in New Issue
Block a user