Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
3498f237
Commit
3498f237
authored
6 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Create token on user creation
parent
5355d6d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
arkindex/users/__init__.py
+1
-0
1 addition, 0 deletions
arkindex/users/__init__.py
arkindex/users/apps.py
+4
-1
4 additions, 1 deletion
arkindex/users/apps.py
arkindex/users/signals.py
+10
-0
10 additions, 0 deletions
arkindex/users/signals.py
arkindex/users/tests.py
+7
-0
7 additions, 0 deletions
arkindex/users/tests.py
with
22 additions
and
1 deletion
arkindex/users/__init__.py
+
1
−
0
View file @
3498f237
default_app_config
=
'
arkindex.users.apps.UsersConfig
'
This diff is collapsed.
Click to expand it.
arkindex/users/apps.py
+
4
−
1
View file @
3498f237
...
...
@@ -2,4 +2,7 @@ from django.apps import AppConfig
class
UsersConfig
(
AppConfig
):
name
=
'
users
'
name
=
'
arkindex.users
'
def
ready
(
self
):
from
arkindex.users
import
signals
# noqa
This diff is collapsed.
Click to expand it.
arkindex/users/signals.py
0 → 100644
+
10
−
0
View file @
3498f237
from
django.conf
import
settings
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
rest_framework.authtoken.models
import
Token
@receiver
(
post_save
,
sender
=
settings
.
AUTH_USER_MODEL
)
def
create_auth_token
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
:
Token
.
objects
.
create
(
user
=
instance
)
This diff is collapsed.
Click to expand it.
arkindex/users/tests.py
+
7
−
0
View file @
3498f237
...
...
@@ -3,6 +3,7 @@ from django.urls import reverse
from
django.core
import
mail
from
django.contrib
import
auth
from
arkindex.users.models
import
User
from
rest_framework.authtoken.models
import
Token
class
TestUsers
(
TestCase
):
...
...
@@ -41,3 +42,9 @@ class TestUsers(TestCase):
self
.
assertListEqual
(
response
.
redirect_chain
,
[(
reverse
(
'
password_reset_done
'
),
302
)])
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
self
.
assertEqual
(
mail
.
outbox
[
0
].
to
,
[
'
email@address.com
'
])
def
test_auto_token
(
self
):
"""
Check creating a user automatically creates a token
"""
self
.
assertEqual
(
Token
.
objects
.
filter
(
user
=
self
.
user
).
count
(),
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment