HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/lib/__pycache__/supervisor_manager.cpython-310.pyc
o

�weZ|�@s<dZdZd�e�ZdZdZdZdgZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZdd	lmZdd
lmZddlmZmZddlmZmZdd
lmZddlmZmZddl Z ddl!Z!ddl"Z"ddl#m$Z$m%Z%e�Z&edd��Z'dZ(edd�Z)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1Gdd�de2�Z3Gdd�de2�Z4Gdd �d e2�Z5d!d"�Z6d#d$�Z7d%d&�Z8d'd(�Z9dPd*d+�Z:d,d-�Z;d.d/�Z<dQd0d1�Z=d2d3�Z>d4d5�Z?d6d7�Z@d8d9�ZAd:d;�ZBdRd<d=�ZCd>d?�ZDd@dA�ZEdBdC�ZFdRdDdE�ZGe&�HdF�ZIe&�HdG�ZJe&�HdH�ZKe&�HdI�ZLe&�HdJ�ZMe&�HdK�ZNe&�HdL�ZOe&�HdM�ZPe&�HdN�ZQe&�HdO�ZRdS)Sa
    flask.ext.login
    ---------------

    This module provides user session management for Flask. It lets you log
    your users in and out in a database-independent manner.

    :copyright: (c) 2011 by Matthew Frazier.
    :license: MIT/X11, see LICENSE for more details.
)�0�2�11�.zMatthew FrazierzMIT/X11z(c) 2011 by Matthew Frazier�LoginManager�)	�_request_ctx_stack�abort�current_app�flash�redirect�request�session�url_for�has_request_context)�	Namespace)�
LocalProxy)�
url_decode�
url_encode)�datetime�	timedelta��wraps)�sha1�md5N)�urlparse�
urlunparsecCst�S�N)�	_get_user�rr�B/home/arjun/projects/buyercall/buyercall/lib/supervisor_manager.py�<lambda>+sr �supervisor_tokenim)�daysFz"Please log in to access this page.�dangerz*Please reauthenticate to access this page.�get_id�
Authorizationc@s�eZdZdZd,dd�Zd-dd�Zd-dd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd.dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZdS)/ra
    This object is used to hold the settings used for logging in. Instances of
    :class:`LoginManager` are *not* bound to specific apps, so you can create
    one in the main body of your code and then bind it to your
    app in a factory function.
    NTcCs|t|_d|_t|_t|_d|_t|_	t
|_d|_d|_
d|_d|_d|_d|_t|_d|_d|_|dur<|�||�dSdS)N�basic)�AnonymousUserMixin�anonymous_user�
login_view�
LOGIN_MESSAGE�
login_message�LOGIN_MESSAGE_CATEGORY�login_message_category�refresh_view�REFRESH_MESSAGE�needs_refresh_message�REFRESH_MESSAGE_CATEGORY�needs_refresh_message_category�session_protection�localize_callback�token_callback�
user_callback�unauthorized_callback�needs_refresh_callback�ID_ATTRIBUTE�id_attribute�header_callback�request_callback�init_app��self�app�add_context_processorrrr�__init__Us&�zLoginManager.__init__cCst�dt�|�||�dS)zl
        This method has been deprecated. Please use
        :meth:`LoginManager.init_app` instead.
        z5Warning setup_app is deprecated. Please use init_app.N)�warnings�warn�DeprecationWarningr=r>rrr�	setup_app�s�zLoginManager.setup_appcCsB||_|�|j�|j�d|j�dd��|_|r|�t�dSdS)a�
        Configures an application. This registers an `after_request` call, and
        attaches this `LoginManager` to it as `app.login_manager`.

        :param app: The :class:`flask.Flask` object to configure.
        :type app: :class:`flask.Flask`
        :param add_context_processor: Whether to add a context processor to
            the app that adds a `current_supervisor_user` variable to the template.
            Defaults to ``True``.
        :type add_context_processor: bool
        �LOGIN_DISABLED�TESTINGFN)�supervisor_login_manager�
