
    _vgU                     `    d dl Z d dlmZ d dlmZ d dlmZmZ ddlm	Z	 dgZ
	 	 	 dd	d
d	ddZdS )    N)login)AnonymousUser)ImproperlyConfiguredPermissionDenied   )get_userauthenticate TF)required	permanentoverridec                      t          j        t                    S t          j                    fd            }|S )a.  
    Decorator that looks for a signed token in the URL and authenticates a user.

    If a valid token is found, the user is available as ``request.user`` in the
    view. Else, :exc:`~django.core.exceptions.PermissionDenied` is raised,
    resulting in an HTTP 403 Forbidden error.

    :obj:`authenticate` may be applied to a view directly::

        @authenticate def view(request):
            ...

    or with arguments::

        @authenticate(scope="status-page")
        def view(request):
            ...

    If ``scope`` is set, a :ref:`scoped token <Scoped tokens>` is expected.

    If ``max_age`` is set, override the :data:`SESAME_MAX_AGE` setting.

    Set ``required`` to :obj:`False` to set ``request.user`` to an
    :class:`~django.contrib.auth.models.AnonymousUser` and execute the view when
    the token is invalid, instead of raising an exception. Then, you can check
    if ``request.user.is_authenticated``.

    :obj:`authenticate` doesn't log the user in permanently. It is intended to
    provide direct access to a specific resource without exposing all other
    private resources. This makes it more acceptable to use the less secure
    authentication mechanism provided by django-sesame.

    Set ``permanent`` to :obj:`True` to call :func:`~django.contrib.auth.login`
    after a user is authenticated.

    :obj:`authenticate` doesn't care if a user is already logged in. It looks
    for a signed token anyway and overrides ``request.user``.

    Set ``override`` to :obj:`False` to skip authentication if a user is already
    logged in.

    N)scopemax_ager   r   r   c           	      b   t          | d          r| j        j        rs 	| g|R i |S rt          | d          st          d          t	          | rdnd  j        |i |          }||nt                      | _        r	|t          r|t          | |            	| g|R i |S )Nusersessionz=authenticate(permanent=True) requires django.contrib.sessionsF)update_last_loginr   r   )	hasattrr   is_authenticatedr   r   formatr   r   r   )
requestargskwargsr   r   r   r   r   r   views
       N/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/sesame/decorators.pywrapperzauthenticate.<locals>.wrapperI   s    7F## 	2(E 	2h 	241$111&111 	WWi88 	&O   '0:eed%,///	
 
 
  $/tt]__ 	#"" 	!)'4   tG-d---f---    )	functoolspartialr	   wraps)r   r   r   r   r   r   r   s   `````` r   r	   r	      s    f | 
 
 
 	
 _T. . . . . . . . . .: Nr   )Nr
   N)r   django.contrib.authr   django.contrib.auth.modelsr   django.core.exceptionsr   r   utilsr   __all__r	    r   r   <module>r(      s        % % % % % % 4 4 4 4 4 4 I I I I I I I I      
 

[
 [ [ [ [ [ [ [r   