ó
ø¢TQc           @   s¦   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z m Z m Z d Z	 d Z
 d Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   ImproperlyConfigured(   t   import_module(   t   user_logged_int   user_logged_outt   user_login_failedt   _auth_user_idt   _auth_user_backendt   nextc         C   sÄ   |  j  d ƒ } |  |  |  | d } } y t | ƒ } WnE t k
 rc } t d |  | f ƒ ‚ n t k
 r t d ƒ ‚ n Xy t | | ƒ } Wn' t k
 r¼ t d | | f ƒ ‚ n X| ƒ  S(   Nt   .i   s/   Error importing authentication backend %s: "%s"sf   Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?s9   Module "%s" does not define a "%s" authentication backend(   t   rfindR   t   ImportErrorR    t
   ValueErrort   getattrt   AttributeError(   t   patht   it   modulet   attrt   modt   et   cls(    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   load_backend   s    c          C   sV   d d l  m }  g  } x$ |  j D] } | j t | ƒ ƒ q  W| sR t d ƒ ‚ n  | S(   Niÿÿÿÿ(   t   settingss\   No authentication backends have been defined. Does AUTHENTICATION_BACKENDS contain anything?(   t   django.confR   t   AUTHENTICATION_BACKENDSt   appendR   R    (   R   t   backendst   backend_path(    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   get_backends   s    c         C   sL   t  j d t  j ƒ } d } x* |  D]" } | j | ƒ r" | |  | <q" q" W|  S(   s¶   
    Cleans a dictionary of credentials of potentially sensitive info before
    sending to less secure functions.

    Not comprehensive - intended for user_login_failed signal
    s'   api|token|key|secret|password|signatures   ********************(   t   ret   compilet   It   search(   t   credentialst   SENSITIVE_CREDENTIALSt   CLEANSED_SUBSTITUTEt   key(    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   _clean_credentials&   s    c          K   s   xj t  ƒ  D]_ } y | j |    } Wn t k
 r9 q
 n X| d k rL q
 n  d | j | j j f | _ | SWt j	 d t d t
 |  ƒ ƒ d S(   sC   
    If the given credentials are valid, return a User object.
    s   %s.%st   senderR!   N(   R   t   authenticatet	   TypeErrort   Nonet
   __module__t	   __class__t   __name__t   backendR   t   sendR%   (   R!   R-   t   user(    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyR'   5   s    c         C   s»   | d k r |  j } n  t |  j k rP |  j t | j k r] |  j j ƒ  q] n |  j j ƒ  | j |  j t <| j |  j t <t	 |  d ƒ r˜ | |  _ n  t
 j d | j d |  d | ƒ d S(   sÕ   
    Persist a user id and a backend in the request. This way a user doesn't
    have to reauthenticate on every request. Note that data set during
    the anonymous session is retained when the user logs in.
    R/   R&   t   requestN(   R)   R/   t   SESSION_KEYt   sessiont   pkt   flusht	   cycle_keyR-   t   BACKEND_SESSION_KEYt   hasattrR   R.   R+   (   R0   R/   (    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   loginJ   s    c         C   s•   t  |  d d ƒ } t | d ƒ r7 | j ƒ  r7 d } n  t j d | j d |  d | ƒ |  j j ƒ  t |  d ƒ r‘ d d l	 m
 } | ƒ  |  _ n  d S(   sb   
    Removes the authenticated user's ID from the request and flushes their
    session data.
    R/   t   is_authenticatedR&   R0   iÿÿÿÿ(   t   AnonymousUserN(   R   R)   R7   R9   R   R.   R+   R2   R4   t   django.contrib.auth.modelsR:   R/   (   R0   R/   R:   (    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   logoutb   s    	c          C   s‘   d d l  m }  d d l m } y |  j j d ƒ \ } } Wn t k
 r[ t d ƒ ‚ n X| | | ƒ } | d k r t d |  j ƒ ‚ n  | S(   s4   Return the User model that is active in this projectiÿÿÿÿ(   R   (   t	   get_modelR   s:   AUTH_USER_MODEL must be of the form 'app_label.model_name's@   AUTH_USER_MODEL refers to model '%s' that has not been installedN(	   R   R   t   django.db.modelsR=   t   AUTH_USER_MODELt   splitR   R    R)   (   R   R=   t	   app_labelt
   model_namet
   user_model(    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   get_user_modelt   s    c         C   ss   d d l  m } yB |  j t } |  j t } t | ƒ } | j | ƒ pN | ƒ  } Wn t k
 rn | ƒ  } n X| S(   Niÿÿÿÿ(   R:   (   R;   R:   R2   R1   R6   R   t   get_usert   KeyError(   R0   R:   t   user_idR   R-   R/   (    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyRE   ƒ   s    (   R   t   django.core.exceptionsR    t   django.utils.importlibR   t   django.contrib.auth.signalsR   R   R   R1   R6   t   REDIRECT_FIELD_NAMER   R   R%   R'   R8   R<   RD   RE   (    (    (    s5   ../Django//lib/python/django/contrib/auth/__init__.pyt   <module>   s   		
					