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
8596bc49
Commit
8596bc49
authored
Sep 16, 2014
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改adduser function
parent
e72aba98
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
37 deletions
+18
-37
views.py
webroot/AutoSa/AutoSa/views.py
+4
-37
forms.py
webroot/AutoSa/UserManage/forms.py
+14
-0
No files found.
webroot/AutoSa/AutoSa/views.py
View file @
8596bc49
...
...
@@ -171,43 +171,10 @@ def addUser(request):
return
render_to_response
(
'addUser.html'
,
{
'user_menu'
:
'active'
,
'form'
:
form
},
context_instance
=
RequestContext
(
request
))
else
:
username
=
request
.
POST
.
get
(
'username'
)
password
=
request
.
POST
.
get
(
'password'
)
password_confirm
=
request
.
POST
.
get
(
'password_confirm'
)
keypass
=
request
.
POST
.
get
(
'keypass'
)
keypass_confirm
=
request
.
POST
.
get
(
'keypass_confirm'
)
name
=
request
.
POST
.
get
(
'name'
)
email
=
request
.
POST
.
get
(
'email'
)
error
=
''
if
''
in
(
username
,
password
,
password_confirm
,
name
):
error
+=
'带*号内容不能为空。'
if
User
.
objects
.
filter
(
username
=
username
):
error
+=
'用户名已存在。'
if
password
!=
password_confirm
or
keypass
!=
keypass_confirm
:
error
+=
'两次输入密码不匹配。'
if
error
:
return
render_to_response
(
'addUser.html'
,
{
'error'
:
error
,
'user_menu'
:
'active'
},
context_instance
=
RequestContext
(
request
))
ldap_password
=
keygen
(
15
)
ret
=
subprocess
.
call
(
"
%
s '
%
s' '
%
s';
%
s '
%
s';
%
s '
%
s' '
%
s'"
%
(
useradd_shell
,
username
,
ldap_password
,
sudoadd_shell
,
username
,
keygen_shell
,
username
,
keypass
),
shell
=
True
)
if
not
ret
:
ret
=
subprocess
.
call
(
'echo
%
s | passwd --stdin
%
s'
%
(
password
,
username
),
shell
=
True
)
if
not
ret
:
user
=
User
(
username
=
username
,
password
=
jm
.
encrypt
(
ldap_password
),
name
=
name
,
email
=
email
)
user
.
save
()
msg
=
u'添加用户
%
s 成功。'
%
name
else
:
msg
=
u'添加用户
%
s 失败。'
%
name
else
:
msg
=
u'添加用户
%
s 失败。'
%
name
form
=
UserAddForm
(
request
.
POST
)
if
form
.
is_valid
():
user
=
form
.
cleaned_data
return
HttpResponse
(
user
)
return
render_to_response
(
'addUser.html'
,
{
'msg'
:
msg
,
'user_menu'
:
'active'
},
context_instance
=
RequestContext
(
request
))
...
...
webroot/AutoSa/UserManage/forms.py
View file @
8596bc49
...
...
@@ -28,4 +28,17 @@ class UserAddForm(forms.Form):
is_admin
=
forms
.
BooleanField
()
is_superuser
=
forms
.
BooleanField
()
def
clean_password_again
(
self
):
password
=
self
.
cleaned_data
[
'password'
]
password_again
=
self
.
cleaned_data
[
'password_again'
]
if
password
!=
password_again
:
raise
forms
.
ValidationError
(
'Password input twice not match. '
)
return
password_again
def
clean_key_pass_again
(
self
):
key_pass
=
self
.
cleaned_data
[
'key_pass'
]
key_pass_again
=
self
.
cleaned_data
[
'key_pass_again'
]
if
key_pass
!=
key_pass_again
:
raise
forms
.
ValidationError
(
'Key Password input twice not match. '
)
return
key_pass_again
\ No newline at end of file
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