Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
11b44dec
authored
2020-06-18 17:46:51 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
user login
1 parent
c364c248
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
src/apps/account/urls.py
src/apps/account/views.py
src/apps/account/urls.py
View file @
11b44de
...
...
@@ -3,5 +3,5 @@ from . import views
urlpatterns
=
[
#
path(r'login/', views.LoginView.as_view()),
path
(
r'login/'
,
views
.
LoginView
.
as_view
()),
]
...
...
src/apps/account/views.py
View file @
11b44de
from
django.shortcuts
import
render
from
common.mixins
import
GenericView
from
rest_framework_jwt.views
import
ObtainJSONWebToken
from
common
import
response
# Create your views here.
class
LoginView
(
ObtainJSONWebToken
,
GenericView
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
res
=
super
(
LoginView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
self
.
running_log
.
info
(
'[users.login] username:
%
s'
%
request
.
data
.
get
(
'username'
))
if
res
.
status_code
==
400
:
raise
self
.
invalid_params
(
msg
=
"用户名或密码错误"
)
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
()
user
=
serializer
.
object
.
get
(
'user'
)
user_id
=
user
.
id
data
=
{
'user_id'
:
user_id
,
'user_name'
:
user
.
username
,
'token'
:
res
.
data
.
get
(
'token'
),
}
return
response
.
ok
(
data
=
data
)
\ No newline at end of file
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment