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
dc4d388d
Commit
dc4d388d
authored
Sep 17, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge with master
parents
df281def
7984806b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
46 deletions
+70
-46
api.py
apps/users/api.py
+7
-3
forms.py
apps/users/forms.py
+19
-10
user_detail.html
apps/users/templates/users/user_detail.html
+22
-29
utils.py
apps/users/utils.py
+22
-0
views.py
apps/users/views.py
+0
-4
No files found.
apps/users/api.py
View file @
dc4d388d
...
...
@@ -6,7 +6,6 @@ import logging
from
rest_framework
import
generics
from
.serializers
import
UserSerializer
,
UserGroupSerializer
,
UserAttributeSerializer
,
UserGroupEditSerializer
from
.serializers
import
UserPKUpdateSerializer
from
.models
import
User
,
UserGroup
...
...
@@ -60,15 +59,20 @@ class UserResetPasswordApi(generics.UpdateAPIView):
# Note: we are not updating the user object here.
# We just do the reset-password staff.
user
=
self
.
get_object
()
import
uuid
user
.
password_raw
=
str
(
uuid
.
uuid4
())
user
.
save
()
from
.utils
import
send_reset_password_mail
send_reset_password_mail
(
user
)
class
UserResetPKApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
User
PKUpdate
Serializer
serializer_class
=
User
GroupEdit
Serializer
def
perform_update
(
self
,
serializer
):
user
=
self
.
get_object
()
user
.
private_key
=
serializer
.
validated_data
[
'_private_key'
]
user
.
_public_key
=
''
user
.
save
()
from
.utils
import
send_reset_ssh_key_mail
send_reset_ssh_key_mail
(
user
)
apps/users/forms.py
View file @
dc4d388d
...
...
@@ -73,15 +73,25 @@ class UserInfoForm(forms.Form):
class
UserKeyForm
(
forms
.
Form
):
private_key
=
forms
.
CharField
(
max_length
=
5000
,
widget
=
forms
.
Textarea
,
label
=
_
(
'private key'
))
def
clean_private_key
(
self
):
from
users.utils
import
validate_ssh_pk
ssh_pk
=
self
.
cleaned_data
[
'private_key'
]
checked
,
reason
=
validate_ssh_pk
(
ssh_pk
)
if
not
checked
:
raise
forms
.
ValidationError
(
_
(
'Not a valid ssh private key.'
))
return
ssh_pk
public_key
=
forms
.
CharField
(
label
=
_
(
'ssh public key'
),
max_length
=
5000
,
widget
=
forms
.
Textarea
(
attrs
=
{
'placeholder'
:
_
(
'ssh-rsa AAAA...'
)}),
help_text
=
_
(
'Paste your id_ras.pub here.'
))
def
clean_public_key
(
self
):
from
sshpubkeys
import
SSHKey
from
sshpubkeys.exceptions
import
InvalidKeyException
public_key
=
self
.
cleaned_data
[
'public_key'
]
ssh
=
SSHKey
(
public_key
)
try
:
ssh
.
parse
()
except
InvalidKeyException
as
e
:
print
e
raise
forms
.
ValidationError
(
_
(
'Not a valid ssh public key'
))
except
NotImplementedError
as
e
:
print
e
raise
forms
.
ValidationError
(
_
(
'Not a valid ssh public key'
))
return
public_key
class
UserPrivateAssetPermissionForm
(
forms
.
ModelForm
):
...
...
@@ -106,4 +116,3 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
'system_users'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select system users'
)}),
}
apps/users/templates/users/user_detail.html
View file @
dc4d388d
...
...
@@ -156,7 +156,7 @@
<td>
{% trans 'Reset ssh key' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_pk"
style=
"width: 54px;"
data-toggle=
"modal"
data-target=
"#user_reset_pk_modal"
>
{% trans 'Reset' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_pk"
style=
"width: 54px;"
>
{% trans 'Reset' %}
</button>
</span>
</td>
</tr>
...
...
@@ -207,7 +207,6 @@
</div>
</div>
</div>
{% include 'users/_user_reset_pk_modal.html' %}
{% endblock %}
{% block custom_foot_js %}
<script>
...
...
@@ -308,34 +307,28 @@ $(document).ready(function () {
doReset
();
}
);
}).
on
(
'click'
,
'#btn_user_reset_pk'
,
function
(){
var
$this
=
$
(
this
);
var
pk
=
$
(
'#txt_pk'
).
val
();
var
the_url
=
'{% url "users:user-reset-pk-api" pk=user_object.id %}'
;
var
body
=
{
'_private_key'
:
pk
};
var
success
=
function
()
{
$
(
'#txt_pk'
).
val
(
''
);
$this
.
closest
(
'.modal'
).
modal
(
'hide'
);
var
msg
=
"{% trans 'Successfully updated the SSH private key.' %}"
;
swal
(
"{% trans 'User SSH Private Key Reset' %}"
,
msg
,
"success"
);
};
var
fail
=
function
()
{
var
msg
=
"{% trans 'Failed to update the user
\
's SSH private key.' %}"
;
swal
({
title
:
"{% trans 'User SSH Private Key Reset' %}"
,
text
:
msg
,
type
:
"error"
,
showCancelButton
:
false
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
"{% trans 'Confirm' %}"
,
closeOnConfirm
:
true
},
function
()
{
$
(
'#txt_pk'
).
focus
();
}
);
}).
on
(
'click'
,
'#btn_reset_pk'
,
function
(){
function
doReset
()
{
var
the_url
=
'{% url "users:user-reset-pk-api" pk=user_object.id %}'
;
var
body
=
{};
var
success
=
function
()
{
var
msg
=
"{% trans 'The reset-ssh-public-key E-mail has been sent successfully. Please inform the user to update his new ssh public key.' %}"
;
swal
(
"{% trans 'SSH-Public-Key Reset' %}"
,
msg
,
"success"
);
}
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
});
}
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
,
error
:
fail
});
swal
({
title
:
"{% trans 'Are you sure?' %}"
,
text
:
"{% trans 'This will reset the user
\
's public key.' %}"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
"{% trans 'Confirm' %}"
,
closeOnConfirm
:
false
},
function
()
{
doReset
();
}
);
});
</script>
{% endblock %}
apps/users/utils.py
View file @
dc4d388d
...
...
@@ -128,6 +128,28 @@ def send_reset_password_mail(user):
send_mail_async
.
delay
(
subject
,
message
,
recipient_list
,
html_message
=
message
)
def
send_reset_ssh_key_mail
(
user
):
subject
=
_
(
'SSH Key Reset'
)
recipient_list
=
[
user
.
email
]
message
=
_
(
"""
Hello
%(name)
s:
</br>
Your ssh public key has been reset by site administrator.
Please login and reset your ssh public key.
</br>
<a href="
%(login_url)
s">Login direct</a>
</br>
"""
)
%
{
'name'
:
user
.
name
,
'login_url'
:
reverse
(
'users:login'
,
external
=
True
),
}
if
settings
.
DEBUG
:
logger
.
debug
(
message
)
send_mail_async
.
delay
(
subject
,
message
,
recipient_list
,
html_message
=
message
)
def
validate_ssh_pk
(
text
):
"""
Expects a SSH private key as string.
...
...
apps/users/views.py
View file @
dc4d388d
...
...
@@ -51,10 +51,6 @@ class UserLoginView(FormView):
auth_login
(
self
.
request
,
form
.
get_user
())
return
redirect
(
self
.
get_success_url
())
def
form_invalid
(
self
,
form
):
logger
.
debug
(
form
.
errors
)
return
super
(
UserLoginView
,
self
)
.
form_invalid
(
form
)
def
get_success_url
(
self
):
if
self
.
request
.
user
.
is_first_login
:
return
reverse
(
'users:user-first-login'
)
...
...
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