
    _vg#                     p    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	 g dZ
dd	Zdd
ZddZddddZdS )    )	urlencode)authenticate)timezone   )settingscreate_token)	get_tokenget_parametersget_query_stringget_user c                 "    t          | |          S )z
    Generate a signed token to authenticate ``user``.

    Set ``scope`` to create a :ref:`scoped token <Scoped tokens>`.

    Use this function to create a token that :func:`get_user` will accept.

    r   userscopes     I/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/sesame/utils.pyr
   r
      s     e$$$    c                 :    t           j        t          | |          iS )z
    Generate a :class:`dict` of query string parameters to authenticate ``user``.

    Set ``scope`` to create a :ref:`scoped token <Scoped tokens>`.

    Use this function to add authentication to a URL that already contains a
    query string.

    )r   
TOKEN_NAMEr	   r   s     r   r   r      s     dE!:!:;;r   c                 Z    dt          t          j        t          | |          i          z   S )z
    Generate a complete query string to authenticate ``user``.

    Set ``scope`` to create a :ref:`scoped token <Scoped tokens>`.

    Use this function to add authentication to a URL that doesn't contain a
    query string.

    ?)r   r   r   r	   r   s     r   r   r   %   s)     H/dE1J1JKLLLLr   N)update_last_loginc                x   t          | t                    rd}| }nI| }	 | j                            t          j                  }n# t          $ r t          d          w xY w|dS t          ||||          }|dS |t          j	        }|r/t          j                    |_        |                    dg           |S )a  
    Authenticate a user based on a signed token.

    ``request_or_sesame`` may be a :class:`~django.http.HttpRequest` containing
    a token in the URL or the token itself, created with :func:`get_token`. The
    latter supports use cases outside the HTTP request lifecycle.

    If a valid token is found, return the user. Else, return :obj:`None`.

    :func:`get_user` doesn't log the user in permanently.

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

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

    If single-use tokens are enabled, :func:`get_user` invalidates the token by
    updating the user's last login date.

    Set ``update_last_login`` to :obj:`True` or :obj:`False` to always or never
    update the user's last login date, regardless of whether single-use tokens
    are enabled. Typically, if you're going to log the user in with
    :func:`~django.contrib.auth.login`, set ``update_last_login`` to
    :obj:`False` to avoid updating the last login date twice.

    Nz,get_user() expects an HTTPRequest or a token)sesamer   max_age
last_login)update_fields)
isinstancestrGETgetr   r   	Exception	TypeErrorr   ONE_TIMEr   nowr   save)request_or_sesamer   r   r   requestr   r   s          r   r   r   2   s    4 #S)) " $	L&*..x/BCCFF 	L 	L 	LJKKK	L>4 	  D |t $- 0",..			///Ks   $A A)r   )r   N)urllib.parser   django.contrib.authr   django.utilsr   r   r   tokensr	   __all__r
   r   r   r    r   r   <module>r0      s    " " " " " " , , , , , , ! ! ! ! ! !                  
I
I
I	% 	% 	% 	%
< 
< 
< 
<
M 
M 
M 
M8T 8 8 8 8 8 8 8r   