Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
220a4c5e
Commit
220a4c5e
authored
May 24, 2020
by
Jonathan Christopher Jakub
Browse files
[GREEN] Add lowercasing on username on obtain auth token
parent
64040ec0
Pipeline
#47732
passed with stages
in 3 minutes and 45 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/custom_auth/views.py
0 → 100644
View file @
220a4c5e
from
rest_framework.authtoken.views
import
ObtainAuthToken
from
rest_framework.authtoken.models
import
Token
from
rest_framework.response
import
Response
from
rest_framework
import
status
class
CustomAuthToken
(
ObtainAuthToken
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
request_data
=
request
.
data
request_data
[
"username"
]
=
request_data
[
"username"
].
lower
()
serializer
=
self
.
serializer_class
(
data
=
request_data
,
context
=
{
"request"
:
request
}
)
serializer
.
is_valid
(
raise_exception
=
True
)
user
=
serializer
.
validated_data
[
"user"
]
token
,
_
=
Token
.
objects
.
get_or_create
(
user
=
user
)
return
Response
(
data
=
{
"token"
:
token
.
key
},
status
=
status
.
HTTP_200_OK
)
project/urls.py
View file @
220a4c5e
from
django.contrib
import
admin
from
django.urls
import
path
,
include
from
rest_framework.authtoken.views
import
obtain_auth_token
from
apps.custom_auth.views
import
CustomAuthToken
urlpatterns
=
[
path
(
"admin/"
,
admin
.
site
.
urls
),
path
(
"accounts/"
,
include
(
"apps.accounts.urls"
)),
path
(
"cases/"
,
include
(
"apps.cases.urls"
)),
path
(
"logs/"
,
include
(
"apps.logs.urls"
)),
path
(
"auth/token/"
,
obtain_a
uth
_t
oken
,
name
=
"api_token_auth"
),
path
(
"auth/token/"
,
CustomA
uth
T
oken
.
as_view
()
,
name
=
"api_token_auth"
),
path
(
"auth/"
,
include
(
"django.contrib.auth.urls"
)),
]
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment