o
    þÞh,  ã                   @   sŽ   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ƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZdS )é    )Úurlsplit)Úsettings)ÚREDIRECT_FIELD_NAME)Úredirect_to_login)ÚImproperlyConfiguredÚPermissionDenied)Úresolve_urlc                   @   s@   e Zd ZdZdZdZdZeZdd„ Z	dd„ Z
d	d
„ Zdd„ ZdS )ÚAccessMixinz^
    Abstract CBV mixin that gives access mixins the same customizable
    functionality.
    NÚ Fc                 C   s>   | j ptj}|st| jj› d| jj› d| jj› d�ƒ‚t|ƒS )zK
        Override this method to override the login_url attribute.
        z, is missing the login_url attribute. Define z,.login_url, settings.LOGIN_URL, or override z.get_login_url().)Ú	login_urlr   Ú	LOGIN_URLr   Ú	__class__Ú__name__Ústr)Úselfr   © r   úZ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/contrib/auth/mixins.pyÚget_login_url   s   
ÿþÿzAccessMixin.get_login_urlc                 C   ó   | j S )z[
        Override this method to override the permission_denied_message attribute.
        )Úpermission_denied_message©r   r   r   r   Úget_permission_denied_message"   ó   z)AccessMixin.get_permission_denied_messagec                 C   r   )zU
        Override this method to override the redirect_field_name attribute.
        )Úredirect_field_namer   r   r   r   Úget_redirect_field_name(   r   z#AccessMixin.get_redirect_field_namec                 C   sŒ   | j s| jjjrt|  ¡ ƒ‚| j ¡ }t|  ¡ ƒ}t	|ƒd d… \}}t	|ƒd d… \}}|r3||kr>|r9||kr>| j 
¡ }t|||  ¡ ƒS )Né   )Úraise_exceptionÚrequestÚuserÚis_authenticatedr   r   Úbuild_absolute_urir   r   r   Úget_full_pathr   r   )r   ÚpathÚresolved_login_urlÚlogin_schemeÚlogin_netlocÚcurrent_schemeÚcurrent_netlocr   r   r   Úhandle_no_permission.   s    
ÿ
ýz AccessMixin.handle_no_permission)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r(   r   r   r   r   r	   
   s    r	   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚLoginRequiredMixinz.Verify that the current user is authenticated.c                    s*   |j js|  ¡ S tƒ j|g|¢R i |¤ŽS ©N)r   r   r(   ÚsuperÚdispatch©r   r   ÚargsÚkwargs©r   r   r   r/   F   ó   zLoginRequiredMixin.dispatch)r   r)   r*   r+   r/   Ú__classcell__r   r   r3   r   r,   C   s    r,   c                       s4   e Zd ZdZdZdd„ Zdd„ Z‡ fdd„Z‡  ZS )	ÚPermissionRequiredMixinz;Verify that the current user has all specified permissions.Nc                 C   sR   | j du rt| jj› d| jj› d| jj› d�ƒ‚t| j tƒr$| j f}|S | j }|S )zv
        Override this method to override the permission_required attribute.
        Must return an iterable.
        Nz6 is missing the permission_required attribute. Define z".permission_required, or override z.get_permission_required().)Úpermission_requiredr   r   r   Ú
isinstancer   ©r   Úpermsr   r   r   Úget_permission_requiredQ   s   

þýÿÿz/PermissionRequiredMixin.get_permission_requiredc                 C   s   |   ¡ }| jj |¡S )zT
        Override this method to customize the way permissions are checked.
        )r;   r   r   Ú	has_permsr9   r   r   r   Úhas_permissionc   s   z&PermissionRequiredMixin.has_permissionc                    s*   |   ¡ s|  ¡ S tƒ j|g|¢R i |¤ŽS r-   )r=   r(   r.   r/   r0   r3   r   r   r/   j   r4   z PermissionRequiredMixin.dispatch)	r   r)   r*   r+   r7   r;   r=   r/   r5   r   r   r3   r   r6   L   s    r6   c                       s0   e Zd ZdZdd„ Zdd„ Z‡ fdd„Z‡  ZS )ÚUserPassesTestMixinz]
    Deny a request with a permission error if the test_func() method returns
    False.
    c                 C   s   t d | jj¡ƒ‚)Nz;{} is missing the implementation of the test_func() method.)ÚNotImplementedErrorÚformatr   r   r   r   r   r   Ú	test_funcv   s
   ÿÿzUserPassesTestMixin.test_funcc                 C   r   )zK
        Override this method to use a different test_func method.
        )rA   r   r   r   r   Úget_test_func}   r   z!UserPassesTestMixin.get_test_funcc                    s0   |   ¡ ƒ }|s|  ¡ S tƒ j|g|¢R i |¤ŽS r-   )rB   r(   r.   r/   )r   r   r1   r2   Úuser_test_resultr3   r   r   r/   ƒ   s   
zUserPassesTestMixin.dispatch)r   r)   r*   r+   rA   rB   r/   r5   r   r   r3   r   r>   p   s
    r>   N)Úurllib.parser   Údjango.confr   Údjango.contrib.authr   Údjango.contrib.auth.viewsr   Údjango.core.exceptionsr   r   Údjango.shortcutsr   r	   r,   r6   r>   r   r   r   r   Ú<module>   s    9	$