Skip to content

Commit 8e05bc8

Browse files
Merge pull request #7 from mabdullahadeel/feature/signals
Added `signals` on user creation.
2 parents 570379c + 1644a07 commit 8e05bc8

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

HISTORY.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
History
33
=======
44

5-
0.1.0 (2022-02-02)
5+
0.1.2 (2022-02-26)
66
------------------
7-
8-
* First release on PyPI.
9-
10-
* Authentication with github.
11-
* Create user account with github.
12-
* Track state.
7+
* Added ``github_user_created`` signal.
138

149
0.1.1 (2022-02-04)
1510
------------------
1611

1712
* Minor updates.
1813

1914
* No explicit ``makemigrations`` required.
15+
16+
0.1.0 (2022-02-02)
17+
------------------
18+
19+
* First release on PyPI.
20+
21+
* Authentication with github.
22+
* Create user account with github.
23+
* Track state.

django_rest_github_oauth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Abdullah Adeel"""
44
__email__ = 'business.info.abd@gmail.com'
5-
__version__ = '0.1.1'
5+
__version__ = '0.1.2'

django_rest_github_oauth/register.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from django.contrib.auth.models import User
66
from rest_framework.exceptions import AuthenticationFailed
77

8+
from django_rest_github_oauth.signals import github_user_created
9+
810
from .models import GitHubAccount
911
from .response import UserResponse
1012
from .utils import id_generator
@@ -24,7 +26,7 @@ def generate_username(name: str) -> str:
2426
def get_names(user_data: dict) -> Tuple:
2527
name: str = user_data.get("name")
2628
names: list = name.split(" ")
27-
return names[0], names[1]
29+
return names[0], names[1] if len(names) > 1 else ""
2830

2931
def register_social_user(provider: str, user_data: dict) -> str:
3032
filtering_by_email = get_user_model().objects.filter(email=user_data.get("email"))
@@ -50,4 +52,5 @@ def register_social_user(provider: str, user_data: dict) -> str:
5052

5153
GitHubAccount.objects.create(user=user).save()
5254
user.save()
55+
github_user_created.send(sender=None, user=user)
5356
return UserResponse.get_user_payload(user)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.dispatch import Signal
2+
3+
github_user_created = Signal(providing_args=["user"])

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Contents:
1717

1818
Getting Started<readme>
1919
installation
20-
usage
20+
signals
2121
contributing
2222
authors
2323
history

docs/signals.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Signals
2+
========
3+
4+
5+
``django-rest-github-oauth`` provides the following signals:
6+
7+
``github_user_created``
8+
-----------------------
9+
Sent when a new GitHub user is created. The signal is sent with the
10+
newly created user instance as one of the keywords arguments.
11+
The user is instance of default User model specified in ``settings.py``.
12+
13+
.. code-block:: python
14+
15+
from django.contrib.auth.models import User
16+
from django.dispatch import receiver
17+
from rest_github_oauth.signals import github_user_created
18+
19+
@receiver(github_user_created)
20+
def my_callback(sender, **kwargs):
21+
user: User = kwargs['user']
22+
# do something with the user
23+
# ...

docs/usage.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.1
2+
current_version = 0.1.2
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
test_suite='tests',
5454
tests_require=test_requirements,
5555
url='https://github.com/mabdullahadeel/django-rest-github-oauth',
56-
version='0.1.1',
56+
version='0.1.2',
5757
zip_safe=False,
5858
)

0 commit comments

Comments
 (0)