Ejemplo n.º 1
0
def is_valid_email(address):
    # FIXME In Django 1.2 we can use validators
    field = EmailField()
    try:
        field.clean(address)
    except ValidationError, e:
        return False
Ejemplo n.º 2
0
def validate_cc_list(cc_list):
    '''Validate each email in cc_list argument

    This is called by ``notification_*`` methods internally.

    No return value, and if any email in cc_list is not valid, ValidationError
    will be raised.
    '''

    if not isinstance(cc_list, list):
        raise TypeError('cc_list should be a list object.')

    field = EmailField(required=True)
    invalid_emails = []

    for item in cc_list:
        try:
            field.clean(item)
        except ValidationError:
            invalid_emails.append(item)

    if invalid_emails:
        raise ValidationError(
            field.error_messages['invalid'] % {
                'value': ', '.join(invalid_emails)})
Ejemplo n.º 3
0
 def clean(self):
     if 'username' in self.cleaned_data:
         username = self.cleaned_data["username"]
     else:
         raise forms.ValidationError(_("Username and Password required"))
     if 'password' in self.cleaned_data:
         password = self.cleaned_data["password"]
     else:
         raise forms.ValidationError(_("Username and Password required"))
     try:
         # User can login via email address too
         # Check whether the provided username is email
         email_check = EmailField()
         email = email_check.clean(username)
         if self.request.site.is_core:
             site_users = SiteUser.objects.filter(
                 email=email,
                 role=settings.SITE_ROLES['ADMIN'])
             site_user = site_users[0]
         else:
             site_user = SiteUser.objects.get(email=email,
                                              site_id=self.request.site.id)
         unique_username = site_user.user.username
     except SiteUser.DoesNotExist:
         # Email does not exist in the current site
         raise forms.ValidationError(_("Username or password incorrect"))
     except forms.ValidationError:
         # Not an email. Probably user is trying to login via username
         try:
             if self.request.site.is_core:
                 site_users = SiteUser.objects.filter(
                     username=username,
                     role=settings.SITE_ROLES['ADMIN'])
                 site_user = site_users[0]
             else:
                 site_user = SiteUser.objects.get(
                     username=username,
                     site_id=self.request.site.id)
             unique_username = site_user.user.username
         except SiteUser.DoesNotExist:
             #User name does not exist in current database
             raise forms.ValidationError(
                 _("Username or password incorrect"))
     user = authenticate(username=unique_username, password=password)
     if user is not None:
         if user.is_active:
             login(self.request, user)
         else:
             raise forms.ValidationError(
                 _("This account is deactivated."))
     else:
         raise forms.ValidationError(
             _("Username or password incorrect"))
Ejemplo n.º 4
0
	def post(self,request,*args,**kwargs):
		email = request.POST['email']
		ef = EmailField()
		try:
			ef.clean(email)
			Candidate.objects.get(email=email)
		except Candidate.DoesNotExist:
			url = "%s?email=%s" % (reverse('home:reg'), email)
			return HttpResponseRedirect(url)
		except ValidationError:
			messages.error(self.request, u"Email inválido")
		else:
			messages.info(self.request, u"O email %s já está cadastrado!" % email)

		return super(HomeView, self).get(request,*args,**kwargs)
Ejemplo n.º 5
0
class ContactForm(Form):
    from_email = EmailField(required=True)
    subject = CharField(max_length=50,
                        required=True,
                        help_text='50 characters max.')
    content = CharField(
        widget=Textarea(attrs={'placeholder': 'Enter your message here.'}),
        required=True)
Ejemplo n.º 6
0
class SignUpForm(UserCreationForm):
    first_name = CharField(max_length=30, required=False)
    last_name = CharField(max_length=30, required=False)
    email = EmailField(max_length=254)

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')
Ejemplo n.º 7
0
class NewsletterSubscribeForm(Form):
    email_address = EmailField(
        label='',
        error_messages={
            'required': 'Please enter your email address',
            'invalid': 'Please enter a valid email address'
        },
        widget=EmailInput(attrs={'class': 'form-control'}))
