ó
®â0_c           @  s  d  d l  m Z d  d l Z d  d l m Z d  d l m Z m Z m Z d  d l	 m
 Z
 m Z 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 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 m  Z! e ƒ  Z" d „  Z# d e j$ f d „  ƒ  YZ% d e j& f d „  ƒ  YZ' d e j( f d „  ƒ  YZ) d e j* f d „  ƒ  YZ+ d e j* f d „  ƒ  YZ, d e j- f d „  ƒ  YZ. d e j- f d „  ƒ  YZ/ d e j- f d  „  ƒ  YZ0 d! e0 f d" „  ƒ  YZ1 d# e j- f d$ „  ƒ  YZ2 d S(%   iÿÿÿÿ(   t   unicode_literalsN(   t   forms(   t   authenticatet   get_user_modelt   password_validation(   t   UNUSABLE_PASSWORD_PREFIXt   identify_hasher(   t   User(   t   default_token_generator(   t   get_current_site(   t   EmailMultiAlternatives(   t   loader(   t   force_bytes(   t   urlsafe_base64_encode(   t   PY3(   t   capfirst(   t   ugettextt   ugettext_lazyc         C  sV   t  j d |  ƒ } t  j d | ƒ } t r@ | j ƒ  | j ƒ  k S| j ƒ  | j ƒ  k S(   u¡   
    Perform case-insensitive comparison of two identifiers, using the
    recommended algorithm from Unicode Technical Report 36, section
    2.11.2(B)(2).
    u   NFKC(   t   unicodedatat	   normalizeR   t   casefoldt   lower(   t   s1t   s2t   normalized1t   normalized2(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   _unicode_ci_compare   s
    t   ReadOnlyPasswordHashWidgetc           B  s   e  Z d  Z d „  Z RS(   u)   auth/widgets/read_only_password_hash.htmlc   	      C  sê   t  t |  ƒ j | | | ƒ } g  } | s: | j t ƒ rW | j i t d ƒ d 6ƒ n… y t | ƒ } Wn+ t k
 r” | j i t d ƒ d 6ƒ nH XxD | j	 | ƒ j
 ƒ  D]- \ } } | j i t | ƒ d 6| d 6ƒ q« W| | d <| S(   Nu   No password set.u   labelu5   Invalid password format or unknown hashing algorithm.u   valueu   summary(   t   superR   t   get_contextt
   startswithR   t   appendR   R   t
   ValueErrort   safe_summaryt   items(	   t   selft   namet   valuet   attrst   contextt   summaryt   hashert   keyt   value_(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR   +   s    "%
(   t   __name__t
   __module__t   template_nameR   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR   (   s   t   ReadOnlyPasswordHashFieldc           B  s)   e  Z e Z d  „  Z d „  Z d „  Z RS(   c         O  s-   | j  d t ƒ t t |  ƒ j | | Ž  d  S(   Nu   required(   t
   setdefaultt   FalseR   R/   t   __init__(   R#   t   argst   kwargs(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   ?   s    c         C  s   | S(   N(    (   R#   t   datat   initial(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt
   bound_dataC   s    c         C  s   t  S(   N(   R1   (   R#   R6   R5   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   has_changedH   s    (   R,   R-   R   t   widgetR2   R7   R8   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR/   <   s   		t   UsernameFieldc           B  s   e  Z d  „  Z RS(   c         C  s"   t  j d t t |  ƒ j | ƒ ƒ S(   Nu   NFKC(   R   R   R   R:   t	   to_python(   R#   R%   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR;   M   s    (   R,   R-   R;   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR:   L   s   t   UserCreationFormc        
   B  s¸   e  Z d  Z i e d ƒ d 6Z e j d e d ƒ d e d e j d e	 j
 ƒ  ƒ Z e j d e d ƒ d e j d e d e d	 ƒ ƒ Z d
 d d „  ƒ  YZ d „  Z d „  Z e d „ Z RS(   uc   
    A form that creates a user, with no privileges, from the given username and
    password.
    u%   The two password fields didn't match.u   password_mismatcht   labelu   Passwordt   stripR9   t	   help_textu   Password confirmationu4   Enter the same password as before, for verification.t   Metac           B  s!   e  Z e Z d Z i e d  6Z RS(   u   username(   u   username(   R,   R-   R   t   modelt   fieldsR:   t   field_classes(    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR@   f   s   c         O  sb   t  t |  ƒ j | | Ž  |  j j j |  j k r^ |  j |  j j j j j j	 i t
 d 6ƒ n  d  S(   Nu	   autofocus(   R   R<   R2   t   _metaRA   t   USERNAME_FIELDRB   R9   R&   t   updatet   True(   R#   R3   R4   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   k   s    c         C  s–   |  j  j d ƒ } |  j  j d ƒ } | r[ | r[ | | k r[ t j |  j d d d ƒ‚ n  |  j  j d ƒ |  j _ t j |  j  j d ƒ |  j ƒ | S(   Nu	   password1u	   password2u   password_mismatcht   codeu   username(	   t   cleaned_datat   getR   t   ValidationErrort   error_messagest   instancet   usernameR   t   validate_password(   R#   t	   password1t	   password2(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   clean_password2p   s    c         C  sF   t  t |  ƒ j d t ƒ } | j |  j d ƒ | rB | j ƒ  n  | S(   Nt   commitu	   password1(   R   R<   t   saveR1   t   set_passwordRI   (   R#   RS   t   user(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRT   |   s
    (    (   R,   R-   t   __doc__t   _RL   R   t	   CharFieldR1   t   PasswordInputR   t"   password_validators_help_text_htmlRP   RQ   R@   R2   RR   RG   RT   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR<   Q   s"   						t   UserChangeFormc           B  sN   e  Z e d  e d ƒ d e d ƒ ƒ Z d d d „  ƒ  YZ d „  Z d „  Z RS(	   R=   u   PasswordR?   u™   Raw passwords are not stored, so there is no way to see this user's password, but you can change the password using <a href="../password/">this form</a>.R@   c           B  s!   e  Z e Z d  Z i e d 6Z RS(   u   __all__u   username(   R,   R-   R   RA   RB   R:   RC   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR@   Ž   s   c         O  sS   t  t |  ƒ j | | Ž  |  j j d ƒ } | d  k	 rO | j j d ƒ | _ n  d  S(   Nu   user_permissionsu   content_type(   R   R\   R2   RB   RJ   t   Nonet   querysett   select_related(   R#   R3   R4   t   f(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   “   s    c         C  s   |  j  d S(   Nu   password(   R6   (   R#   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   clean_password™   s    (    (   R,   R-   R/   RX   t   passwordR@   R2   Ra   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR\   „   s   	t   AuthenticationFormc        	   B  s­   e  Z d  Z e d d d e j d i e d 6ƒ ƒ Z e j d e	 d ƒ d e
 d e j ƒ Z i e	 d	 ƒ d
 6e	 d ƒ d 6Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   us   
    Base class for authenticating users. Extend this to get a form that accepts
    username/password logins.
    t
   max_lengthiþ   R9   R&   u	   autofocusR=   u   PasswordR>   u^   Please enter a correct %(username)s and password. Note that both fields may be case-sensitive.u   invalid_loginu   This account is inactive.u   inactivec         O  s|   | |  _  d |  _ t t |  ƒ j | | Ž  t j j t j	 ƒ |  _
 |  j d j d k rx t |  j
 j ƒ |  j d _ n  d S(   u‘   
        The 'request' parameter is set for custom auth use by subclasses.
        The form data comes in via the standard 'data' kwarg.
        u   usernameN(   t   requestR]   t
   user_cacheR   Rc   R2   t	   UserModelRD   t	   get_fieldRE   t   username_fieldRB   R=   R   t   verbose_name(   R#   Re   R3   R4   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   ·   s    		c         C  s¯   |  j  j d ƒ } |  j  j d ƒ } | d  k	 r¨ | r¨ t |  j d | d | ƒ|  _ |  j d  k r• t j |  j d d d d i |  j	 j
 d 6ƒ‚ q¨ |  j |  j ƒ n  |  j  S(   Nu   usernameu   passwordRN   Rb   u   invalid_loginRH   t   params(   RI   RJ   R]   R   Re   Rf   R   RK   RL   Ri   Rj   t   confirm_login_allowed(   R#   RN   Rb   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   cleanÅ   s    c         C  s,   | j  s( t j |  j d d d ƒ‚ n  d S(   u›  
        Controls whether the given User may log in. This is a policy setting,
        independent of end-user authentication. This default behavior is to
        allow login by active users, and reject login by inactive users.

        If the given user cannot log in, this method should raise a
        ``forms.ValidationError``.

        If the given user may log in, this method should return None.
        u   inactiveRH   N(   t	   is_activeR   RK   RL   (   R#   RV   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRl   Ö   s    	c         C  s   |  j  r |  j  j Sd  S(   N(   Rf   t   idR]   (   R#   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   get_user_idç   s    	
c         C  s   |  j  S(   N(   Rf   (   R#   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   get_userì   s    N(   R,   R-   RW   R:   R   t	   TextInputRG   RN   RY   RX   R1   RZ   Rb   RL   R]   R2   Rm   Rl   Rp   Rq   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRc       s"   	
			t   PasswordResetFormc        
   B  s_   e  Z e j d  e d ƒ d d ƒ Z d	 d „ Z d „  Z d	 d d e	 e
 d	 d	 d	 d	 d „	 Z RS(
   R=   u   EmailRd   iþ   c         C  s   t  j | | ƒ } d j | j ƒ  ƒ } t  j | | ƒ } t | | | | g ƒ }	 | d k	 r‚ t  j | | ƒ }
 |	 j |
 d ƒ n  |	 j ƒ  d S(   uP   
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        u    u	   text/htmlN(   R   t   render_to_stringt   joint
   splitlinesR
   R]   t   attach_alternativet   send(   R#   t   subject_template_namet   email_template_nameR'   t
   from_emailt   to_emailt   html_email_template_namet   subjectt   bodyt   email_messaget
   html_email(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt	   send_mailó   s    c           sG   t  j ƒ  ‰ t  j j i ˆ  d ˆ 6t d 6  } ‡  ‡ f d †  | Dƒ S(   u  Given an email, return matching user(s) who should receive a reset.

        This allows subclasses to more easily customize the default policies
        that prevent inactive users and users with unusable passwords from
        resetting their password.
        u
   %s__iexactu	   is_activec         3  s9   |  ]/ } | j  ƒ  r t ˆ  t | ˆ ƒ ƒ r | Vq d  S(   N(   t   has_usable_passwordR   t   getattr(   t   .0t   u(   t   emailt   email_field_name(    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pys	   <genexpr>  s    (   Rg   t   get_email_field_namet   _default_managert   filterRG   (   R#   R‡   t   active_users(    (   R‡   Rˆ   s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt	   get_users  s
    u'   registration/password_reset_subject.txtu&   registration/password_reset_email.htmlc
      	   C  s  |  j  d }
 t j ƒ  } xí |  j |
 ƒ D]Ü } | sV t | ƒ } | j } | j } n
 | } } t | | ƒ } i | d 6| d 6| d 6t t	 | j
 ƒ ƒ d 6| d 6| j | ƒ d 6| rÀ d n d d	 6} |	 d k	 ræ | j |	 ƒ n  |  j | | | | | d
 | ƒq) Wd S(   ue   
        Generates a one-use only link for resetting password and sends to the
        user.
        u   emailu   domainu	   site_nameu   uidu   useru   tokenu   httpsu   httpu   protocolR}   N(   RI   Rg   R‰   R   R	   R$   t   domainR„   R   R   t   pkt
   make_tokenR]   RF   R‚   (   R#   t   domain_overrideRy   Rz   t	   use_httpst   token_generatorR{   Re   R}   t   extra_email_contextR‡   Rˆ   RV   t   current_sitet	   site_nameRŽ   t
   user_emailR'   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRT     s,    
	
N(   R,   R-   R   t
   EmailFieldRX   R‡   R]   R‚   R   R1   R   RT   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRs   ð   s   		t   SetPasswordFormc        	   B  s™   e  Z d  Z i e d ƒ d 6Z e j d e d ƒ d e j d e d e	 j
 ƒ  ƒ Z e j d e d ƒ d e d e j ƒ Z d	 „  Z d
 „  Z e d „ Z RS(   ua   
    A form that lets a user change set their password without entering the old
    password
    u%   The two password fields didn't match.u   password_mismatchR=   u   New passwordR9   R>   R?   u   New password confirmationc         O  s&   | |  _  t t |  ƒ j | | Ž  d  S(   N(   RV   R   R™   R2   (   R#   RV   R3   R4   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   O  s    	c         C  su   |  j  j d ƒ } |  j  j d ƒ } | r^ | r^ | | k r^ t j |  j d d d ƒ‚ q^ n  t j | |  j ƒ | S(   Nu   new_password1u   new_password2u   password_mismatchRH   (   RI   RJ   R   RK   RL   R   RO   RV   (   R#   RP   RQ   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   clean_new_password2S  s    c         C  s:   |  j  d } |  j j | ƒ | r3 |  j j ƒ  n  |  j S(   Nu   new_password1(   RI   RV   RU   RT   (   R#   RS   Rb   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRT   _  s
    (   R,   R-   RW   RX   RL   R   RY   RZ   R1   R   R[   t   new_password1t   new_password2R2   Rš   RG   RT   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR™   ;  s   					t   PasswordChangeFormc           B  s|   e  Z d  Z e e j i e d ƒ d 6 Z e j d e d ƒ d e	 d e j
 d i e d 6ƒ ƒ Z d	 d
 d g Z d „  Z RS(   u[   
    A form that lets a user change their password by entering their old
    password.
    uA   Your old password was entered incorrectly. Please enter it again.u   password_incorrectR=   u   Old passwordR>   R9   R&   u	   autofocusu   old_passwordu   new_password1u   new_password2c         C  sB   |  j  d } |  j j | ƒ s> t j |  j d d d ƒ‚ n  | S(   uC   
        Validates that the old_password field is correct.
        u   old_passwordu   password_incorrectRH   (   RI   RV   t   check_passwordR   RK   RL   (   R#   t   old_password(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   clean_old_passwordw  s    (   R,   R-   RW   t   dictR™   RL   RX   R   RY   R1   RZ   RG   RŸ   t   field_orderR    (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR   g  s   	t   AdminPasswordChangeFormc        
   B  sÊ   e  Z d  Z i e d ƒ d 6Z d Z e j d e d ƒ d e j d i e	 d 6ƒ d	 e
 d
 e j ƒ  ƒ Z e j d e d ƒ d e j d	 e
 d
 e d ƒ ƒ Z d „  Z d „  Z e	 d „ Z e d „  ƒ Z RS(   uN   
    A form used to change the password of a user in the admin interface.
    u%   The two password fields didn't match.u   password_mismatchu   requiredR=   u   PasswordR9   R&   u	   autofocusR>   R?   u   Password (again)u4   Enter the same password as before, for verification.c         O  s&   | |  _  t t |  ƒ j | | Ž  d  S(   N(   RV   R   R£   R2   (   R#   RV   R3   R4   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR2   ™  s    	c         C  su   |  j  j d ƒ } |  j  j d ƒ } | r^ | r^ | | k r^ t j |  j d d d ƒ‚ q^ n  t j | |  j ƒ | S(   Nu	   password1u	   password2u   password_mismatchRH   (   RI   RJ   R   RK   RL   R   RO   RV   (   R#   RP   RQ   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRR     s    c         C  s:   |  j  d } |  j j | ƒ | r3 |  j j ƒ  n  |  j S(   u)   
        Saves the new password.
        u	   password1(   RI   RV   RU   RT   (   R#   RS   Rb   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyRT   ©  s
    c         C  sC   t  t |  ƒ j } x' |  j j ƒ  D] } | | k r" g  Sq" Wd g S(   Nu   password(   R   R£   t   changed_dataRB   t   keys(   R#   R5   R$   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR¤   ³  s
    (   R,   R-   RW   RX   RL   t   required_css_classR   RY   RZ   RG   R1   R   R[   RP   RQ   R2   RR   RT   t   propertyR¤   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyR£   „  s$   					
(3   t
   __future__R    R   t   djangoR   t   django.contrib.authR   R   R   t   django.contrib.auth.hashersR   R   t   django.contrib.auth.modelsR   t   django.contrib.auth.tokensR   t   django.contrib.sites.shortcutsR	   t   django.core.mailR
   t   django.templateR   t   django.utils.encodingR   t   django.utils.httpR   t   django.utils.sixR   t   django.utils.textR   t   django.utils.translationR   R   RX   Rg   R   t   WidgetR   t   FieldR/   RY   R:   t	   ModelFormR<   R\   t   FormRc   Rs   R™   R   R£   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/forms.pyt   <module>   s4   		3PK,