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
fe01f925
Commit
fe01f925
authored
Feb 03, 2017
by
xiaokong1937@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user profile: update ssh pk
parent
8a5d0b2d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
32 deletions
+25
-32
.gitignore
.gitignore
+1
-0
base.html
apps/templates/base.html
+4
-3
api.py
apps/users/api.py
+9
-11
permissions.py
apps/users/permissions.py
+11
-18
user_profile.html
apps/users/templates/users/user_profile.html
+0
-0
No files found.
.gitignore
View file @
fe01f925
...
...
@@ -20,3 +20,4 @@ migrations/
*.log
host_rsa_key
*.bat
tags
apps/templates/base.html
View file @
fe01f925
...
...
@@ -24,9 +24,9 @@
{% block first_login_message %}
{% if user.is_authenticated and user.is_first_login %}
<div
class=
"alert alert-danger"
style=
"margin: 20px auto 0px"
>
{% url 'users:user-first-login' as
the
_url %}
{% url 'users:user-first-login' as
first_login
_url %}
{% blocktrans %}
Your information was incomplete. Please click
<a
href=
"{{
the
_url }}"
>
this link
</a>
to complete your information.
Your information was incomplete. Please click
<a
href=
"{{
first_login
_url }}"
>
this link
</a>
to complete your information.
{% endblocktrans %}
</div>
{% endif %}
...
...
@@ -34,8 +34,9 @@
{% block update_public_key_message %}
{% if user.is_authenticated and not user.is_public_key_valid %}
<div
class=
"alert alert-danger"
style=
"margin: 20px auto 0px"
>
{% url 'users:user-profile' as profile_url %}
{% blocktrans %}
Your ssh-public-key has been expired. Please click
<a
href=
"
#"
>
this link
</a>
to
update your ssh-public-key.
Your ssh-public-key has been expired. Please click
<a
href=
"
{{ profile_url }}"
>
this link
</a>
to
update your ssh-public-key.
{% endblocktrans %}
</div>
{% endif %}
...
...
apps/users/api.py
View file @
fe01f925
# ~*~ coding: utf-8 ~*~
#
from
rest_framework
import
generics
,
viewsets
from
rest_framework
import
generics
from
rest_framework.permissions
import
AllowAny
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework.permissions
import
AllowAny
from
rest_framework_bulk
import
BulkModelViewSet
# from django_filters.rest_framework import DjangoFilterBackend
from
.
import
serializers
from
.hands
import
write_login_log_async
from
.models
import
User
,
UserGroup
from
.permissions
import
IsSuperUser
,
IsValidUser
,
IsCurrentUserOrReadOnly
from
.utils
import
check_user_valid
,
generate_token
from
common.mixins
import
IDInFilterMixin
from
common.utils
import
get_logger
from
.utils
import
check_user_valid
,
generate_token
from
.models
import
User
,
UserGroup
from
.hands
import
write_login_log_async
from
.permissions
import
(
IsSuperUser
,
IsAppUser
,
IsValidUser
)
from
.
import
serializers
logger
=
get_logger
(
__name__
)
...
...
@@ -41,7 +38,7 @@ class UserResetPasswordApi(generics.UpdateAPIView):
def
perform_update
(
self
,
serializer
):
# Note: we are not updating the user object here.
# We just do the reset-password st
a
ff.
# We just do the reset-password st
u
ff.
import
uuid
from
.utils
import
send_reset_password_mail
user
=
self
.
get_object
()
...
...
@@ -65,6 +62,7 @@ class UserResetPKApi(generics.UpdateAPIView):
class
UserUpdatePKApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
serializers
.
UserPKUpdateSerializer
permission_classes
=
(
IsCurrentUserOrReadOnly
,)
def
perform_update
(
self
,
serializer
):
user
=
self
.
get_object
()
...
...
apps/users/permissions.py
View file @
fe01f925
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import
base64
from
django.core.cache
import
cache
from
django.conf
import
settings
from
django.utils.translation
import
ugettext
as
_
from
rest_framework
import
authentication
,
exceptions
,
permissions
from
rest_framework.compat
import
is_authenticated
from
common.utils
import
signer
,
get_object_or_none
from
.hands
import
Terminal
from
.models
import
User
from
rest_framework
import
permissions
class
IsValidUser
(
permissions
.
IsAuthenticated
,
permissions
.
BasePermission
):
...
...
@@ -20,7 +9,7 @@ class IsValidUser(permissions.IsAuthenticated, permissions.BasePermission):
def
has_permission
(
self
,
request
,
view
):
return
super
(
IsValidUser
,
self
)
.
has_permission
(
request
,
view
)
\
and
request
.
user
.
is_valid
and
request
.
user
.
is_valid
class
IsAppUser
(
IsValidUser
,
permissions
.
BasePermission
):
...
...
@@ -28,7 +17,7 @@ class IsAppUser(IsValidUser, permissions.BasePermission):
def
has_permission
(
self
,
request
,
view
):
return
super
(
IsAppUser
,
self
)
.
has_permission
(
request
,
view
)
\
and
request
.
user
.
is_app
and
request
.
user
.
is_app
class
IsSuperUser
(
IsValidUser
,
permissions
.
BasePermission
):
...
...
@@ -36,7 +25,7 @@ class IsSuperUser(IsValidUser, permissions.BasePermission):
def
has_permission
(
self
,
request
,
view
):
return
super
(
IsSuperUser
,
self
)
.
has_permission
(
request
,
view
)
\
and
request
.
user
.
is_superuser
and
request
.
user
.
is_superuser
class
IsSuperUserOrAppUser
(
IsValidUser
,
permissions
.
BasePermission
):
...
...
@@ -44,8 +33,12 @@ class IsSuperUserOrAppUser(IsValidUser, permissions.BasePermission):
def
has_permission
(
self
,
request
,
view
):
return
super
(
IsSuperUserOrAppUser
,
self
)
.
has_permission
(
request
,
view
)
\
and
(
request
.
user
.
is_superuser
or
request
.
user
.
is_app
)
and
(
request
.
user
.
is_superuser
or
request
.
user
.
is_app
)
class
IsCurrentUserOrReadOnly
(
permissions
.
BasePermission
):
if
__name__
==
'__main__'
:
pass
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
request
.
method
in
permissions
.
SAFE_METHODS
:
return
True
return
obj
==
request
.
user
apps/users/templates/users/user_profile.html
View file @
fe01f925
This diff is collapsed.
Click to expand it.
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