mirror of https://github.com/jumpserver/jumpserver
修改adduser function
parent
e72aba98e6
commit
8596bc4997
|
@ -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))
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue