Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE651_Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chris Li
ECE651_Backend
Commits
fab1e0e1
Commit
fab1e0e1
authored
2 years ago
by
Chris Li
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug for is_valid setting to False, add test cases.
parent
eaf055c9
No related branches found
No related tags found
1 merge request
!1
User Authentication Feature Added
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/api/auth.py
+2
-2
2 additions, 2 deletions
core/api/auth.py
core/signals.py
+0
-2
0 additions, 2 deletions
core/signals.py
core/tests.py
+32
-2
32 additions, 2 deletions
core/tests.py
with
34 additions
and
6 deletions
core/api/auth.py
+
2
−
2
View file @
fab1e0e1
...
...
@@ -15,6 +15,8 @@ class RegisterAPI(generics.GenericAPIView):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
user
=
serializer
.
save
()
user
.
is_active
=
False
user
.
save
()
token
=
AuthToken
.
objects
.
create
(
user
)
return
Response
({
"
user
"
:
UserSerializer
(
user
,
context
=
self
.
get_serializer_context
()).
data
,
...
...
@@ -37,8 +39,6 @@ class LoginAPI(generics.GenericAPIView):
def
verify_user_and_activate
(
request
,
token
):
#print(AuthToken.objects.filter(pk=token).first())
print
(
AuthToken
.
objects
.
all
())
try
:
auth
=
AuthToken
.
objects
.
filter
(
digest
=
token
).
first
()
auth
.
user
.
is_active
=
True
...
...
This diff is collapsed.
Click to expand it.
core/signals.py
+
0
−
2
View file @
fab1e0e1
...
...
@@ -15,8 +15,6 @@ def create_related_profile(sender, instance, created, *args, **kwargs):
if
instance
and
created
:
# create profile for new user
instance
.
profile
=
Profile
.
objects
.
create
(
user
=
instance
)
# reset user's status to inactive
instance
.
is_active
=
False
@receiver
(
post_save
,
sender
=
User
)
...
...
This diff is collapsed.
Click to expand it.
core/tests.py
+
32
−
2
View file @
fab1e0e1
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
rest_framework.test
import
APIClient
from
rest_framework.test
import
APITestCase
from
rest_framework
import
status
# Create your tests here.
from
.models.profile
import
Profile
class
ProfileTestCase
(
APITestCase
):
"""
Test suite for Contact
"""
def
setUp
(
self
):
self
.
client
=
APIClient
()
self
.
data
=
{
"
username
"
:
"
xjhmlcy
"
,
"
email
"
:
"
xjhmlcy@gmail.com
"
,
"
password
"
:
"
abcdefg123
"
}
self
.
url
=
"
/api/auth/register
"
def
test_create_contact
(
self
):
'''
test ContactViewSet create method
'''
data
=
self
.
data
response
=
self
.
client
.
post
(
self
.
url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
User
.
objects
.
count
(),
1
)
self
.
assertEqual
(
Profile
.
objects
.
count
(),
1
)
self
.
assertEqual
(
User
.
objects
.
get
().
username
,
"
xjhmlcy
"
)
self
.
assertEqual
(
Profile
.
objects
.
get
().
user
.
email
,
"
xjhmlcy@gmail.com
"
)
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