ó
@()Qc           @  s`   d  d l  m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(	   iÿÿÿÿ(   t   unicode_literals(   t   get_user_model(   t
   Permissiont   ModelBackendc           B  sS   e  Z d  Z d d d „ Z d d „ Z d d „ Z d d „ Z d „  Z d „  Z	 RS(   u@   
    Authenticates against django.contrib.auth.models.User.
    c         K  so   t  ƒ  } | d  k r* | j | j ƒ } n  y) | j j | ƒ } | j | ƒ rR | SWn | j k
 rj d  SXd  S(   N(   R   t   Nonet   gett   USERNAME_FIELDt   _default_managert   get_by_natural_keyt   check_passwordt   DoesNotExist(   t   selft   usernamet   passwordt   kwargst	   UserModelt   user(    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   authenticate   s    	c         C  sÛ   | j  ƒ  s | d k	 r t ƒ  St | d ƒ sÔ | j rI t j j ƒ  } n> t ƒ  j	 j
 d ƒ } d | j ƒ  } t j j i | | 6  } | j d d ƒ j ƒ  } t g  | D] \ } } d | | f ^ q© ƒ | _ n  | j S(   uh   
        Returns a set of permission strings that this user has through his/her
        groups.
        u   _group_perm_cacheu   groupsu	   group__%su   content_type__app_labelu   codenameu   %s.%sN(   t   is_anonymousR   t   sett   hasattrt   is_superuserR   t   objectst   allR   t   _metat	   get_fieldt   related_query_namet   filtert   values_listt   order_byt   _group_perm_cache(   R   t   user_objt   objt   permst   user_groups_fieldt   user_groups_queryt   ctt   name(    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   get_group_permissions   s    	5c         C  s   | j  ƒ  s | d  k	 r t ƒ  St | d ƒ sˆ t g  | j j ƒ  D] } d | j j | j f ^ qA ƒ | _	 | j	 j
 |  j | ƒ ƒ n  | j	 S(   Nu   _perm_cacheu   %s.%s(   R   R   R   R   t   user_permissionst   select_relatedt   content_typet	   app_labelt   codenamet   _perm_cachet   updateR&   (   R   R   R    t   p(    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   get_all_permissions(   s    >c         C  s#   | j  s t S| |  j | | ƒ k S(   N(   t	   is_activet   FalseR/   (   R   R   t   permR    (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   has_perm0   s    	c         C  sH   | j  s t Sx4 |  j | ƒ D]# } | | j d ƒ  | k r t Sq Wt S(   uV   
        Returns True if user_obj has any permissions in the given app_label.
        u   .(   R0   R1   R/   t   indext   True(   R   R   R*   R2   (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   has_module_perms5   s    	c         C  s<   y  t  ƒ  } | j j d | ƒ SWn | j k
 r7 d  SXd  S(   Nt   pk(   R   R   R   R
   R   (   R   t   user_idR   (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   get_user@   s
    	N(
   t   __name__t
   __module__t   __doc__R   R   R&   R/   R3   R6   R9   (    (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyR      s   	t   RemoteUserBackendc           B  s/   e  Z d  Z e Z d „  Z d „  Z d „  Z RS(   uÆ  
    This backend is to be used in conjunction with the ``RemoteUserMiddleware``
    found in the middleware module of this package, and is used when the server
    is handling authentication outside of Django.

    By default, the ``authenticate`` method creates ``User`` objects for
    usernames that don't already exist in the database.  Subclasses can disable
    this behavior by setting the ``create_unknown_user`` attribute to
    ``False``.
    c         C  sŸ   | s
 d Sd } |  j | ƒ } t ƒ  } |  j rn | j j i | | j 6  \ } } | r› |  j | ƒ } q› n- y | j j | ƒ } Wn | j	 k
 rš n X| S(   u  
        The username passed as ``remote_user`` is considered trusted.  This
        method simply returns the ``User`` object with the given username,
        creating a new ``User`` object if ``create_unknown_user`` is ``True``.

        Returns None if ``create_unknown_user`` is ``False`` and a ``User``
        object with the given username is not found in the database.
        N(
   R   t   clean_usernameR   t   create_unknown_userR   t   get_or_createR   t   configure_userR   R
   (   R   t   remote_userR   R   R   t   created(    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyR   W   s    			c         C  s   | S(   uÉ   
        Performs any cleaning on the "username" prior to using it to get or
        create the user object.  Returns the cleaned username.

        By default, returns the username unchanged.
        (    (   R   R   (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyR>   w   s    c         C  s   | S(   u‚   
        Configures a user after creation and returns the updated user.

        By default, returns the user unmodified.
        (    (   R   R   (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyRA   €   s    (   R:   R;   R<   R5   R?   R   R>   RA   (    (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyR=   H   s
   
	 		N(	   t
   __future__R    t   django.contrib.authR   t   django.contrib.auth.modelsR   t   objectR   R=   (    (    (    s5   ../Django//lib/python/django/contrib/auth/backends.pyt   <module>   s   B