o
    ×èFh5  ã                   @   s  d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ ddlmZmZ dd	lmZ G d
d„ dejƒZG dd„ deƒZe ¡ ZG dd„ deƒZe ¡ ZG dd„ deƒZe ¡ ZG dd„ deƒZe ¡ ZG dd„ deƒZe ¡ ZG dd„ deƒZe ¡ Z dS )é    )Úimport_string)ÚgenericsÚstatus)ÚRequest)ÚResponse)Ú
Serializeré   )ÚAUTH_HEADER_TYPES)ÚInvalidTokenÚ
TokenError)Úapi_settingsc                   @   sR   e Zd ZdZdZdZdZdZdefdd„Z	de
defd	d
„Zde
defdd„ZdS )ÚTokenViewBase© NÚ ÚapiÚreturnc                 C   s>   | j r| j S zt| jƒW S  ty   d| j› d�}t|ƒ‚w )ze
        If serializer_class is set, use it directly. Otherwise get the class from settings.
        zCould not import serializer 'ú')Úserializer_classr   Ú_serializer_classÚImportError)ÚselfÚmsgr   r   úW/var/www/html/loop/nvenv/lib/python3.10/site-packages/rest_framework_simplejwt/views.pyÚget_serializer_class   s   þz"TokenViewBase.get_serializer_classÚrequestc                 C   s   d  td | j¡S )Nz{} realm="{}"r   )Úformatr	   Úwww_authenticate_realm)r   r   r   r   r   Úget_authenticate_header"   s   þz%TokenViewBase.get_authenticate_headerc              
   O   sV   | j |jd�}z|jdd� W n ty" } zt|jd ƒ‚d }~ww t|jtj	d�S )N)ÚdataT)Úraise_exceptionr   )r   )
Úget_serializerr   Úis_validr   r
   Úargsr   Úvalidated_datar   ÚHTTP_200_OK)r   r   r"   ÚkwargsÚ
serializerÚer   r   r   Úpost(   s   €ÿzTokenViewBase.post)Ú__name__Ú
__module__Ú__qualname__Úpermission_classesÚauthentication_classesr   r   r   r   r   r   Ústrr   r   r(   r   r   r   r   r      s    r   c                   @   ó   e Zd ZdZejZdS )ÚTokenObtainPairViewz•
    Takes a set of user credentials and returns an access and refresh JSON web
    token pair to prove the authentication of those credentials.
    N)r)   r*   r+   Ú__doc__r   ÚTOKEN_OBTAIN_SERIALIZERr   r   r   r   r   r0   3   ó    
r0   c                   @   r/   )ÚTokenRefreshViewzz
    Takes a refresh type JSON web token and returns an access type JSON web
    token if the refresh token is valid.
    N)r)   r*   r+   r1   r   ÚTOKEN_REFRESH_SERIALIZERr   r   r   r   r   r4   ?   r3   r4   c                   @   r/   )ÚTokenObtainSlidingViewz„
    Takes a set of user credentials and returns a sliding JSON web token to
    prove the authentication of those credentials.
    N)r)   r*   r+   r1   r   ÚSLIDING_TOKEN_OBTAIN_SERIALIZERr   r   r   r   r   r6   K   r3   r6   c                   @   r/   )ÚTokenRefreshSlidingViewz€
    Takes a sliding JSON web token and returns a new, refreshed version if the
    token's refresh period has not expired.
    N)r)   r*   r+   r1   r   Ú SLIDING_TOKEN_REFRESH_SERIALIZERr   r   r   r   r   r8   W   r3   r8   c                   @   r/   )ÚTokenVerifyViewzŠ
    Takes a token and indicates if it is valid.  This view provides no
    information about a token's fitness for a particular use.
    N)r)   r*   r+   r1   r   ÚTOKEN_VERIFY_SERIALIZERr   r   r   r   r   r:   c   r3   r:   c                   @   r/   )ÚTokenBlacklistViewz~
    Takes a token and blacklists it. Must be used with the
    `rest_framework_simplejwt.token_blacklist` app installed.
    N)r)   r*   r+   r1   r   ÚTOKEN_BLACKLIST_SERIALIZERr   r   r   r   r   r<   o   r3   r<   N)!Údjango.utils.module_loadingr   Úrest_frameworkr   r   Úrest_framework.requestr   Úrest_framework.responser   Úrest_framework.serializersr   Úauthenticationr	   Ú
exceptionsr
   r   Úsettingsr   ÚGenericAPIViewr   r0   Úas_viewÚtoken_obtain_pairr4   Útoken_refreshr6   Útoken_obtain_slidingr8   Útoken_refresh_slidingr:   Útoken_verifyr<   Útoken_blacklistr   r   r   r   Ú<module>   s*    '						