after_request�_update_remember_cookie�config�get�_login_disabled�context_processor�_user_context_processorr>rrrr=�s��zLoginManager.init_appcCstt�tt��|jr|��S|jstd�|jr1|jdur)t	|�|j�|j
d�nt	|j|j
d�tt|jt
j��S)a"
        This is called when the user is required to log in. If you register a
        callback with :meth:`LoginManager.unauthorized_handler`, then it will
        be called. Otherwise, it will take the following actions:

            - Flash :attr:`LoginManager.login_message` to the user.

            - Redirect the user to `login_view`. (The page they were attempting
              to access will be passed in the ``next`` query string variable,
              so you can redirect there if present instead of the homepage.)

        If :attr:`LoginManager.login_view` is not defined, then it will simply
        raise a HTTP 401 (Unauthorized) error instead.

        This should be returned from a view or before/after_request function,
        otherwise the redirect will have no effect.
        i�N��category)�supervisor_unauthorized�send�_get_current_object_helperr	r7r)rr+r4r
r-r�	login_urlr�url�r?rrr�unauthorized�s
�zLoginManager.unauthorizedcC�
||_|S)aA
        This sets the callback for reloading a user from the session. The
        function you set should take a user ID (a ``unicode``) and return a
        user object, or ``None`` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        :type callback: unicode
        )r6�r?�callbackrrr�user_loader�s	zLoginManager.user_loadercCrZ)a
        This sets the callback for loading a user from a header value.
        The function you set should take an authentication token and
        return a user object, or `None` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        )r;r[rrr�
header_loader��zLoginManager.header_loadercCrZ)a
        This sets the callback for loading a user from a Flask request.
        The function you set should take Flask request object and
        return a user object, or `None` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        )r<r[rrr�request_loader�r_zLoginManager.request_loadercCrZ)a�
        This sets the callback for loading a user from an authentication
        token. The function you set should take an authentication token
        (a ``unicode``, as returned by a user's `get_auth_token` method) and
        return a user object, or ``None`` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        :type callback: unicode
        )r5r[rrr�token_loader��
zLoginManager.token_loadercCrZ)ab
        This will set the callback for the `unauthorized` method, which among
        other things is used by `login_required`. It takes no arguments, and
        should return a response to be sent to the user instead of their
        normal view.

        :param callback: The callback for unauthorized users.
        :type callback: function
        )r7r[rrr�unauthorized_handler�rbz!LoginManager.unauthorized_handlercCrZ)ai
        This will set the callback for the `needs_refresh` method, which among
        other things is used by `fresh_login_required`. It takes no arguments,
        and should return a response to be sent to the user instead of their
        normal view.

        :param callback: The callback for unauthorized users.
        :type callback: function
        )r8r[rrr�needs_refresh_handlerrbz"LoginManager.needs_refresh_handlercCsnt�tt��|jr|��S|jstd�|jdur&t|�|j	�|j
d�nt|j	|j
d�tt|jt
j��S)a}
        This is called when the user is logged in, but they need to be
        reauthenticated because their session is stale. If you register a
        callback with `needs_refresh_handler`, then it will be called.
        Otherwise, it will take the following actions:

            - Flash :attr:`LoginManager.needs_refresh_message` to the user.

            - Redirect the user to :attr:`LoginManager.refresh_view`. (The page
              they were attempting to access will be passed in the ``next``
              query string variable, so you can redirect there if present
              instead of the homepage.)

        If :attr:`LoginManager.refresh_view` is not defined, then it will
        simply raise a HTTP 403 (Forbidden) error instead.

        This should be returned from a view or before/after_request function,
        otherwise the redirect will have no effect.
        i�NrQ)�supervisor_needs_refreshrTrUr	r8r.rr4r
r0r2rrVrrWrXrrr�
needs_refreshs
��zLoginManager.needs_refreshcCs^tj}|dur*t�d�}|dur|��|_dS|�|�}|dur%t�dS||_dS||_dS)N�
supervisor_id)r�topr
rMr(�
supervisorr6�logout_user)r?�user�ctx�user_idrrr�reload_user:s




zLoginManager.reload_usercCs�t�tt��tj}|�d|j�r|��}|r|��Sdt	v}|rTd}|�dt
�}|tjvo4t	�d�dk}|r?|�
tj|�S|jrG|�t�S|tjvrT|�tj|�S|��S)z;Loads user from session or remember_me cookie as applicable�SESSION_PROTECTIONrgr!�AUTH_HEADER_NAME�remember�clear)�supervisor_accessedrTrUr	rLrMr3�_session_protectionrnr
rpr�cookies�_load_from_cookier<�_load_from_request�headers�_load_from_header)r?rL�deleted�is_missing_user_id�cookie_name�header_name�
has_cookierrr�
_load_userJs(
�

zLoginManager._load_usercCs�tt�}t�}tt�}|j�d|j�}d|vr||d<|p |dk}|rP||�dd�krP|dks2|jr=d|d<t�	|�dS|dkrP|�
�d|d<t�	|�d	SdS)
Nro�_id�strongr&F�_freshrrrqT)rUr
�_create_identifierr	rLrMr3�	permanent�supervisor_session_protectedrTrr)r?�sess�identr@�mode�check_protectionrrrrtjs$

