Question

I have a question about django-registration (https://bitbucket.org/ubernostrum/django-registration), but I can't find their issue tracker or a mailing list for it, so I'll try my luck here.

My application enables login via OpenID and login/password.

Some users "forget their password" on FS on try to reset it (here), but then they get the message:

The user account associated with this e-mail address cannot reset the password.

With no further explanations. (You can try and reset my password - just type my email (tonylampada at gmail dot com) there to see the error message.

I want to customize that message. A better message would be:

The user account associated with this e-mail address cannot reset the password. This happens because the user account was created with an OpenID or OAuth provider (tipically Google, Facebook, MyOpenID, etc). To see the login provider(s) associated with this account, take a look at the user profile.

What is the easiest way to tell django-registration that?

Thanks!

PS: This issue on Github: https://github.com/freedomsponsors/www.freedomsponsors.org/issues/191 (just in case you're feeling like making a pull request today :-))

Was it helpful?

Solution

django-registration uses views from django.contrib.auth.

In this case: reset_password() github

Since this is no class based view, you can't override/inherit from it, but you can pass in a PasswordResetForm from django.contrib.auth.forms

from django.contrib.auth.forms import PasswordResetForm

class CustomResetForm(PasswordResetForm):

       def validate(self, value):
            #pseudocode
            if user.cant_reset_pw:
               raise ValidationError("The user account associated with this e-mail address cannot reset the password. and so forth..")

            super(CustomResetForm, self).validate(value)

You'll have to wire things together by overriding the url r'^password/change/$' to point to a custom function that calls django.contrib.auth.passwort_reset() with your CustomResetForm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top