Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
6d552f46
Commit
6d552f46
authored
Jan 29, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 添加链接token
parent
cc4eca25
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
+35
-2
api.py
apps/users/api.py
+32
-1
api_urls.py
apps/users/urls/api_urls.py
+1
-0
login.py
apps/users/views/login.py
+2
-1
No files found.
apps/users/api.py
View file @
6d552f46
# ~*~ coding: utf-8 ~*~
import
uuid
from
django.core.cache
import
cache
from
rest_framework
import
generics
from
rest_framework.permissions
import
AllowAny
,
IsAuthenticated
...
...
@@ -11,7 +14,8 @@ from .serializers import UserSerializer, UserGroupSerializer, \
UserUpdateGroupSerializer
,
ChangeUserPasswordSerializer
from
.tasks
import
write_login_log_async
from
.models
import
User
,
UserGroup
from
.permissions
import
IsSuperUser
,
IsValidUser
,
IsCurrentUserOrReadOnly
from
.permissions
import
IsSuperUser
,
IsValidUser
,
IsCurrentUserOrReadOnly
,
\
IsSuperUserOrAppUser
from
.utils
import
check_user_valid
,
generate_token
from
common.mixins
import
CustomFilterMixin
from
common.utils
import
get_logger
...
...
@@ -160,3 +164,30 @@ class UserAuthApi(APIView):
return
Response
({
'token'
:
token
,
'user'
:
user
.
to_json
()})
else
:
return
Response
({
'msg'
:
msg
},
status
=
401
)
class
UserConnectionTokenApi
(
APIView
):
permission_classes
=
(
IsSuperUserOrAppUser
,)
def
post
(
self
,
request
):
user_id
=
request
.
data
.
get
(
'user'
,
''
)
asset_id
=
request
.
data
.
get
(
'asset'
,
''
)
system_user_id
=
request
.
data
.
get
(
'system_user'
,
''
)
token
=
str
(
uuid
.
uuid4
())
value
=
{
'user'
:
user_id
,
'asset'
:
asset_id
,
'system_user'
:
system_user_id
}
cache
.
set
(
token
,
value
,
timeout
=
3600
)
return
Response
({
"token"
:
token
},
status
=
201
)
def
get
(
self
,
request
):
token
=
request
.
query_params
.
get
(
'token'
)
value
=
cache
.
get
(
token
,
None
)
if
value
:
cache
.
delete
(
token
)
return
Response
(
value
)
apps/users/urls/api_urls.py
View file @
6d552f46
...
...
@@ -17,6 +17,7 @@ router.register(r'v1/groups', api.UserGroupViewSet, 'user-group')
urlpatterns
=
[
# url(r'', api.UserListView.as_view()),
url
(
r'^v1/token/$'
,
api
.
UserToken
.
as_view
(),
name
=
'user-token'
),
url
(
r'^v1/connection-token/$'
,
api
.
UserConnectionTokenApi
.
as_view
(),
name
=
'connection-token'
),
url
(
r'^v1/profile/$'
,
api
.
UserProfile
.
as_view
(),
name
=
'user-profile'
),
url
(
r'^v1/auth/$'
,
api
.
UserAuthApi
.
as_view
(),
name
=
'user-auth'
),
url
(
r'^v1/users/(?P<pk>[0-9a-zA-Z\-]{36})/password/$'
,
...
...
apps/users/views/login.py
View file @
6d552f46
...
...
@@ -80,7 +80,8 @@ class UserLogoutView(TemplateView):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
auth_logout
(
request
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
response
=
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
return
response
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
Write
Preview
Markdown
is supported
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