z LoginManager._session_protectioncCs�|jr#|�|�}|durt||j��td<dtd<|tj_n|��nt|�}|dur3|td<dtd<|��tjjdurIt	}t
j|t�d�dSdS)NrgFr��rk)
r5�getattrr:r
rrhrirn�
decode_cookier	�supervisor_loaded_from_cookierTr)r?�cookierkrmr@rrrrv�s 


�zLoginManager._load_from_cookiecC�Pd}|jr
|�|�}|dur"|j|d�tt�}tj|t�d�dS|��dS�Nr�)r;rnrUr	�supervisor_loaded_from_headerrTr)r?�headerrkr@rrrry��
zLoginManager._load_from_headercCr�r�)r<rnrUr	�supervisor_loaded_from_requestrTr)r?rrkr@rrrrw�r�zLoginManager._load_from_requestcCs|Srr)r?�responserrrrK�s
z$LoginManager._update_remember_cookiec
Cs~tj}d}|�dt�}|�d�}|�dt�}|�dt�}|jr$t��}nt	t
td��}t�
�|}	|j|||	|||d�dS)Nr!�REMEMBER_COOKIE_DURATION�REMEMBER_COOKIE_DOMAIN�REMEMBER_COOKIE_SECURE�REMEMBER_COOKIE_HTTPONLYrg)�value�expires�domain�secure�httponly)r	rLrM�COOKIE_DURATION�
COOKIE_SECURE�COOKIE_HTTPONLYr5�current_supervisor_user�get_auth_token�
encode_cookie�strr
r�utcnow�
set_cookie)
r?r�rLr|�durationr�r�r��datar�rrr�_set_cookie�s"


