Sending a custom signal when users are registered

remotes/origin/enhancement/email-actions
Alejandro Alonso 2014-10-07 18:53:09 +02:00 committed by David Barragán Merino
parent d5800ffe3a
commit ceff57e84d
2 changed files with 26 additions and 1 deletions

View File

@ -36,7 +36,7 @@ from taiga.users.serializers import UserSerializer
from taiga.users.services import get_and_validate_user
from .backends import get_token_for_user
from .signals import user_registered as user_registered_signal
def send_public_register_email(user) -> bool:
"""
@ -126,6 +126,7 @@ def public_register(username:str, password:str, email:str, full_name:str):
raise exc.WrongArguments("User is already register.")
# send_public_register_email(user)
user_registered_signal.send(sender=user.__class__, user=user)
return user
@ -177,6 +178,7 @@ def private_register_for_new_user(token:str, username:str, email:str,
membership = get_membership_by_token(token)
membership.user = user
membership.save(update_fields=["user"])
user_registered_signal.send(sender=user.__class__, user=user)
return user
@ -202,6 +204,9 @@ def github_register(username:str, email:str, full_name:str, github_id:int, bio:s
membership.user = user
membership.save(update_fields=["user"])
if created:
user_registered_signal.send(sender=user.__class__, user=user)
return user

20
taiga/auth/signals.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.dispatch
user_registered = django.dispatch.Signal(providing_args=["user"])