checks email for uniqueness upon change
This commit is contained in:
@@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.validators import validate_email
|
||||
from django.core.exceptions import ValidationError
|
||||
from django import forms
|
||||
from django.forms import ModelForm
|
||||
from django.dispatch import receiver
|
||||
@@ -941,15 +943,50 @@ class AccountRowerForm(ModelForm):
|
||||
'defaulttimezone','showfavoritechartnotes',
|
||||
'defaultlandingpage']
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
|
||||
try:
|
||||
validate_email(email)
|
||||
except ValidationError:
|
||||
raise forms.ValidationError(
|
||||
'Please enter a valid email address')
|
||||
|
||||
try:
|
||||
match = User.objects.get(email__iexact=email)
|
||||
if self.instance.user == match:
|
||||
return email
|
||||
except User.DoesNotExist:
|
||||
return email
|
||||
|
||||
raise forms.ValidationError('This email address is not allowed')
|
||||
|
||||
|
||||
|
||||
class UserForm(ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['first_name','last_name','email']
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(UserForm, self).clean()
|
||||
try:
|
||||
validate_email(email)
|
||||
except ValidationError:
|
||||
raise forms.ValidationError(
|
||||
'Please enter a valid email address')
|
||||
|
||||
try:
|
||||
match = User.objects.get(email__iexact=email)
|
||||
if self.instance == match:
|
||||
return email
|
||||
except User.DoesNotExist:
|
||||
return email
|
||||
|
||||
raise forms.ValidationError('This email address is not allowed')
|
||||
|
||||
|
||||
# Form to set rower's Heart Rate zones, including test routines
|
||||
# to enable consistency
|
||||
class RowerForm(ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user