�zLoginManager._set_cookiecCs&tj}d}|�d�}|j||d�dS)Nr!r�)r�)r	rLrM�
delete_cookie)r?r�rLr|r�rrr�
_clear_cookie�s
zLoginManager._clear_cookie�NT)Tr)�__name__�
__module__�__qualname__�__doc__rBrFr=rYr]r^r`rarcrdrfrnrrtrvryrwrKr�r�rrrrrMs,

7
	#


% c@sdeZdZdZedd��Zedd��Zedd��Zdd	�Zd
d�Z	dd
�Z
ejddkr0e
jZdSdS)�	UserMixinzr
    This provides default implementations for the methods that Flask-Login
    expects user objects to have.
    cC�dSr�rrXrrr�	is_active��zUserMixin.is_activecCr�r�rrXrrr�is_authenticated�r�zUserMixin.is_authenticatedcCr��NFrrXrrr�is_anonymous�r�zUserMixin.is_anonymouscCs z|jWStytd��w)Nz%No `id` attribute - override `get_id`)�id�AttributeError�NotImplementedErrorrXrrrr$�s
�zUserMixin.get_idcCst|t�r
|��|��kStS)zP
        Checks the equality of two `UserMixin` objects using `get_id`.
        )�
isinstancer�r$�NotImplemented)r?�otherrrr�__eq__�s
zUserMixin.__eq__cCs|�|�}|turtS|S)zR
        Checks the inequality of two `UserMixin` objects using `get_id`.
        )r�r�)r?r��equalrrr�__ne__�s
zUserMixin.__ne__r�N)r�r�r�r��propertyr�r�r�r$r�r��sys�version_info�object�__hash__rrrrr��s


	
�r�c@s<eZdZdZedd��Zedd��Zedd��Zdd	�Zd
S)r'zH
    This is the default object for representing an anonymous user.
    cCr�r�rrXrrrr�r�z#AnonymousUserMixin.is_authenticatedcCr�r�rrXrrrr�r�zAnonymousUserMixin.is_activecCr�r�rrXrrrr�r�zAnonymousUserMixin.is_anonymouscCsdSrrrXrrrr$szAnonymousUserMixin.get_idN)	r�r�r�r�r�r�r�r�r$rrrrr'
s


r'cCsPt|d�s|St|jd�s|��Szt|j|j�WSty'td|j��w)z�Return the current object.  This is useful if you want the real
    object behind the proxy at a time for performance reasons or because
    you want to pass the object into a different context.
    �__local�__release_local__zno object bound to %s)�hasattrr�r�r�r��RuntimeError)�objrrrrU"s
�rUcCsd�|t|��S)z�
    This will encode a ``unicode`` value into a cookie, and sign that cookie
    with the app's secret key.

    :param payload: The value to encode, as `unicode`.
    :type payload: unicode
    �{0}|{1})�format�_cookie_digest)�payloadrrrr�1sr�cCsVz|�dd�\}}t|d�r|�d�}Wn
tyYdSwt�t|�|�r)|SdS)z�
    This decodes a cookie given by `encode_cookie`. If verification of the
    cookie fails, ``None`` will be implicitly returned.

    :param cookie: An encoded cookie.
    :type cookie: str
    �|��decode�asciiN)�rsplitr�r��
ValueError�hmac�compare_digestr�)r�r��digestrrrr�<s

���r�cCsRt|�}t|�}|jr|j|jkr'|jr|j|jkr'tdd|j|j|jdf�S|S)a
    Reduces the scheme and host from a given URL so it can be passed to
    the given `login` URL more efficiently.

    :param login_url: The login URL being redirected to.
    :type login_url: str
    :param current_url: The URL to reduce.
    :type current_url: str
    �)r�scheme�netlocr�path�params�query)rV�current_url�l�crrr�make_next_paramOs
�r��nextcCsb|�d�r|}nt|�}|dur|Stt|��}t|d�}t||�||<t|dd�|d<t|�S)a�
    Creates a URL for redirecting to a login page. If only `login_view` is
    provided, this will just return the URL for it. If `next_url` is provided,
    however, this will append a ``next=URL`` parameter to the query string
    so that the login view can redirect back to that URL.

    :param login_view: The name of the login view. (Alternately, the actual
                       URL to the login view.)
    :type login_view: str
    :param next_url: The URL to give the login view for redirection.
    :type next_url: str
    :param next_field: What field to store the next URL in. (It defaults to
                       ``next``.)
    :type next_field: str
    )zhttps://zhttp://�/N�T)�sort)�
startswithr�listrrr�rr)r)�next_url�
next_field�base�parts�mdrrrrVbs
rVcOsT|�d�}t|�}dd�|D�}d�|�}t�||t���}t|d�r(|�d�}|S)aL
    This will create a secure token that you can use as an authentication
    token for your users. It uses heavy-duty HMAC encryption to prevent people
    from guessing the information. (To make it even more effective, if you
    will never need to regenerate the token, you can  pass some random data
    as one of the arguments.)

    :param \*args: The data to include in the token.
    :type args: args
    :param \*\*options: To manually specify a secret key, pass ``key=THE_KEY``.
        Otherwise, the ``current_app`` secret key will be used.
    :type \*\*options: kwargs
    �keycSs$g|]}t|t�r|n|�d��qS)�utf-8)r��bytes�encode)�.0�srrr�
<listcomp>�s$z%make_secure_token.<locals>.<listcomp>�r�r�)	rM�_secret_key�joinr��newr�	hexdigestr�r�)�args�optionsr�r�r��token_valuerrr�make_secure_token�s



r�cCst�dd�S)z>
    This returns ``True`` if the current login is fresh.
    r�F)r
rMrrrr�login_fresh�sr�cCsH|s|��sdSt|tjj��}|td<|tj_t	j
tt�t�d�dS)a�
    Logs a user in. You should pass the actual user object to this. If the
    user's `is_active` method returns ``False``, they will not be logged in
    unless `force` is ``True``.

    This will return ``True`` if the log in attempt succeeds, and ``False`` if
    it fails (i.e. because the user is inactive).

    :param user: The user object to log in.
    :type user: object
    :param remember: Whether to remember the user after their session expires.
        Defaults to ``False``.
    :type remember: bool
    :param force: If the user is inactive, setting this to ``True`` will log
        them in regardless. Defaults to ``False``.
    :type force: bool
    Frgr�T)
r�r�r	rIr:r
rrhri�supervisor_logged_inrTrUr)rkrq�forcermrrr�
login_user�srcCsjdtvr	t�d�dtvrt�d�d}|tjvrdtd<t�}|r.|js.tjtt	�|d�t	j
��dS)z�
    Logs a user out. (You do not need to pass the actual user.) This will
    also clean up the 'remember me' cookie if it exists.
    rgr�r!rrrqr�T)r
�poprrurr��supervisor_logged_outrTrUr	rIrn)r|rkrrrrj�s




rjcCs$dtd<t�td<t�tt��dS)zq
    This sets the current session as fresh. Sessions become stale when they
    are reloaded from a cookie.
    Tr�r�N)r
r��supervisor_login_confirmedrTrUr	rrrr�
confirm_login�s
rc�t���fdd��}|S)a�
    If you decorate a view with this, it will ensure that the current user is
    logged in and authenticated before calling the actual view. (If they are
    not, it calls the :attr:`LoginManager.unauthorized` callback.) For
    example::

        @app.route('/post')
        @login_required
        def post():
            pass

    If there are only certain times you need to require that your user is
    logged in, you can do so with::

        if not current_supervisor_user.is_authenticated:
            return current_app.login_manager.unauthorized()

    ...which is essentially the code that this function adds to your views.

    It can be convenient to globally turn off authentication when unit
    testing. To enable this, if either of the application
    configuration variables `LOGIN_DISABLED` or `TESTING` is set to
    `True`, this decorator will be ignored.

    :param func: The view function to decorate.
    :type func: function
    cs4tjjr�|i|��Stjstj��S�|i|��Sr)r	rIrNr�r�rY�r��kwargs��funcrr�decorated_views

z&login_required.<locals>.decorated_viewr�rrrr
r�login_required�srcr)a
    If you decorate a view with this, it will ensure that the current user's
    login is fresh - i.e. there session was not restored from a 'remember me'
    cookie. Sensitive operations, like changing a password or e-mail, should
    be protected with this, to impede the efforts of cookie thieves.

    If the user is not authenticated, :meth:`LoginManager.unauthorized` is
    called as normal. If they are authenticated, but their session is not
    fresh, it will call :meth:`LoginManager.needs_refresh` instead. (In that
    case, you will need to provide a :attr:`LoginManager.refresh_view`.)

    Behaves identically to the :func:`login_required` decorator with respect
    to configutation variables.

    :param func: The view function to decorate.
    :type func: function
    csDtjjr�|i|��Stjstj��St�stj��S�|i|��Sr)r	rIrNr�r�rYr�rfrr
rrr s

z,fresh_login_required.<locals>.decorated_viewrr
rr
r�fresh_login_requiredsrcCs*t�rttjd�stj��ttjdd�S)Nri)rr�rrhr	rIrr�rrrrr,s
rcCs t|�}t�||�d�t���S)Nr�)r�r�r�r�rr�)r�r�rrrr�3sr�cCs&tj�dtj�}|dur|�d�}|S)NzX-Forwarded-Forr�)rrxrM�remote_addrr�)�addressrrr�_get_remote_addr9s
rcCsJtj�d�}|dur|�d�}d�t�|�}t�}|�|�d��|��S)Nz
User-Agentr�r��utf8)	rrxrMr�r�rr�updater�)�
user_agentr��hrrrr�@s
r�cCstt�d�S)N)r�)�dictrrrrrrPJsrPcCs*|dur	tjd}t|t�r|�d�}|S)N�
SECRET_KEY�latin1)r	rLr�r�r�)r�rrrr�Ns



r�zsupervisor-logged-inzsupervisor-logged-outzsupervisor-loaded-from-cookiezsupervisor-loaded-from-headerzsupervisor-loaded-from-requestzsupervisor-login-confirmedzsupervisor-unauthorizedzsupervisor-needs-refreshzsupervisor-accessedzsupervisor-session-protected)Nr�)FFr)Sr��__version_info__r��__version__�
__author__�__license__�
__copyright__�__all__�flaskrrr	r
rrr
rr�
flask.signalsr�werkzeug.localr�
werkzeug.urlsrrrr�	functoolsr�hashlibrrr�rCr��urllib.parserr�_signalsr��COOKIE_NAMEr�r�r�r*r,r/r1r9rpr�rr�r'rUr�r�r�rVr�r�rrjrrrrr�rr�rPr��signalrrr�r�r�rrSrersr�rrrr�<module>s�
,
/

"
&