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
759760e7
Commit
759760e7
authored
Mar 21, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 服务器可以生成用户密钥
parent
6f29cf5d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
179 additions
and
95 deletions
+179
-95
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+104
-78
forms.py
apps/users/forms.py
+30
-4
user.py
apps/users/models/user.py
+1
-1
first_login.html
apps/users/templates/users/first_login.html
+4
-4
user_profile.html
apps/users/templates/users/user_profile.html
+18
-7
user_pubkey_update.html
apps/users/templates/users/user_pubkey_update.html
+6
-0
user_update.html
apps/users/templates/users/user_update.html
+1
-0
views_urls.py
apps/users/urls/views_urls.py
+1
-0
user.py
apps/users/views/user.py
+14
-1
No files found.
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
759760e7
No preview for this file type
apps/i18n/zh/LC_MESSAGES/django.po
View file @
759760e7
...
...
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Jumpserver 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-
14 19:07
+0800\n"
"POT-Creation-Date: 2018-03-
21 15:15
+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
...
...
@@ -29,9 +29,8 @@ msgstr ""
msgid "测试节点下资产是否可连接: {}"
msgstr ""
#: assets/forms/asset.py:23 assets/forms/asset.py:54 assets/forms/user.py:125
#: assets/models/asset.py:53 assets/models/user.py:218
#: assets/templates/assets/asset_detail.html:183
#: assets/forms/asset.py:23 assets/forms/asset.py:54 assets/models/asset.py:53
#: assets/models/user.py:218 assets/templates/assets/asset_detail.html:183
#: assets/templates/assets/asset_detail.html:191
#: assets/templates/assets/system_user_detail.html:166
msgid "Nodes"
...
...
@@ -64,7 +63,7 @@ msgid "* required Must set exact system platform, Windows, Linux ..."
msgstr "* required 必须准确设置操作系统平台,如Windows, Linux ..."
#: assets/forms/asset.py:80 assets/forms/asset.py:84 assets/forms/label.py:15
#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:2
44
#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:2
70
msgid "Select assets"
msgstr "选择资产"
...
...
@@ -162,15 +161,11 @@ msgstr "名称"
msgid "Username"
msgstr "用户名"
#: assets/forms/user.py:132
msgid "If auto push checked, system user will be create at node assets"
msgstr "如果选择了自动推送,系统用户将会创建在节点资产上"
#: assets/forms/user.py:133
#: assets/forms/user.py:126
msgid "Auto push system user to asset"
msgstr "自动推送系统用户到资产"
#: assets/forms/user.py:1
34
#: assets/forms/user.py:1
27
msgid ""
"High level will be using login asset as default, if user was granted more "
"than 2 system user"
...
...
@@ -370,10 +365,10 @@ msgstr "默认资产组"
#: terminal/templates/terminal/command_list.html:32
#: terminal/templates/terminal/command_list.html:72
#: terminal/templates/terminal/session_list.html:33
#: terminal/templates/terminal/session_list.html:71 users/forms.py:
192
#: terminal/templates/terminal/session_list.html:71 users/forms.py:
218
#: users/models/user.py:30 users/models/user.py:254
#: users/templates/users/user_group_detail.html:78
#: users/templates/users/user_group_list.html:13 users/views/user.py:33
3
#: users/templates/users/user_group_list.html:13 users/views/user.py:33
4
msgid "User"
msgstr "用户"
...
...
@@ -627,7 +622,7 @@ msgstr "激活所选"
#: users/templates/users/user_list.html:44
#: users/templates/users/user_password_update.html:59
#: users/templates/users/user_profile_update.html:64
#: users/templates/users/user_pubkey_update.html:7
1
#: users/templates/users/user_pubkey_update.html:7
7
msgid "Submit"
msgstr "提交"
...
...
@@ -647,6 +642,8 @@ msgstr "提交"
#: users/templates/users/user_group_detail.html:28
#: users/templates/users/user_group_list.html:43
#: users/templates/users/user_list.html:76
#: users/templates/users/user_profile.html:135
#: users/templates/users/user_profile.html:143
msgid "Update"
msgstr "更新"
...
...
@@ -713,10 +710,10 @@ msgstr "其它"
#: users/templates/users/_user.html:43
#: users/templates/users/user_bulk_update.html:23
#: users/templates/users/user_password_update.html:58
#: users/templates/users/user_profile.html:135
#: users/templates/users/user_profile.html:143
#: users/templates/users/user_profile.html:151
#: users/templates/users/user_profile_update.html:63
#: users/templates/users/user_pubkey_update.html:70
#: users/templates/users/user_pubkey_update.html:76
msgid "Reset"
msgstr "重置"
...
...
@@ -782,7 +779,7 @@ msgstr "替换资产的管理员"
#: users/templates/users/user_group_create_update.html:32
#: users/templates/users/user_group_list.html:86
#: users/templates/users/user_list.html:196
#: users/templates/users/user_profile.html:1
77
#: users/templates/users/user_profile.html:1
85
msgid "Confirm"
msgstr "确认"
...
...
@@ -1175,6 +1172,7 @@ msgid "User search filter"
msgstr "用户过滤器"
#: common/forms.py:121
#, python-format
msgid "Choice may be (cn|uid|sAMAccountName)=%(user)s)"
msgstr "可能的选项是(cn或uid或sAMAccountName=%(user)s)"
...
...
@@ -1613,7 +1611,7 @@ msgstr "添加"
msgid "Add asset group to this permission"
msgstr "添加资产组"
#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:2
47
#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:2
73
msgid "Select asset groups"
msgstr "选择资产组"
...
...
@@ -1642,7 +1640,7 @@ msgstr "资产组数量"
msgid "System user count"
msgstr "系统用户数量"
#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:2
50
#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:2
76
msgid "Select system users"
msgstr "选择系统用户"
...
...
@@ -1695,13 +1693,13 @@ msgstr "商业支持"
msgid "Docs"
msgstr "文档"
#: templates/_header_bar.html:37 templates/_nav_user.html:9
#: templates/_header_bar.html:37 templates/_nav_user.html:9
users/forms.py:92
#: users/templates/users/_user.html:36
#: users/templates/users/user_password_update.html:37
#: users/templates/users/user_profile.html:17
#: users/templates/users/user_profile_update.html:37
#: users/templates/users/user_profile_update.html:57
#: users/templates/users/user_pubkey_update.html:37 users/views/user.py:31
6
#: users/templates/users/user_pubkey_update.html:37 users/views/user.py:31
7
msgid "Profile"
msgstr "个人信息"
...
...
@@ -1758,13 +1756,13 @@ msgstr "关闭"
#: templates/_nav.html:10 users/views/group.py:28 users/views/group.py:44
#: users/views/group.py:62 users/views/group.py:79 users/views/group.py:95
#: users/views/login.py:209 users/views/login.py:258 users/views/user.py:
59
#: users/views/user.py:7
4 users/views/user.py:93 users/views/user.py:149
#: users/views/user.py:30
4 users/views/user.py:351 users/views/user.py:373
#: users/views/login.py:209 users/views/login.py:258 users/views/user.py:
60
#: users/views/user.py:7
5 users/views/user.py:94 users/views/user.py:150
#: users/views/user.py:30
5 users/views/user.py:352 users/views/user.py:374
msgid "Users"
msgstr "用户管理"
#: templates/_nav.html:13 users/views/user.py:6
0
#: templates/_nav.html:13 users/views/user.py:6
1
msgid "User list"
msgstr "用户列表"
...
...
@@ -2087,51 +2085,63 @@ msgstr ""
msgid "Role"
msgstr "角色"
#: users/forms.py:45 users/templates/users/user_detail.html:187
#: users/forms.py:30 users/forms.py:138
msgid "ssh public key"
msgstr "ssh公钥"
#: users/forms.py:31 users/forms.py:139
msgid "ssh-rsa AAAA..."
msgstr ""
#: users/forms.py:32
msgid "Paste user id_rsa.pub here."
msgstr "复制用户公钥到这里"
#: users/forms.py:50 users/templates/users/user_detail.html:187
msgid "Join user groups"
msgstr "添加到用户组"
#: users/forms.py:76
#: users/forms.py:58 users/forms.py:153
msgid "Public key should not be the same as your old one."
msgstr "不能和原来的密钥相同"
#: users/forms.py:62 users/forms.py:157 users/serializers.py:42
msgid "Not a valid ssh public key"
msgstr "ssh密钥不合法"
#: users/forms.py:98
msgid "Old password"
msgstr "原来密码"
#: users/forms.py:
81
#: users/forms.py:
103
msgid "New password"
msgstr "新密码"
#: users/forms.py:
86
#: users/forms.py:
108
msgid "Confirm password"
msgstr "确认密码"
#: users/forms.py:
96
#: users/forms.py:
118
msgid "Old password error"
msgstr "原来密码错误"
#: users/forms.py:1
04
#: users/forms.py:1
26
msgid "Password does not match"
msgstr "密码不一致"
#: users/forms.py:116
msgid "ssh public key"
msgstr "ssh公钥"
#: users/forms.py:117
msgid "ssh-rsa AAAA..."
msgstr ""
#: users/forms.py:118
#: users/forms.py:140
msgid "Paste your id_rsa.pub here."
msgstr "复制你的公钥到这里"
#: users/forms.py:1
31
msgid "Public key should not be the same as your old one."
msgstr "不能和原来的密钥相同"
#: users/
forms.py:135 users/serializers.py:42
msgid "
Not a valid ssh p
ublic key"
msgstr "ssh
密钥不合法
"
#: users/forms.py:1
68 users/models/user.py:46
#: users/templates/users/user_password_update.html:43
#: users/templates/users/user_profile.html:71
#: users/templates/users/user_profile_update.html:43
#: users/
templates/users/user_pubkey_update.html:43
msgid "
P
ublic key"
msgstr "ssh
公钥
"
#: users/forms.py:1
49 users/forms.py:154 users/forms.py:166 users/forms.py:196
#: users/forms.py:1
75 users/forms.py:180 users/forms.py:192 users/forms.py:222
msgid "Select users"
msgstr "选择用户"
...
...
@@ -2184,13 +2194,6 @@ msgstr "微信"
msgid "Enable OTP"
msgstr "二次验证"
#: users/models/user.py:46 users/templates/users/user_password_update.html:43
#: users/templates/users/user_profile.html:71
#: users/templates/users/user_profile_update.html:43
#: users/templates/users/user_pubkey_update.html:43
msgid "Public key"
msgstr "ssh公钥"
#: users/models/user.py:265
msgid "Administrator is the super user of system"
msgstr "Administrator是初始的超级管理员"
...
...
@@ -2241,13 +2244,13 @@ msgstr "首次登陆"
msgid "Step"
msgstr "Step"
#: users/templates/users/first_login.html:5
9
msgid "
First step
"
msgstr "
第一步
"
#: users/templates/users/first_login.html:5
7
msgid "
Previous
"
msgstr ""
#: users/templates/users/first_login.html:60
msgid "
Prev step
"
msgstr "
上一步
"
msgid "
Next
"
msgstr ""
#: users/templates/users/first_login_done.html:30
msgid "Welcome to use jumpserver, visit "
...
...
@@ -2283,8 +2286,7 @@ msgid "City"
msgstr "城市"
#: users/templates/users/reset_password.html:45
#: users/templates/users/user_detail.html:325
#: users/templates/users/user_profile.html:132 users/utils.py:71
#: users/templates/users/user_detail.html:325 users/utils.py:71
msgid "Reset password"
msgstr "重置密码"
...
...
@@ -2298,7 +2300,7 @@ msgid "Setting"
msgstr "设置"
#: users/templates/users/user_create.html:4
#: users/templates/users/user_list.html:16 users/views/user.py:7
4
#: users/templates/users/user_list.html:16 users/views/user.py:7
5
msgid "Create user"
msgstr "创建用户"
...
...
@@ -2307,7 +2309,7 @@ msgid "Reset link will be generated and sent to the user. "
msgstr "生成重置密码连接,通过邮件发送给用户"
#: users/templates/users/user_detail.html:19
#: users/templates/users/user_granted_asset.html:18 users/views/user.py:15
0
#: users/templates/users/user_granted_asset.html:18 users/views/user.py:15
1
msgid "User detail"
msgstr "用户详情"
...
...
@@ -2351,7 +2353,6 @@ msgid ""
msgstr "重设密钥邮件将会发送到用户邮箱"
#: users/templates/users/user_detail.html:350
#: users/templates/users/user_profile.html:140
msgid "Reset SSH public key"
msgstr "重置SSH密钥"
...
...
@@ -2360,14 +2361,14 @@ msgid "This will reset the user public key and send a reset mail"
msgstr "将会失效用户当前密钥,并发送重置邮件到用户邮箱"
#: users/templates/users/user_detail.html:377
#: users/templates/users/user_profile.html:1
66
#: users/templates/users/user_profile.html:1
74
msgid "Successfully updated the SSH public key."
msgstr "更新ssh密钥成功"
#: users/templates/users/user_detail.html:378
#: users/templates/users/user_detail.html:382
#: users/templates/users/user_profile.html:1
67
#: users/templates/users/user_profile.html:1
72
#: users/templates/users/user_profile.html:1
75
#: users/templates/users/user_profile.html:1
80
msgid "User SSH public key update"
msgstr "ssh密钥"
...
...
@@ -2427,12 +2428,24 @@ msgstr "用户删除失败"
msgid "OTP"
msgstr ""
#: users/templates/users/user_profile.html:100 users/views/user.py:1
79
#: users/views/user.py:23
3
#: users/templates/users/user_profile.html:100 users/views/user.py:1
80
#: users/views/user.py:23
4
msgid "User groups"
msgstr "用户组"
#: users/templates/users/user_profile.html:170
#: users/templates/users/user_profile.html:132
msgid "Update password"
msgstr "更改密码"
#: users/templates/users/user_profile.html:140
msgid "Update SSH public key"
msgstr "更改SSH密钥"
#: users/templates/users/user_profile.html:148
msgid "Reset public key and download"
msgstr "重置并下载SSH密钥"
#: users/templates/users/user_profile.html:178
msgid "Failed to update SSH public key."
msgstr "更新密钥失败"
...
...
@@ -2448,7 +2461,11 @@ msgstr "指纹"
msgid "Update public key"
msgstr "更新密钥"
#: users/templates/users/user_update.html:4 users/views/user.py:93
#: users/templates/users/user_pubkey_update.html:68
msgid "Or reset by server"
msgstr "或者重置并下载密钥"
#: users/templates/users/user_update.html:4 users/views/user.py:94
msgid "Update user"
msgstr "更新用户"
...
...
@@ -2643,30 +2660,39 @@ msgstr "首次登陆"
msgid "Login log list"
msgstr "登录日志"
#: users/views/user.py:10
3
#: users/views/user.py:10
4
msgid "Bulk update user success"
msgstr "批量更新用户成功"
#: users/views/user.py:20
8
#: users/views/user.py:20
9
msgid "Invalid file."
msgstr "文件不合法"
#: users/views/user.py:30
5
#: users/views/user.py:30
6
msgid "User granted assets"
msgstr "用户授权资产"
#: users/views/user.py:33
4
#: users/views/user.py:33
5
msgid "Profile setting"
msgstr "个人信息设置"
#: users/views/user.py:35
2
#: users/views/user.py:35
3
msgid "Password update"
msgstr "密码更新"
#: users/views/user.py:37
4
#: users/views/user.py:37
5
msgid "Public key update"
msgstr "密钥更新"
#~ msgid "If auto push checked, system user will be create at node assets"
#~ msgstr "如果选择了自动推送,系统用户将会创建在节点资产上"
#~ msgid "First step"
#~ msgstr "第一步"
#~ msgid "Prev step"
#~ msgstr "上一步"
#~ msgid "Test node assets connective: {}"
#~ msgstr "测试节点资产可连接性"
...
...
apps/users/forms.py
View file @
759760e7
...
...
@@ -26,6 +26,11 @@ class UserCreateUpdateForm(forms.ModelForm):
max_length
=
128
,
strip
=
False
,
required
=
False
,
)
role
=
forms
.
ChoiceField
(
choices
=
role_choices
,
required
=
True
,
initial
=
User
.
ROLE_USER
,
label
=
_
(
"Role"
))
public_key
=
forms
.
CharField
(
label
=
_
(
'ssh public key'
),
max_length
=
5000
,
widget
=
forms
.
Textarea
(
attrs
=
{
'placeholder'
:
_
(
'ssh-rsa AAAA...'
)}),
help_text
=
_
(
'Paste user id_rsa.pub here.'
)
)
class
Meta
:
model
=
User
...
...
@@ -47,12 +52,26 @@ class UserCreateUpdateForm(forms.ModelForm):
),
}
def
clean_public_key
(
self
):
public_key
=
self
.
cleaned_data
[
'public_key'
]
if
self
.
instance
.
public_key
and
public_key
==
self
.
instance
.
public_key
:
msg
=
_
(
'Public key should not be the same as your old one.'
)
raise
forms
.
ValidationError
(
msg
)
if
not
validate_ssh_public_key
(
public_key
):
raise
forms
.
ValidationError
(
_
(
'Not a valid ssh public key'
))
return
public_key
def
save
(
self
,
commit
=
True
):
password
=
self
.
cleaned_data
.
get
(
'password'
)
public_key
=
self
.
cleaned_data
.
get
(
'public_key'
)
user
=
super
()
.
save
(
commit
=
commit
)
if
password
:
user
.
set_password
(
password
)
user
.
save
()
if
public_key
:
user
.
public_key
=
public_key
user
.
save
()
return
user
...
...
@@ -70,6 +89,9 @@ class UserProfileForm(forms.ModelForm):
}
UserProfileForm
.
verbose_name
=
_
(
"Profile"
)
class
UserPasswordForm
(
forms
.
Form
):
old_password
=
forms
.
CharField
(
max_length
=
128
,
widget
=
forms
.
PasswordInput
,
...
...
@@ -113,7 +135,7 @@ class UserPasswordForm(forms.Form):
class
UserPublicKeyForm
(
forms
.
Form
):
public_key
=
forms
.
CharField
(
label
=
_
(
'ssh public key'
),
max_length
=
5000
,
label
=
_
(
'ssh public key'
),
max_length
=
5000
,
required
=
False
,
widget
=
forms
.
Textarea
(
attrs
=
{
'placeholder'
:
_
(
'ssh-rsa AAAA...'
)}),
help_text
=
_
(
'Paste your id_rsa.pub here.'
)
)
...
...
@@ -131,17 +153,21 @@ class UserPublicKeyForm(forms.Form):
msg
=
_
(
'Public key should not be the same as your old one.'
)
raise
forms
.
ValidationError
(
msg
)
if
not
validate_ssh_public_key
(
public_key
):
if
public_key
and
not
validate_ssh_public_key
(
public_key
):
raise
forms
.
ValidationError
(
_
(
'Not a valid ssh public key'
))
return
public_key
def
save
(
self
):
public_key
=
self
.
cleaned_data
[
'public_key'
]
self
.
instance
.
public_key
=
public_key
self
.
instance
.
save
()
if
public_key
:
self
.
instance
.
public_key
=
public_key
self
.
instance
.
save
()
return
self
.
instance
UserPublicKeyForm
.
verbose_name
=
_
(
"Public key"
)
class
UserBulkUpdateForm
(
forms
.
ModelForm
):
users
=
forms
.
ModelMultipleChoiceField
(
required
=
True
,
...
...
apps/users/models/user.py
View file @
759760e7
...
...
@@ -115,7 +115,7 @@ class User(AbstractUser):
import
sshpubkeys
try
:
return
sshpubkeys
.
SSHKey
(
self
.
public_key
)
except
TabError
:
except
(
TabError
,
TypeError
)
:
pass
return
PubKey
()
...
...
apps/users/templates/users/first_login.html
View file @
759760e7
...
...
@@ -45,10 +45,8 @@
{{ wizard.form.management_form }}
{% for form in wizard.form.forms %}
{% bootstrap_form form %}
{# {{ form|bootstrap }}#}
{% endfor %}
{% else %}
{# {{ wizard.form|bootstrap }}#}
{% bootstrap_form wizard.form %}
{% endif %}
</form>
...
...
@@ -56,8 +54,10 @@
<div
class=
"actions clearfix"
>
<ul>
{% if wizard.steps.prev %}
<li><a
class=
"fl_goto"
data-goto=
"{{ wizard.steps.first }}"
>
{% trans "First step" %}
</a></li>
<li><a
class=
"fl_goto"
name=
"wizard_goto_step"
data-goto=
"{{ wizard.steps.prev }}"
>
{% trans "Prev step" %}
</a></li>
<li><a
class=
"fl_goto"
name=
"wizard_goto_step"
data-goto=
"{{ wizard.steps.prev }}"
>
{% trans "Previous" %}
</a></li>
{% endif %}
{% if wizard.steps.next %}
<li><a
class=
"fl_goto"
name=
"wizard_goto_step"
data-goto=
"{{ wizard.steps.next }}"
>
{% trans "Next" %}
</a></li>
{% endif %}
<li><a
id=
"fl_submit"
>
{% trans "Submit" %}
</a></li>
</ul>
...
...
apps/users/templates/users/user_profile.html
View file @
759760e7
...
...
@@ -22,7 +22,7 @@
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-
7
"
style=
"padding-left: 0;"
>
<div
class=
"col-sm-
8
"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label label-primary"
><b>
{{ user.name }}
</b></span>
...
...
@@ -120,7 +120,7 @@
</div>
</div>
</div>
<div
class=
"col-sm-
5
"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"col-sm-
4
"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick modify' %}
...
...
@@ -129,18 +129,26 @@
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td>
{% trans '
Reset
password' %}:
</td>
<td>
{% trans '
Update
password' %}:
</td>
<td>
<span
class=
"pull-right"
>
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
href=
"{% url 'users:user-password-update' %}"
>
{% trans '
Reset
' %}
</a>
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
href=
"{% url 'users:user-password-update' %}"
>
{% trans '
Update
' %}
</a>
</span>
</td>
</tr>
<tr>
<td>
{% trans '
Reset
SSH public key' %}:
</td>
<td>
{% trans '
Update
SSH public key' %}:
</td>
<td>
<span
class=
"pull-right"
>
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
href=
"{% url 'users:user-pubkey-update' %}"
>
{% trans 'Reset' %}
</a>
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
href=
"{% url 'users:user-pubkey-update' %}"
>
{% trans 'Update' %}
</a>
</span>
</td>
</tr>
<tr>
<td>
{% trans 'Reset public key and download' %}:
</td>
<td>
<span
class=
"pull-right"
>
<a
type=
"button"
class=
"btn btn-primary btn-xs btn-reset-pubkey"
style=
"width: 54px"
>
{% trans 'Reset' %}
</a>
</span>
</td>
</tr>
...
...
@@ -180,8 +188,11 @@ $(document).on('click', '#btn_update_pk', function() {
$
(
'#txt_pk'
).
focus
();
}
);
}
}
;
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
,
error
:
fail
});
}).
on
(
'click'
,
'.btn-reset-pubkey'
,
function
()
{
var
the_url
=
'{% url "users:user-pubkey-generate" %}'
;
window
.
open
(
the_url
,
"_blank"
)
})
</script>
{% endblock %}
apps/users/templates/users/user_pubkey_update.html
View file @
759760e7
...
...
@@ -64,6 +64,12 @@
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Update public key' %}
</h3>
{% bootstrap_field form.public_key layout="horizontal" %}
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-2 col-lg-2"
style=
"padding-top: 0"
>
{% trans 'Or reset by server' %}
</label>
<div
class=
" col-sm-9 col-lg-9 "
>
<a
href=
"{% url 'users:user-pubkey-generate' %}"
>
{% trans 'Reset' %}
</a>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
...
...
apps/users/templates/users/user_update.html
View file @
759760e7
...
...
@@ -5,4 +5,5 @@
{% block password %}
<h3>
{% trans 'Auth' %}
</h3>
{% bootstrap_field form.password layout="horizontal" %}
{% bootstrap_field form.public_key layout="horizontal" %}
{% endblock %}
apps/users/urls/views_urls.py
View file @
759760e7
...
...
@@ -20,6 +20,7 @@ urlpatterns = [
url
(
r'^profile/update/$'
,
views
.
UserProfileUpdateView
.
as_view
(),
name
=
'user-profile-update'
),
url
(
r'^profile/password/update/$'
,
views
.
UserPasswordUpdateView
.
as_view
(),
name
=
'user-password-update'
),
url
(
r'^profile/pubkey/update/$'
,
views
.
UserPublicKeyUpdateView
.
as_view
(),
name
=
'user-pubkey-update'
),
url
(
r'^profile/pubkey/generate/$'
,
views
.
UserPublicKeyGenerateView
.
as_view
(),
name
=
'user-pubkey-generate'
),
# User view
url
(
r'^user$'
,
views
.
UserListView
.
as_view
(),
name
=
'user-list'
),
...
...
apps/users/views/user.py
View file @
759760e7
...
...
@@ -31,7 +31,7 @@ from django.contrib.auth import logout as auth_logout
from
common.const
import
create_success_msg
,
update_success_msg
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_logger
,
get_object_or_none
,
is_uuid
from
common.utils
import
get_logger
,
get_object_or_none
,
is_uuid
,
ssh_key_gen
from
..
import
forms
from
..models
import
User
,
UserGroup
from
..utils
import
AdminUserRequiredMixin
...
...
@@ -45,6 +45,7 @@ __all__ = [
'UserExportView'
,
'UserBulkImportView'
,
'UserProfileView'
,
'UserProfileUpdateView'
,
'UserPasswordUpdateView'
,
'UserPublicKeyUpdateView'
,
'UserBulkUpdateView'
,
'UserPublicKeyGenerateView'
,
]
logger
=
get_logger
(
__name__
)
...
...
@@ -375,3 +376,15 @@ class UserPublicKeyUpdateView(LoginRequiredMixin, UpdateView):
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
UserPublicKeyGenerateView
(
LoginRequiredMixin
,
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
private
,
public
=
ssh_key_gen
(
username
=
request
.
user
.
username
,
hostname
=
'jumpserver'
)
request
.
user
.
public_key
=
public
request
.
user
.
save
()
response
=
HttpResponse
(
private
,
content_type
=
'text/plain'
)
filename
=
"{0}-jumpserver.pem"
.
format
(
request
.
user
.
username
)
response
[
'Content-Disposition'
]
=
'attachment; filename={}'
.
format
(
filename
)
return
response
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