mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-04 08:53:42 +00:00
users: Add option to create LDAP user.
This commit is contained in:
parent
8418713741
commit
910ff97c62
31
actions/create-ldap-user
Executable file
31
actions/create-ldap-user
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
username="$1"
|
||||
password="$2"
|
||||
|
||||
service slapd stop
|
||||
cat <<EOF |slapadd
|
||||
dn: uid=$username,ou=users,dc=thisbox
|
||||
objectClass: inetOrgPerson
|
||||
uid: $username
|
||||
sn: $username
|
||||
cn: $username
|
||||
userPassword: $password
|
||||
EOF
|
||||
service slapd start
|
||||
@ -26,7 +26,10 @@ from plinth.errors import ActionError
|
||||
|
||||
|
||||
class CreateUserForm(UserCreationForm):
|
||||
"""Custom user create form with option to also create POSIX user."""
|
||||
"""Custom user create form
|
||||
|
||||
Includes options to also create POSIX and LDAP user.
|
||||
"""
|
||||
|
||||
add_posix_user = forms.BooleanField(
|
||||
label=_('Also create a POSIX system user'),
|
||||
@ -35,6 +38,12 @@ class CreateUserForm(UserCreationForm):
|
||||
'through SSH. The new user will also have administrative '
|
||||
'privileges (sudo).'))
|
||||
|
||||
add_ldap_user = forms.BooleanField(
|
||||
label=_('Also create an LDAP user'),
|
||||
required=False,
|
||||
help_text=_('This will allow the new user to log in to various '
|
||||
'services that support single sign-on through LDAP.'))
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
"""Initialize the form with extra request argument."""
|
||||
self.request = request
|
||||
@ -43,14 +52,24 @@ class CreateUserForm(UserCreationForm):
|
||||
def save(self, commit=True):
|
||||
"""Save the user model and create POSIX user if required."""
|
||||
user = super(CreateUserForm, self).save(commit)
|
||||
if commit and self.cleaned_data['add_posix_user']:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'create-user',
|
||||
[user.get_username(), self.cleaned_data['password1']])
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Creating POSIX system user failed.'))
|
||||
|
||||
if commit:
|
||||
if self.cleaned_data['add_posix_user']:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'create-user',
|
||||
[user.get_username(), self.cleaned_data['password1']])
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Creating POSIX system user failed.'))
|
||||
if self.cleaned_data['add_ldap_user']:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'create-ldap-user',
|
||||
[user.get_username(), self.cleaned_data['password1']])
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Creating LDAP user failed.'))
|
||||
|
||||
return user
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user