-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PasswordChangeForm and EmailChangeForm (and their views) #15
Comments
I definitely missed that. What about EmailChangeForm/EmailChangeView? |
I'd definitely be interested in seeing the change email stuff. What do you mean it checks the password? |
class UpdateEmailForm(forms.Form):
email = forms.EmailField(label='New email')
password = forms.CharField(label='Confirm your password', widget=forms.PasswordInput)
def __init__(self, *args, **kwargs):
self.instance = kwargs.pop('instance', None)
assert self.instance is not None
super(UpdateEmailForm, self).__init__(*args, **kwargs)
def clean_password(self):
password = self.cleaned_data['password']
assert self.instance is not None
if not self.instance.check_password(password):
raise forms.ValidationError("Invalid password")
return password
def clean_email(self):
email = User.objects.normalize_email(self.cleaned_data['email'])
if User.objects.filter(email=email).exists():
raise forms.ValidationError("This email address is already taken")
else:
return email
def save(self, commit=True):
assert self.instance is not None
self.instance.email = self.cleaned_data['email']
if commit:
self.instance.save()
return self.instance
class UpdateEmailView(EnsureAuthMixin, UpdateView):
form_class = UpdateEmailForm
template_name = 'accounts/update_email.html'
def get_object(self):
user = self.request.user
assert not user.is_anonymous()
return user |
Is the UpdateEmail stuff applicable to any other application? I can see very different requirements here. Verifing the email address, editing the email address with the other profile fields ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just wrote my own PasswordChangeForm/PasswordChangeView in one of my project. (The form is two password fields, and ask for the current password). I also created EmailChangeForm/EmailChangeView (with newemail/password confirmation)
IMHO, it sounds like something that should go in authtools. What do you think?
FYI, It looks like this:
The text was updated successfully, but these errors were encountered: