ó
ø¢TQc           @  s1  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 d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z d  d l m Z m Z d  d l m Z d  d l m Z m Z d  d l m  Z  d  d l! m" Z" d 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/ f d! „  ƒ  YZ0 e	 g  d" d# d$ g D] Z1 e1 e0 j2 e1 f ^ qïƒ e0 _2 d% e j, f d& „  ƒ  YZ3 d' S((   iÿÿÿÿ(   t   unicode_literals(   t   forms(   t   flatatt(   t   loader(   t
   SortedDict(   t   format_htmlt   format_html_join(   t   int_to_base36(   t	   mark_safe(   t   capfirst(   t   ugettextt   ugettext_lazy(   t   authenticatet   get_user_model(   t   User(   t   UNUSABLE_PASSWORDt   identify_hasher(   t   default_token_generator(   t   get_current_sitei   c         C  s)   d |  t   d t t |  ƒ t  d ƒ f S(   Nu   %s%su   *i    (   t   UNMASKED_DIGITS_TO_SHOWt   maxt   len(   t   p(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   <lambda>   s    t   ReadOnlyPasswordHashWidgetc           B  s   e  Z d  „  Z RS(   c         C  s¼   | } |  j  | ƒ } | s( | t k rA t d t d ƒ ƒ } ne y t | ƒ } Wn' t k
 rz t d t d ƒ ƒ } n, Xt d d d „  | j | ƒ j ƒ  Dƒ ƒ } t	 d t
 | ƒ | ƒ S(   Nu   <strong>%s</strong>u   No password set.u5   Invalid password format or unknown hashing algorithm.u    u   <strong>{0}</strong>: {1} c         s  s'   |  ] \ } } t  | ƒ | f Vq d  S(   N(   R
   (   t   .0t   keyt   value(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pys	   <genexpr>)   s   u   <div{0}>{1}</div>(   t   build_attrsR   R   R
   R   t
   ValueErrorR   t   safe_summaryt   itemsR   R   (   t   selft   nameR   t   attrst   encodedt   final_attrst   summaryt   hasher(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   render   s    	(   t   __name__t
   __module__R'   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR      s   t   ReadOnlyPasswordHashFieldc           B  s    e  Z e Z d  „  Z d „  Z RS(   c         O  s-   | j  d t ƒ t t |  ƒ j | | Ž  d  S(   Nu   required(   t
   setdefaultt   Falset   superR*   t   __init__(   R    t   argst   kwargs(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR.   3   s    c         C  s   | S(   N(    (   R    t   datat   initial(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt
   bound_data7   s    (   R(   R)   R   t   widgetR.   R3   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR*   0   s   	t   UserCreationFormc           B  sð   e  Z d  Z i e d ƒ d 6e d ƒ d 6Z e j d e d ƒ d d d	 d
 d e d ƒ d i e d ƒ d 6ƒ Z e j d e d ƒ d e j	 ƒ Z
 e j d e d ƒ d e j	 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)   A user with that username already exists.u   duplicate_usernameu%   The two password fields didn't match.u   password_mismatcht   labelu   Usernamet
   max_lengthi   t   regexu   ^[\w.@+-]+$t	   help_textuE   Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.t   error_messagesuF   This value may contain only letters, numbers and @/./+/-/_ characters.u   invalidu   PasswordR4   u   Password confirmationu3   Enter the same password as above, for verification.t   Metac           B  s   e  Z e Z d Z RS(   u   username(   u   username(   R(   R)   R   t   modelt   fields(    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR;   S   s   c         C  sV   |  j  d } y t j j d | ƒ Wn t j k
 r; | SXt j |  j d ƒ ‚ d  S(   Nu   usernamet   usernameu   duplicate_username(   t   cleaned_dataR   t   _default_managert   gett   DoesNotExistR   t   ValidationErrorR:   (   R    R>   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_usernameW   s    c         C  sY   |  j  j d ƒ } |  j  j d ƒ } | rU | rU | | k rU t j |  j d ƒ ‚ n  | S(   Nu	   password1u	   password2u   password_mismatch(   R?   RA   R   RC   R:   (   R    t	   password1t	   password2(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_password2a   s    c         C  sF   t  t |  ƒ j d t ƒ } | j |  j d ƒ | rB | j ƒ  n  | S(   Nt   commitu	   password1(   R-   R5   t   saveR,   t   set_passwordR?   (   R    RH   t   user(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRI   i   s
    (    (   R(   R)   t   __doc__t   _R:   R   t
   RegexFieldR>   t	   CharFieldt   PasswordInputRE   RF   R;   RD   RG   t   TrueRI   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR5   =   s$   		
	t   UserChangeFormc           B  s‘   e  Z e j d  e d ƒ d d d d d e d ƒ d i e d	 ƒ d
 6ƒ Z e d  e d ƒ d e d ƒ ƒ Z d d d „  ƒ  YZ d „  Z	 d „  Z
 RS(   R6   u   UsernameR7   i   R8   u   ^[\w.@+-]+$R9   uE   Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.R:   uF   This value may contain only letters, numbers and @/./+/-/_ characters.u   invalidu   Passwordu–   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 RS(    (   R(   R)   R   R<   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR;   ~   s   c         O  sV   t  t |  ƒ j | | Ž  |  j j d d  ƒ } | d  k	 rR | j j d ƒ | _ n  d  S(   Nu   user_permissionsu   content_type(   R-   RR   R.   R=   RA   t   Nonet   querysett   select_related(   R    R/   R0   t   f(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR.      s    c         C  s   |  j  d S(   Nu   password(   R2   (   R    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_password‡   s    (    (   R(   R)   R   RN   RM   R>   R*   t   passwordR;   R.   RW   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRR   q   s   		t   AuthenticationFormc           B  sž   e  Z d  Z e j d d ƒ Z e j d e d ƒ d e j ƒ Z i e d ƒ d 6e 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.
    R7   iþ   R6   u   PasswordR4   u^   Please enter a correct %(username)s and password. Note that both fields may be case-sensitive.u   invalid_loginu]   Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.u
   no_cookiesu   This account is inactive.u   inactivec         O  s   | |  _  d |  _ t t |  ƒ j | | Ž  t ƒ  } | j j | j	 ƒ |  _
 |  j d j s{ t |  j
 j ƒ |  j d _ n  d S(   u  
        If request is passed in, the form will validate that cookies are
        enabled. Note that the request (a HttpRequest object) must have set a
        cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
        running this validation.
        u   usernameN(   t   requestRS   t
   user_cacheR-   RY   R.   R   t   _metat	   get_fieldt   USERNAME_FIELDt   username_fieldR=   R6   R	   t   verbose_name(   R    RZ   R/   R0   t	   UserModel(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR.   ž   s    			c         C  sº   |  j  j d ƒ } |  j  j d ƒ } | r© | r© t d | d | ƒ |  _ |  j d  k r t j |  j d i |  j j	 d 6ƒ ‚ q© |  j j
 s© t j |  j d ƒ ‚ q© n  |  j ƒ  |  j  S(   Nu   usernameu   passwordR>   RX   u   invalid_loginu   inactive(   R?   RA   R   R[   RS   R   RC   R:   R_   R`   t	   is_activet   check_for_test_cookie(   R    R>   RX   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean¯   s    
c         C  s9   |  j  r5 |  j  j j ƒ  r5 t j |  j d ƒ ‚ n  d  S(   Nu
   no_cookies(   RZ   t   sessiont   test_cookie_workedR   RC   R:   (   R    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRc   À   s    c         C  s   |  j  r |  j  j Sd  S(   N(   R[   t   idRS   (   R    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   get_user_idÄ   s    	
c         C  s   |  j  S(   N(   R[   (   R    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   get_userÉ   s    N(   R(   R)   RL   R   RO   R>   RM   RP   RX   R:   RS   R.   Rd   Rc   Rh   Ri   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRY   Ž   s   !			t   PasswordResetFormc           B  sm   e  Z i e d  ƒ d 6e d ƒ d 6Z e j d e d ƒ d d ƒ Z d „  Z d d	 d
 e	 e
 d d d „ Z RS(   u[   That email address doesn't have an associated user account. Are you sure you've registered?u   unknownuN   The user account associated with this email address cannot reset the password.u   unusableR6   u   EmailR7   iþ   c         C  s¾   t  ƒ  } |  j d } | j j d | ƒ |  _ t |  j ƒ sV t j |  j d ƒ ‚ n  t	 d „  |  j Dƒ ƒ sˆ t j |  j d ƒ ‚ n  t	 d „  |  j Dƒ ƒ rº t j |  j d ƒ ‚ n  | S(   uT   
        Validates that an active user exists with the given email address.
        u   emailt   email__iexactu   unknownc         s  s   |  ] } | j  Vq d  S(   N(   Rb   (   R   RK   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pys	   <genexpr>ß   s    c         s  s   |  ] } | j  t k Vq d  S(   N(   RX   R   (   R   RK   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pys	   <genexpr>â   s   u   unusable(
   R   R?   R@   t   filtert   users_cacheR   R   RC   R:   t   any(   R    Ra   t   email(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_emailÖ   s    		u'   registration/password_reset_subject.txtu&   registration/password_reset_email.htmlc         C  s  d d l  m } xì |  j D]á }	 | sG t | ƒ }
 |
 j } |
 j } n
 | } } i |	 j d 6| d 6| d 6t |	 j ƒ d 6|	 d 6| j	 |	 ƒ d 6| rŸ d	 p¢ d
 d 6} t
 j | | ƒ } d j | j ƒ  ƒ } t
 j | | ƒ } | | | | |	 j g ƒ q Wd S(   ue   
        Generates a one-use only link for resetting password and sends to the
        user.
        iÿÿÿÿ(   t	   send_mailu   emailu   domainu	   site_nameu   uidu   useru   tokenu   httpsu   httpu   protocolu    N(   t   django.core.mailRq   Rm   R   R!   t   domainRo   R   t   pkt
   make_tokenR   t   render_to_stringt   joint
   splitlines(   R    t   domain_overridet   subject_template_namet   email_template_namet	   use_httpst   token_generatort
   from_emailRZ   Rq   RK   t   current_sitet	   site_nameRs   t   ct   subjectRo   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRI   ç   s&    		

N(   R(   R)   RM   R:   R   t
   EmailFieldRo   Rp   RS   R,   R   RI   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRj   Í   s   	t   SetPasswordFormc           B  s   e  Z d  Z i e d ƒ d 6Z e j d e d ƒ d e j ƒ Z e j d e d ƒ d e j ƒ Z	 d „  Z
 d „  Z e d	 „ Z RS(
   uc   
    A form that lets a user change set his/her password without entering the
    old password
    u%   The two password fields didn't match.u   password_mismatchR6   u   New passwordR4   u   New password confirmationc         O  s&   | |  _  t t |  ƒ j | | Ž  d  S(   N(   RK   R-   R„   R.   (   R    RK   R/   R0   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR.     s    	c         C  s\   |  j  j d ƒ } |  j  j d ƒ } | rX | rX | | k rX t j |  j d ƒ ‚ qX n  | S(   Nu   new_password1u   new_password2u   password_mismatch(   R?   RA   R   RC   R:   (   R    RE   RF   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_new_password2  s    c         C  s4   |  j  j |  j d ƒ | r- |  j  j ƒ  n  |  j  S(   Nu   new_password1(   RK   RJ   R?   RI   (   R    RH   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRI   "  s    (   R(   R)   RL   RM   R:   R   RO   RP   t   new_password1t   new_password2R.   R…   RQ   RI   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR„     s   			t   PasswordChangeFormc           B  sW   e  Z d  Z e e j i e d ƒ d 6 Z e j d e d ƒ d e j	 ƒ Z
 d „  Z RS(   u]   
    A form that lets a user change his/her password by entering
    their old password.
    uA   Your old password was entered incorrectly. Please enter it again.u   password_incorrectR6   u   Old passwordR4   c         C  s<   |  j  d } |  j j | ƒ s8 t j |  j d ƒ ‚ n  | S(   uC   
        Validates that the old_password field is correct.
        u   old_passwordu   password_incorrect(   R?   RK   t   check_passwordR   RC   R:   (   R    t   old_password(    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   clean_old_password5  s
    (   R(   R)   RL   t   dictR„   R:   RM   R   RO   RP   RŠ   R‹   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRˆ   )  s   u   old_passwordu   new_password1u   new_password2t   AdminPasswordChangeFormc           B  s   e  Z d  Z i e d ƒ d 6Z e j d e d ƒ d e j ƒ Z e j d e d ƒ d e j ƒ Z	 d „  Z
 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_mismatchR6   u   PasswordR4   u   Password (again)c         O  s&   | |  _  t t |  ƒ j | | Ž  d  S(   N(   RK   R-   R   R.   (   R    RK   R/   R0   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR.   Q  s    	c         C  s\   |  j  j d ƒ } |  j  j d ƒ } | rX | rX | | k rX t j |  j d ƒ ‚ qX n  | S(   Nu	   password1u	   password2u   password_mismatch(   R?   RA   R   RC   R:   (   R    RE   RF   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRG   U  s    c         C  s4   |  j  j |  j d ƒ | r- |  j  j ƒ  n  |  j  S(   u)   
        Saves the new password.
        u	   password1(   RK   RJ   R?   RI   (   R    RH   (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyRI   ^  s    (   R(   R)   RL   RM   R:   R   RO   RP   RE   RF   R.   RG   RQ   RI   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyR   E  s   			N(4   t
   __future__R    t   djangoR   t   django.forms.utilR   t   django.templateR   t   django.utils.datastructuresR   t   django.utils.htmlR   R   t   django.utils.httpR   t   django.utils.safestringR   t   django.utils.textR	   t   django.utils.translationR
   R   RM   t   django.contrib.authR   R   t   django.contrib.auth.modelsR   t   django.contrib.auth.hashersR   R   t   django.contrib.auth.tokensR   t   django.contrib.sites.modelsR   R   t   mask_passwordt   WidgetR   t   FieldR*   t	   ModelFormR5   RR   t   FormRY   Rj   R„   Rˆ   t   kt   base_fieldsR   (    (    (    s2   ../Django//lib/python/django/contrib/auth/forms.pyt   <module>   s8   	4?;!2