Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
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
5266437e
Commit
5266437e
authored
Apr 29, 2020
by
Jonathan Christopher Jakub
Browse files
[GREEN] Implement handler for existing user on account creation
parent
2089805a
Pipeline
#43984
failed with stages
in 2 minutes and 38 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/accounts/views.py
View file @
5266437e
...
...
@@ -51,13 +51,27 @@ class AccountViewSet(viewsets.ModelViewSet):
return
AccountRegisterSerializer
return
AccountSerializer
def
perform_create
(
self
,
serializer
):
def
create
(
self
,
request
):
serializer_class
=
self
.
get_serializer_class
()
serializer
=
serializer_class
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
username
=
serializer
.
validated_data
.
pop
(
"username"
).
lower
()
password
=
serializer
.
validated_data
.
pop
(
"password"
)
if
User
.
objects
.
filter
(
username
=
username
).
exists
():
return
Response
(
{
"username"
:
"User with that username already exists"
},
status
=
status
.
HTTP_409_CONFLICT
)
user
=
User
.
objects
.
create_user
(
username
=
username
,
password
=
password
)
Account
.
objects
.
create
(
user
=
user
,
**
serializer
.
validated_data
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
,
)
def
perform_destroy
(
self
,
instance
):
instance
.
delete
(
author
=
self
.
request
.
user
.
account
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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