
    iiN                        S SK J r   S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJ	r	  S S
KJ
r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SS K"J#r#  SS!K"J$r$  SS"K"J%r%  SS#K"J&r&  SS$K"J'r'  SS%K"J(r)  SS&K"J*r*   " S' S(5      r+g))*    )datetime)	timedelta)abort)current_app)flash)g)has_app_context)redirect)request)session   )AUTH_HEADER_NAME)COOKIE_DURATION)COOKIE_HTTPONLY)COOKIE_NAME)COOKIE_SAMESITE)COOKIE_SECURE)ID_ATTRIBUTE)LOGIN_MESSAGE)LOGIN_MESSAGE_CATEGORY)REFRESH_MESSAGE)REFRESH_MESSAGE_CATEGORY)SESSION_KEYS)USE_SESSION_FOR_NEXT)AnonymousUserMixin)session_protected)user_accessed)user_loaded_from_cookie)user_loaded_from_request)user_needs_refresh)user_unauthorized)_create_identifier)_user_context_processor)decode_cookie)encode_cookie)expand_login_view)	login_url)make_next_paramc                       \ rS rSrSrSS jrSS jrSS jrS rS r	\
S	 5       rS
 r\
S 5       rS rS rS rS rSS jrS rS rS rS rS rS rS rS r\
S 5       r\R8                  S 5       rSrg)LoginManager*   zThis 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.
Nc                 T   [         U l        S U l        0 U l        [        U l        [        U l        S U l        [        U l
        [        U l        SU l        S U l        S U l        S U l        ["        U l        S U l        S U l        S U l        [,        U l        Ub  U R1                  X5        g g )Nbasic)r   anonymous_user
login_viewblueprint_login_viewsr   login_messager   login_message_categoryrefresh_viewr   needs_refresh_messager   needs_refresh_message_categorysession_protectionlocalize_callbackunauthorized_callbackneeds_refresh_callbackr   id_attribute_user_callback_header_callback_request_callbackr"   _session_identifier_generatorinit_appselfappadd_context_processors      K/var/www/ias/venv/lib/python3.13/site-packages/flask_login/login_manager.py__init__LoginManager.__init__1   s     1
 
 &(" + '=# ! &5" /G+
 #* "&%)"&*#(" $!%-?*?MM#5     c                 X    SSK nUR                  S[        SS9  U R                  X5        g)zT
This method has been deprecated. Please use
:meth:`LoginManager.init_app` instead.
r   NzY'setup_app' is deprecated and will be removed in Flask-Login 0.7. Use 'init_app' instead.   
stacklevel)warningswarnDeprecationWarningr?   )rA   rB   rC   rL   s       rD   	setup_appLoginManager.setup_appm   s1    
 	8	 	 	
 	c1rG   c                     Xl         UR                  U R                  5        U(       a  UR                  [        5        gg)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_user` variable to the template.
    Defaults to ``True``.
:type add_context_processor: bool
N)login_managerafter_request_update_remember_cookiecontext_processorr#   r@   s      rD   r?   LoginManager.init_app|   s5     !$667 !!"9: !rG   c                 X   [         R                  " [        R                  " 5       5        U R                  (       a  U R	                  5       $ [
        R                  U R                  ;   a  U R                  [
        R                     nOU R                  nU(       d  [        S5        U R                  (       aY  U R                  b.  [        U R                  U R                  5      U R                  S9  O[        U R                  U R                  S9  [        R                  nUR                  S[         5      (       aO  [#        U5      nU R%                  5       [&        S'   [)        U[
        R*                  5      [&        S'   [-        U5      nO[-        U[
        R*                  S9n[/        U5      $ )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.

    - If the app is using blueprints find the login view for
      the current blueprint using `blueprint_login_views`. If the app
      is not using blueprints or the login view for the current
      blueprint is not specified use the value of `login_view`.

    - Redirect the user to the 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. Alternatively, it will be added to the session
      as ``next`` if USE_SESSION_FOR_NEXT is set.)

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.
  categoryr   _idnextnext_url)r!   sendr   _get_current_objectr8   r   	blueprintr0   r/   r   r1   r7   r   r2   configgetr   r&   r>   r   r(   urlmake_login_urlr
   )rA   r/   rb   r'   redirect_urls        rD   unauthorizedLoginManager.unauthorized   s5   2 	{>>@A%%--// : ::33G4E4EFJJ#J%%1**4+=+=>!88
 d((43N3NO##::,.BCC)*5I!??AGEN-iEGFO)*5L)*w{{KL%%rG   c                 &    Xl         U R                  $ )a  
This sets the callback for reloading a user from the session. The
function you set should take a user ID (a ``str``) and return a
user object, or ``None`` if the user does not exist.

:param callback: The callback for retrieving a user object.
:type callback: callable
)r;   user_callbackrA   callbacks     rD   user_loaderLoginManager.user_loader   s     '!!!rG   c                     U R                   $ )z;Gets the user_loader callback set by user_loader decorator.)r;   rA   s    rD   rj   LoginManager.user_callback   s     """rG   c                 &    Xl         U R                  $ )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.
:type callback: callable
)r=   request_callbackrk   s     rD   request_loaderLoginManager.request_loader   s     "*$$$rG   c                     U R                   $ )zAGets the request_loader callback set by request_loader decorator.)r=   rp   s    rD   rs   LoginManager.request_callback   s     %%%rG   c                     Xl         U$ )a*  
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: callable
)r8   rk   s     rD   unauthorized_handler!LoginManager.unauthorized_handler   s     &."rG   c                     Xl         U$ )a1  
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: callable
)r9   rk   s     rD   needs_refresh_handler"LoginManager.needs_refresh_handler   s     '/#rG   c                    [         R                  " [        R                  " 5       5        U R                  (       a  U R	                  5       $ U R
                  (       d  [        S5        U R                  (       aY  U R                  b.  [        U R                  U R                  5      U R                  S9  O[        U R                  U R                  S9  [        R                  nUR                  S[        5      (       ac  [        U R
                  5      nU R                  5       [         S'   [#        U[$        R&                  5      [         S'   [)        U R
                  5      nO$U R
                  n[)        U[$        R&                  S9n[+        U5      $ )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 401 (Unauthorized) error instead.

This should be returned from a view or before/after_request function,
otherwise the redirect will have no effect.
rX   rY   r   r[   r\   r]   )r    r_   r   r`   r9   r3   r   r4   r7   r   r5   rb   rc   r   r&   r>   r   r(   r   rd   re   r
   )rA   rb   r'   rf   s       rD   needs_refreshLoginManager.needs_refresh  s%   ( 	 ? ? AB&&..00  #J%%%%1**4+E+EF!@@
 ..!@@
 ##::,.BCC)$*;*;<I!??AGEN-iEGFO)$*;*;<L))I))gkkJL%%rG   c                 D    SSK nUR                  S[        SS9  Xl        U$ )ak  
This function has been deprecated. Please use
:meth:`LoginManager.request_loader` instead.

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.
:type callback: callable
r   Nzc'header_loader' is deprecated and will be removed in Flask-Login 0.7. Use 'request_loader' instead.rI   rJ   )rL   rM   rN   r<   )rA   rl   rL   s      rD   header_loaderLoginManager.header_loader8  s0     	>	 	 	
 !)rG   c                 @    Uc  U R                  5       nU[        l        g)z!Store the given user as ctx.user.N)r.   r   _login_user)rA   users     rD   !_update_request_context_with_user.LoginManager._update_request_context_with_userO  s     <&&(DrG   c                 v   U R                   c  U R                  c  [        S5      e[        R                  " [
        R                  " 5       5        U R                  5       (       a  U R                  5       $ Sn[        R                  " S5      nUb  U R                   b  U R                  U5      nUc  [
        R                  nUR                  S[        5      nUR                  S[        5      nU[        R                  ;   =(       a    [        R                  " S5      S:g  nU(       a%  [        R                  U   nU R!                  U5      nO_U R                  (       a  U R#                  [        5      nO8U[        R$                  ;   a$  [        R$                  U   nU R'                  U5      nU R                  U5      $ )z;Loads user from session or remember_me cookie as applicableNznMissing user_loader or request_loader. Refer to http://flask-login.readthedocs.io/#how-it-works for more info._user_idREMEMBER_COOKIE_NAMEr   	_rememberclear)r;   r=   	Exceptionr   r_   r   r`   _session_protection_failedr   r   rc   rb   r   r   r   cookies_load_user_from_remember_cookie_load_user_from_requestheaders_load_user_from_header)	rA   r   user_idrb   cookie_nameheader_name
has_cookiecookieheaders	            rD   
_load_userLoginManager._load_userW  sl    &4+A+A+I!  	;::<= **,,99;; ++j)4#6#6#B&&w/D < ''F **%;[IK **%79IJKw.V7;;{3Kw3V   5;;FC''33G</ 5226:55d;;rG   c                 (   [         R                  " 5       nU R                  5       n[        R                  " 5       nUR                  R                  SU R                  5      nU(       a  US;  a  gU(       a  X!R                  SS 5      :w  a  US:X  d  UR                  (       a0  UR                  S5      SLa  SUS'   [        R                  " U5        gUS:X  a;  [         H  nUR                  US 5        M     SUS	'   [        R                  " U5        g
g)NSESSION_PROTECTION)r-   strongFr[   r-   _freshr   r   r   T)r   r`   r>   r   rb   rc   r6   	permanentr   r_   r   pop)rA   sessidentrB   modeks         rD   r   'LoginManager._session_protection_failed  s    **,224--/zz~~2D4K4KLt#66 EXXeT22w$..88H%U2%*DN!&&s+!%AHHQ% & %,[!!&&s+rG   c                     [        U5      nUbd  U[        S'   S[        S'   S nU R                  (       a  U R                  U5      nUb+  [        R                  " 5       n[
        R                  " XCS9  U$ g )Nr   Fr   r   )r$   r   r;   r   r`   r   r_   )rA   r   r   r   rB   s        rD   r   ,LoginManager._load_user_from_remember_cookie  sn    '")GJ %GHD""**73!557',,S<rG   c                     U R                   (       a@  U R                  U5      nUb,  [        R                  " 5       nSSKJn  UR                  X2S9  U$ g )Nr   )_user_loaded_from_headerr   )r<   r   r`   signalsr   r_   )rA   r   r   rB   r   s        rD   r   #LoginManager._load_user_from_header  sK      ((0D!557=(--c-=rG   c                     U R                   (       a?  U R                  U5      nUb+  [        R                  " 5       n[        R                  " X2S9  U$ g )Nr   )r=   r   r`   r   r_   )rA   r   r   rB   s       rD   r   $LoginManager._load_user_from_request  sE    !!))'2D!557(--c=rG   c                 *   S[         ;  a-  [        R                  R                  S5      (       a	  S[         S'   S[         ;   aQ  [         R                  " SS 5      nUS:X  a  S[         ;   a  U R                  U5        U$ US:X  a  U R                  U5        U$ )Nr   $REMEMBER_COOKIE_REFRESH_EACH_REQUESTsetr   r   )r   r   rb   rc   r   _set_cookie_clear_cookie)rA   response	operations      rD   rT   $LoginManager._update_remember_cookie  s    g%+*<*<*@*@2+
 +
 $)GK '!K6IE!jG&;  *  g%""8,rG   c                    [         R                  nUR                  S[        5      nUR                  S5      nUR                  SS5      nUR                  S[        5      nUR                  S[
        5      nUR                  S[        5      nS[        ;   a  [        [        S   S	9n	OUR                  S
[        5      n	[        [        [        S   5      5      n
[        U	[        5      (       a	  [        U	S	9n	 [        R                  " 5       U	-   nUR%                  UU
UUUUUUS9  g ! [          a  n[#        SU	 35      UeS nAff = f)Nr   REMEMBER_COOKIE_DOMAINREMEMBER_COOKIE_PATH/REMEMBER_COOKIE_SECUREREMEMBER_COOKIE_HTTPONLYREMEMBER_COOKIE_SAMESITE_remember_seconds)secondsREMEMBER_COOKIE_DURATIONr   zDREMEMBER_COOKIE_DURATION must be a datetime.timedelta, instead got: )valueexpiresdomainpathsecurehttponlysamesite)r   rb   rc   r   r   r   r   r   r   r   r%   str
isinstanceintr   utcnow	TypeErrorr   
set_cookie)rA   r   rb   r   r   r   r   r   r   durationdatar   es                rD   r   LoginManager._set_cookie  s=   ##jj!7E45zz0#64mD::8/J::8/J') 1D)EFHzz"<oNH S!456h$$ 2H	oo'(2G 	 	 		
  	!!)
, 	s   7D& &
E0D??Ec                     [         R                  nUR                  S[        5      nUR                  S5      nUR                  SS5      nUR	                  X4US9  g )Nr   r   r   r   )r   r   )r   rb   rc   r   delete_cookie)rA   r   rb   r   r   r   s         rD   r   LoginManager._clear_cookie  sQ    ##jj!7E45zz0#6{ErG   c                     SSK nUR                  S[        SS9  [        5       (       a   [        R
                  R                  SS5      $ g)z:Legacy property, use app.config['LOGIN_DISABLED'] instead.r   Nu'_login_disabled' is deprecated and will be removed in Flask-Login 0.7. Use 'LOGIN_DISABLED' in 'app.config' instead.rI   rJ   LOGIN_DISABLEDF)rL   rM   rN   r	   r   rb   rc   )rA   rL   s     rD   _login_disabledLoginManager._login_disabled  sM     	  	 	
 %%))*:EBBrG   c                 \    SSK nUR                  S[        SS9  U[        R                  S'   g)zALegacy property setter, use app.config['LOGIN_DISABLED'] instead.r   Nr   rI   rJ   r   )rL   rM   rN   r   rb   )rA   newvaluerL   s      rD   r   r     s8     	  	 	
 08+,rG   )r<   r=   r>   r;   r.   r0   r:   r7   r1   r2   r/   r9   r4   r5   r3   r6   r8   )NT)T)N)__name__
__module____qualname____firstlineno____doc__rE   rO   r?   rg   rm   propertyrj   rt   rs   ry   r|   r   r   r   r   r   r   r   r   rT   r   r   r   setter__static_attributes__ rG   rD   r*   r*   *   s    :6x2;$8&t
" # #
% & &2&h.(<T8
"(
TF    8 8rG   r*   N),r   r   flaskr   r   r   r   r	   r
   r   r   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   mixinsr   r   r   r   r   r   r    r!   utilsr"   r#   r$   r%   r&   r'   re   r(   r*   r   rG   rD   <module>r      s          !    $ # #  # !   ! * # ,   ( & & " , - ' & % *     $ . "u8 u8rG   