Ńň
0NÜJc           @   s˛   d  Z  d d k l Z d d k l Z d d k l Z d d k l	 Z	 h d d 6Z
 d e i f d	     YZ d
 e f d     YZ d e f d     YZ d e f d     YZ d S(   s3   
Forms and validation code for user registration.

i˙˙˙˙(   t   User(   t   forms(   t   ugettext_lazy(   t   RegistrationProfilet   requiredt   classt   RegistrationFormc        
   B   ső   e  Z d  Z e i d d d d d e i d e  d e d   Z e i	 d e i d e
 e d	 d
  d e d   Z e i d e i d e d e  d e d   Z e i d e i d e d e  d e d   Z d   Z d   Z d   Z RS(   s  
    Form for registering a new user account.
    
    Validates that the requested username is not already in use, and
    requires the password to be entered twice to catch typos.
    
    Subclasses should feel free to add any additional validation they
    need, but should either preserve the base ``save()`` or implement
    a ``save()`` method which returns a ``User``.
    
    t   regexs   ^\S+$t
   max_lengthi   t   widgett   attrst   labelu   usernamet	   maxlengthiK   u   email addresst   render_valueu   passwordu   password (again)c         C   sZ   y  t  i i d |  i d  } Wn t  i j
 o |  i d SXt i t d    d S(   sh   
        Validate that the username is alphanumeric and is not already
        in use.
        
        t   username__iexactt   usernameu6   This username is already taken. Please choose another.N(   R    t   objectst   gett   cleaned_datat   DoesNotExistR   t   ValidationErrort   _(   t   selft   user(    (    s3   /var/www/Pootle/external_apps/registration/forms.pyt   clean_username-   s
     c         C   s_   d |  i  j oH d |  i  j o8 |  i  d |  i  d j o t i t d    qX n |  i  S(   sŕ   
        Verifiy that the values entered into the two password fields
        match. Note that an error here will end up in
        ``non_field_errors()`` because it doesn't apply to a single
        field.
        
        t	   password1t	   password2u)   You must type the same password each time(   R   R   R   R   (   R   (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyt   clean9   s     c         C   s:   t  i i d |  i d d |  i d d |  i d  } | S(   s˝   
        Create the new ``User`` and ``RegistrationProfile``, and
        returns the ``User`` (by calling
        ``RegistrationProfile.objects.create_inactive_user()``).
        
        R   t   passwordR   t   email(   R   R   t   create_inactive_userR   (   R   t   new_user(    (    s3   /var/www/Pootle/external_apps/registration/forms.pyt   saveF   s    (   t   __name__t
   __module__t   __doc__R   t
   RegexFieldt	   TextInputt
   attrs_dictR   R   t
   EmailFieldt   dictR   t	   CharFieldt   PasswordInputt   FalseR   R   R   R   R    (    (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyR      s   !!		t   RegistrationFormTermsOfServicec        	   B   sE   e  Z d  Z e i d e i d e  d e d  d h d d 6 Z RS(   s}   
    Subclass of ``RegistrationForm`` which adds a required checkbox
    for agreeing to a site's Terms of Service.
    
    R	   R
   R   u-   I have read and agree to the Terms of Servicet   error_messagesu'   You must agree to the terms to registerR   (	   R!   R"   R#   R   t   BooleanFieldt   CheckboxInputR&   R   t   tos(    (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyR,   S   s   t   RegistrationFormUniqueEmailc           B   s   e  Z d  Z d   Z RS(   sa   
    Subclass of ``RegistrationForm`` which enforces uniqueness of
    email addresses.
    
    c         C   sA   t  i i d |  i d  o t i t d    n |  i d S(   sc   
        Validate that the supplied email address is unique for the
        site.
        
        t   email__iexactR   uN   This email address is already in use. Please supply a different email address.(   R    R   t   filterR   R   R   R   (   R   (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyt   clean_emaild   s    (   R!   R"   R#   R4   (    (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyR1   ^   s   t   RegistrationFormNoFreeEmailc           B   s>   e  Z d  Z d d d d d d d d d	 d
 d g Z d   Z RS(   s>  
    Subclass of ``RegistrationForm`` which disallows registration with
    email addresses from popular free webmail services; moderately
    useful for preventing automated spam registrations.
    
    To change the list of banned domains, subclass this form and
    override the attribute ``bad_domains``.
    
    s   aim.coms   aol.coms	   email.coms	   gmail.coms   googlemail.coms   hotmail.coms   hushmail.coms   msn.coms   mail.rus   mailinator.coms   live.comc         C   sN   |  i  d i d  d } | |  i j o t i t d    n |  i  d S(   sq   
        Check the supplied email address against a list of known free
        webmail domains.
        
        R   t   @i   u_   Registration using free email addresses is prohibited. Please supply a different email address.(   R   t   splitt   bad_domainsR   R   R   (   R   t   email_domain(    (    s3   /var/www/Pootle/external_apps/registration/forms.pyR4   }   s    (   R!   R"   R#   R8   R4   (    (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyR5   o   s
   		N(   R#   t   django.contrib.auth.modelsR    t   djangoR   t   django.utils.translationR   R   t   registration.modelsR   R&   t   FormR   R,   R1   R5   (    (    (    s3   /var/www/Pootle/external_apps/registration/forms.pyt   <module>   s   >