Jens Diemer schrieb:
> I would like to do something if the django user password has been set or
> update.
> So i trigger signals.post_save with the User class, like this:
> ===============================================================================
> from django.db.models import signals
> from django.dispatch import dispatcher
>
>
> def update(sender, instance, signal, *args, **kwargs):
>
> user_obj = instance
>
> ...
>
> user_obj.message_set.create(message="Updated!")
>
>
> dispatcher.connect(update, signal=signals.post_save, sender=User)
> ===============================================================================
> But my function 'update' is not only called if the user password changed.
> The problem is, in the User model exists e.g. 'last_login'. So the save
> method
> called every time, the user logged in :(
>
> Any better ideas?
I found a simple way to trigger a user password change. I hacked directly into
the django.contrib.auth.models.User.set_password() method.
It looks like this:
===============================================================================
from django.contrib.auth.models import User
# Save the original method
old_set_password = User.set_password
def set_password(user, raw_password):
if user.id == None:
# It's a new user. We must save the django user account first.
user.save()
#
# Do something with the user obejct and the given raw_password ;)
#
# Use the original method to set the django User password:
old_set_password(user, raw_password)
# Replace the method
User.set_password = set_password
===============================================================================
So every normal password change (e.g. from the django admin panel) are caught
and i can access to the raw plaintext password.
I added a snippets here: http://www.djangosnippets.org/snippets/397/
--
Mfg.
Jens Diemer
----
A django powered CMS: http://www.pylucid.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---