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
935b628b
Commit
935b628b
authored
1 year ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
Add function of delete user.
parent
bc6e971a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/api/auth.py
+16
-2
16 additions, 2 deletions
core/api/auth.py
core/urls.py
+2
-1
2 additions, 1 deletion
core/urls.py
with
18 additions
and
3 deletions
core/api/auth.py
+
16
−
2
View file @
935b628b
...
...
@@ -6,8 +6,8 @@ import requests
from
django.contrib.auth.models
import
User
from
django.shortcuts
import
render
from
django.urls
import
reverse
from
rest_framework
import
generics
,
status
,
serializers
,
HTTP_HEADER_ENCODING
from
rest_framework.decorators
import
api_view
,
authentication_classes
from
rest_framework
import
generics
,
status
,
serializers
,
HTTP_HEADER_ENCODING
,
permissions
from
rest_framework.decorators
import
api_view
,
authentication_classes
,
permission_classes
from
rest_framework.response
import
Response
from
knox.auth
import
TokenAuthentication
from
knox.models
import
AuthToken
...
...
@@ -180,6 +180,20 @@ def validate_token(request):
return
Response
({
'
valid
'
:
'
false
'
})
@api_view
([
'
DELETE
'
])
@authentication_classes
([])
# @permission_classes([permissions.IsAuthenticated])
def
delete_account
(
request
):
try
:
authenticator
=
TokenAuthentication
()
user
,
auth_token
=
authenticator
.
authenticate
(
request
)
if
user
and
auth_token
:
user
.
delete
()
return
Response
({
'
msg
'
:
'
Delete successfully.
'
})
except
:
return
Response
({
'
msg
'
:
'
Failed to delete this account.
'
},
status
=
status
.
HTTP_401_UNAUTHORIZED
)
def
verify_user_and_activate
(
request
,
token
):
try
:
auth
=
AuthToken
.
objects
.
filter
(
digest
=
token
).
first
()
...
...
This diff is collapsed.
Click to expand it.
core/urls.py
+
2
−
1
View file @
935b628b
...
...
@@ -2,7 +2,7 @@ from django.urls import path, include
from
knox
import
views
as
knox_views
from
rest_framework
import
routers
from
core.api.auth
import
RegisterAPI
,
LoginAPI
,
AppleLogin
,
GoogleLogin
,
FacebookLogin
,
validate_token
,
verify_user_and_activate
from
core.api.auth
import
RegisterAPI
,
LoginAPI
,
AppleLogin
,
GoogleLogin
,
FacebookLogin
,
validate_token
,
delete_account
,
verify_user_and_activate
from
core.api.password
import
ChangePasswordView
from
core.api.profile
import
ProfileViewSet
from
core.api.coupon
import
CouponViewSet
...
...
@@ -24,6 +24,7 @@ urlpatterns += [
path
(
'
api/auth/google
'
,
GoogleLogin
.
as_view
(),
name
=
'
google_login
'
),
path
(
'
api/auth/facebook
'
,
FacebookLogin
.
as_view
(),
name
=
'
facebook_login
'
),
path
(
'
api/auth/validate-token
'
,
validate_token
,
name
=
'
validate-token
'
),
path
(
'
api/auth/delete-account
'
,
delete_account
,
name
=
'
delete-account
'
),
# passwd
path
(
'
api/change-password
'
,
ChangePasswordView
.
as_view
(),
name
=
'
change-password
'
),
path
(
'
api/password_reset/
'
,
include
(
'
django_rest_passwordreset.urls
'
,
namespace
=
'
password_reset
'
)),
...
...
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