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
e08d542c
Commit
e08d542c
authored
Jun 25, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改users public_key等字段
parent
824ba433
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
37 deletions
+71
-37
base.py
apps/assets/models/base.py
+6
-6
user.py
apps/users/api/user.py
+1
-1
0021_auto_20190625_1104.py
apps/users/migrations/0021_auto_20190625_1104.py
+29
-0
0022_auto_20190625_1105.py
apps/users/migrations/0022_auto_20190625_1105.py
+28
-0
user.py
apps/users/models/user.py
+7
-30
No files found.
apps/assets/models/base.py
View file @
e08d542c
...
@@ -76,14 +76,14 @@ class AssetUser(OrgModelMixin):
...
@@ -76,14 +76,14 @@ class AssetUser(OrgModelMixin):
def
set_auth
(
self
,
password
=
None
,
private_key
=
None
,
public_key
=
None
):
def
set_auth
(
self
,
password
=
None
,
private_key
=
None
,
public_key
=
None
):
update_fields
=
[]
update_fields
=
[]
if
password
:
if
password
:
self
.
_password
=
signer
.
sign
(
password
)
self
.
password
=
password
update_fields
.
append
(
'
_
password'
)
update_fields
.
append
(
'password'
)
if
private_key
:
if
private_key
:
self
.
_private_key
=
signer
.
sign
(
private_key
)
self
.
private_key
=
private_key
update_fields
.
append
(
'
_
private_key'
)
update_fields
.
append
(
'private_key'
)
if
public_key
:
if
public_key
:
self
.
_public_key
=
signer
.
sign
(
public_key
)
self
.
public_key
=
public_key
update_fields
.
append
(
'
_
public_key'
)
update_fields
.
append
(
'public_key'
)
if
update_fields
:
if
update_fields
:
self
.
save
(
update_fields
=
update_fields
)
self
.
save
(
update_fields
=
update_fields
)
...
...
apps/users/api/user.py
View file @
e08d542c
...
@@ -54,7 +54,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
...
@@ -54,7 +54,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
self
.
send_created_signal
(
users
)
self
.
send_created_signal
(
users
)
def
get_queryset
(
self
):
def
get_queryset
(
self
):
queryset
=
current_org
.
get_org_users
()
queryset
=
current_org
.
get_org_users
()
.
prefetch_related
(
'groups'
)
return
queryset
return
queryset
def
get_permissions
(
self
):
def
get_permissions
(
self
):
...
...
apps/users/migrations/0021_auto_20190625_1104.py
0 → 100644
View file @
e08d542c
# Generated by Django 2.1.7 on 2019-06-25 03:04
import
common.fields.model
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'users'
,
'0020_auto_20190612_1825'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'user'
,
name
=
'_otp_secret_key'
,
field
=
common
.
fields
.
model
.
EncryptCharField
(
blank
=
True
,
max_length
=
128
,
null
=
True
),
),
migrations
.
AlterField
(
model_name
=
'user'
,
name
=
'_private_key'
,
field
=
common
.
fields
.
model
.
EncryptTextField
(
blank
=
True
,
max_length
=
5000
,
verbose_name
=
'Private key'
),
),
migrations
.
AlterField
(
model_name
=
'user'
,
name
=
'_public_key'
,
field
=
common
.
fields
.
model
.
EncryptTextField
(
blank
=
True
,
max_length
=
5000
,
verbose_name
=
'Public key'
),
),
]
apps/users/migrations/0022_auto_20190625_1105.py
0 → 100644
View file @
e08d542c
# Generated by Django 2.1.7 on 2019-06-25 03:05
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'users'
,
'0021_auto_20190625_1104'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'user'
,
old_name
=
'_otp_secret_key'
,
new_name
=
'otp_secret_key'
,
),
migrations
.
RenameField
(
model_name
=
'user'
,
old_name
=
'_private_key'
,
new_name
=
'private_key'
,
),
migrations
.
RenameField
(
model_name
=
'user'
,
old_name
=
'_public_key'
,
new_name
=
'public_key'
,
),
]
apps/users/models/user.py
View file @
e08d542c
...
@@ -17,6 +17,7 @@ from django.utils import timezone
...
@@ -17,6 +17,7 @@ from django.utils import timezone
from
django.shortcuts
import
reverse
from
django.shortcuts
import
reverse
from
common.utils
import
get_signer
,
date_expired_default
,
get_logger
from
common.utils
import
get_signer
,
date_expired_default
,
get_logger
from
common
import
fields
__all__
=
[
'User'
]
__all__
=
[
'User'
]
...
@@ -84,12 +85,12 @@ class User(AbstractUser):
...
@@ -84,12 +85,12 @@ class User(AbstractUser):
otp_level
=
models
.
SmallIntegerField
(
otp_level
=
models
.
SmallIntegerField
(
default
=
0
,
choices
=
OTP_LEVEL_CHOICES
,
verbose_name
=
_
(
'MFA'
)
default
=
0
,
choices
=
OTP_LEVEL_CHOICES
,
verbose_name
=
_
(
'MFA'
)
)
)
_otp_secret_key
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
null
=
True
)
otp_secret_key
=
fields
.
Encrypt
CharField
(
max_length
=
128
,
blank
=
True
,
null
=
True
)
# Todo: Auto generate key, let user download
# Todo: Auto generate key, let user download
_private_key
=
models
.
Char
Field
(
private_key
=
fields
.
EncryptText
Field
(
max_length
=
5000
,
blank
=
True
,
verbose_name
=
_
(
'Private key'
)
max_length
=
5000
,
blank
=
True
,
verbose_name
=
_
(
'Private key'
)
)
)
_public_key
=
models
.
Char
Field
(
public_key
=
fields
.
EncryptText
Field
(
max_length
=
5000
,
blank
=
True
,
verbose_name
=
_
(
'Public key'
)
max_length
=
5000
,
blank
=
True
,
verbose_name
=
_
(
'Public key'
)
)
)
comment
=
models
.
TextField
(
comment
=
models
.
TextField
(
...
@@ -141,14 +142,6 @@ class User(AbstractUser):
...
@@ -141,14 +142,6 @@ class User(AbstractUser):
def
can_update_password
(
self
):
def
can_update_password
(
self
):
return
self
.
is_local
return
self
.
is_local
@property
def
otp_secret_key
(
self
):
return
signer
.
unsign
(
self
.
_otp_secret_key
)
@otp_secret_key.setter
def
otp_secret_key
(
self
,
item
):
self
.
_otp_secret_key
=
signer
.
sign
(
item
)
def
check_otp
(
self
,
code
):
def
check_otp
(
self
,
code
):
from
..utils
import
check_otp_code
from
..utils
import
check_otp_code
return
check_otp_code
(
self
.
otp_secret_key
,
code
)
return
check_otp_code
(
self
.
otp_secret_key
,
code
)
...
@@ -161,13 +154,13 @@ class User(AbstractUser):
...
@@ -161,13 +154,13 @@ class User(AbstractUser):
Check if the user's ssh public key is valid.
Check if the user's ssh public key is valid.
This function is used in base.html.
This function is used in base.html.
"""
"""
if
self
.
_
public_key
:
if
self
.
public_key
:
return
True
return
True
return
False
return
False
@property
@property
def
groups_display
(
self
):
def
groups_display
(
self
):
return
' '
.
join
(
self
.
groups
.
all
()
.
values_list
(
'name'
,
flat
=
True
)
)
return
' '
.
join
(
[
group
.
name
for
group
in
self
.
groups
.
all
()]
)
@property
@property
def
role_display
(
self
):
def
role_display
(
self
):
...
@@ -190,22 +183,6 @@ class User(AbstractUser):
...
@@ -190,22 +183,6 @@ class User(AbstractUser):
return
True
return
True
return
False
return
False
@property
def
private_key
(
self
):
return
signer
.
unsign
(
self
.
_private_key
)
@private_key.setter
def
private_key
(
self
,
private_key_raw
):
self
.
_private_key
=
signer
.
sign
(
private_key_raw
)
@property
def
public_key
(
self
):
return
signer
.
unsign
(
self
.
_public_key
)
@public_key.setter
def
public_key
(
self
,
public_key_raw
):
self
.
_public_key
=
signer
.
sign
(
public_key_raw
)
@property
@property
def
public_key_obj
(
self
):
def
public_key_obj
(
self
):
class
PubKey
(
object
):
class
PubKey
(
object
):
...
@@ -364,7 +341,7 @@ class User(AbstractUser):
...
@@ -364,7 +341,7 @@ class User(AbstractUser):
def
generate_reset_token
(
self
):
def
generate_reset_token
(
self
):
letter
=
string
.
ascii_letters
+
string
.
digits
letter
=
string
.
ascii_letters
+
string
.
digits
token
=
''
.
join
([
random
.
choice
(
letter
)
for
_
in
range
(
50
)])
token
=
''
.
join
([
random
.
choice
(
letter
)
for
_
in
range
(
50
)])
self
.
set_cache
(
token
)
self
.
set_cache
(
token
)
return
token
return
token
...
...
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