From f3ea867e07742c157dfc50450911b8363177a63f Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 29 Dec 2014 23:08:14 -0500 Subject: [PATCH] Add option when adding a new user, to also create a POSIX user. Conflicts: plinth/modules/users/views.py --- plinth/modules/users/forms.py | 41 +++++++++++++++++++++++++++++++++++ plinth/modules/users/views.py | 6 +++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 plinth/modules/users/forms.py diff --git a/plinth/modules/users/forms.py b/plinth/modules/users/forms.py new file mode 100644 index 000000000..6acb1ddc8 --- /dev/null +++ b/plinth/modules/users/forms.py @@ -0,0 +1,41 @@ +# +# 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 . +# + +from django import forms +from django.contrib.auth.forms import UserCreationForm +from gettext import gettext as _ + +from plinth import actions + + +class CreateUserForm(UserCreationForm): + """Custom user create form with option to also create POSIX user.""" + + add_posix_user = forms.BooleanField( + label=_('Also create POSIX user'), + required=False, + help_text=_('This will allow the new user to log in to the system ' + 'through SSH. The new user will also have administrative ' + 'privileges (sudo).')) + + def save(self, commit=True): + user = super(CreateUserForm, self).save(commit) + if commit and self.cleaned_data['add_posix_user']: + actions.superuser_run( + 'create-user', + [user.username, self.cleaned_data['password1']]) + return user diff --git a/plinth/modules/users/views.py b/plinth/modules/users/views.py index 3e6bc3127..e186162b2 100644 --- a/plinth/modules/users/views.py +++ b/plinth/modules/users/views.py @@ -18,7 +18,7 @@ from django import forms from django.contrib import messages from django.contrib.auth import update_session_auth_hash -from django.contrib.auth.forms import UserCreationForm, SetPasswordForm +from django.contrib.auth.forms import SetPasswordForm from django.contrib.auth.models import User from django.contrib.messages.views import SuccessMessageMixin from django.core.urlresolvers import reverse, reverse_lazy @@ -27,6 +27,8 @@ from django.views.generic.edit import (CreateView, DeleteView, UpdateView, from django.views.generic import ListView from gettext import gettext as _ +from .forms import CreateUserForm + subsubmenu = [{'url': reverse_lazy('users:index'), 'text': _('Users')}, @@ -46,7 +48,7 @@ class ContextMixin(object): class UserCreate(ContextMixin, SuccessMessageMixin, CreateView): """View to create a new user.""" - form_class = UserCreationForm + form_class = CreateUserForm template_name = 'users_create.html' model = User success_message = _('User %(username)s created.')