[Backport] Throw a signal when users change their email adress
parent
0fd080b101
commit
ba76c9431f
|
@ -47,6 +47,7 @@ from . import permissions
|
|||
from . import filters as user_filters
|
||||
from . import services
|
||||
from .signals import user_cancel_account as user_cancel_account_signal
|
||||
from .signals import user_change_email as user_change_email_signal
|
||||
|
||||
|
||||
class UsersViewSet(ModelCrudViewSet):
|
||||
|
@ -273,11 +274,20 @@ class UsersViewSet(ModelCrudViewSet):
|
|||
"didn't use it before?"))
|
||||
|
||||
self.check_permissions(request, "change_email", user)
|
||||
user.email = user.new_email
|
||||
|
||||
old_email = user.email
|
||||
new_email = user.new_email
|
||||
|
||||
user.email = new_email
|
||||
user.new_email = None
|
||||
user.email_token = None
|
||||
user.save(update_fields=["email", "new_email", "email_token"])
|
||||
|
||||
user_change_email_signal.send(sender=user.__class__,
|
||||
user=user,
|
||||
old_email=old_email,
|
||||
new_email=new_email)
|
||||
|
||||
return response.NoContent()
|
||||
|
||||
@list_route(methods=["GET"])
|
||||
|
|
|
@ -19,4 +19,5 @@
|
|||
import django.dispatch
|
||||
|
||||
|
||||
user_change_email = django.dispatch.Signal(providing_args=["user", "old_email", "new_email"])
|
||||
user_cancel_account = django.dispatch.Signal(providing_args=["user", "request_data"])
|
||||
|
|
Loading…
Reference in New Issue