Ejemplo n.º 8
0
class SignupForm(Form):
    username = CharField()
    email = EmailField()
    password = CharField(widget=PasswordInput())

    def save(self):
        user = User.objects.create_user(**self.cleaned_data)
        return user
Ejemplo n.º 9
0
class UserSignupForm(UserMixin, UserCreationForm):
    email = EmailField(required=True)

    helper = FormHelper()
    helper.form_method = 'POST'
    helper.form_action = reverse_lazy("user:signup")
    helper.add_input(
        Submit('signup', 'Зарегистрироваться', css_class='btn-primary'))
Ejemplo n.º 10
0
 def test_emailfield_1(self):
     f = EmailField()
     self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required>')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean('')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(None)
     self.assertEqual('*****@*****.**', f.clean('*****@*****.**'))
     with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
         f.clean('foo')
     self.assertEqual(
         '[email protected]\xe4\xf6\xfc\xdfabc.part.com',
         f.clean('[email protected]äöüßabc.part.com')
     )
Ejemplo n.º 11
0
    def clean(self):
        """called in `save()`
        """
        emails = functions.split_list(self.preapproved_emails)
        email_field = EmailField()
        try:
            map(lambda v: email_field.clean(v), emails)
        except exceptions.ValidationError:
            raise exceptions.ValidationError(_("Please give a list of valid email addresses."))
        self.preapproved_emails = " " + "\n".join(emails) + " "

        domains = functions.split_list(self.preapproved_email_domains)
        domain_field = DomainNameField()
        try:
            map(lambda v: domain_field.clean(v), domains)
        except exceptions.ValidationError:
            raise exceptions.ValidationError(_("Please give a list of valid email domain names."))
        self.preapproved_email_domains = " " + "\n".join(domains) + " "
Ejemplo n.º 12
0
 def test_emailfield_not_required(self):
     f = EmailField(required=False)
     self.assertEqual('', f.clean(''))
     self.assertEqual('', f.clean(None))
     self.assertEqual('*****@*****.**', f.clean('*****@*****.**'))
     self.assertEqual('*****@*****.**', f.clean('      [email protected]  \t   \t '))
     with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
         f.clean('foo')
Ejemplo n.º 13
0
 def test_emailfield_min_max_length(self):
     f = EmailField(min_length=10, max_length=15)
     self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />')
     with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"):
         f.clean("*****@*****.**")
     self.assertEqual("*****@*****.**", f.clean("*****@*****.**"))
     with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"):
         f.clean("*****@*****.**")
Ejemplo n.º 14
0
    def clean(self):
        """called in `save()`
        """
        emails = functions.split_list(self.preapproved_emails)
        email_field = EmailField()
        try:
            map(lambda v: email_field.clean(v), emails)
        except exceptions.ValidationError:
            raise exceptions.ValidationError(
                _('Please give a list of valid email addresses.')
            )
        self.preapproved_emails = ' ' + '\n'.join(emails) + ' '

        domains = functions.split_list(self.preapproved_email_domains)
        from askbot.forms import DomainNameField
        domain_field = DomainNameField()
        try:
            map(lambda v: domain_field.clean(v), domains)
        except exceptions.ValidationError:
            raise exceptions.ValidationError(
                _('Please give a list of valid email domain names.')
            )
        self.preapproved_email_domains = ' ' + '\n'.join(domains) + ' '
Ejemplo n.º 15
0
 def test_emailfield_strip_on_none_value(self):
     f = EmailField(required=False, empty_value=None)
     self.assertIsNone(f.clean(None))
Ejemplo n.º 16
0
 def test_email_regexp_for_performance(self):
     f = EmailField()
     # Check for runaway regex security problem. This will take a long time
     # if the security fix isn't in place.
     addr = '[email protected]'
     self.assertEqual(addr, f.clean(addr))