mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
When updating a user's password, also update the POSIX user's password, when needed.
This commit is contained in:
parent
46dd2225f7
commit
eeced1c213
34
actions/change-user-password
Executable file
34
actions/change-user-password
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Must be run as root.
|
||||||
|
|
||||||
|
username="$1"
|
||||||
|
password="$2"
|
||||||
|
|
||||||
|
getent passwd "$username"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed: user not found"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$username:$password" | chpasswd
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed: could not set user password"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
@ -16,7 +16,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
@ -39,3 +39,15 @@ class CreateUserForm(UserCreationForm):
|
|||||||
'create-user',
|
'create-user',
|
||||||
[user.username, self.cleaned_data['password1']])
|
[user.username, self.cleaned_data['password1']])
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
class UserChangePasswordForm(SetPasswordForm):
|
||||||
|
"""Custom form that also updates password for POSIX users."""
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
user = super(UserChangePasswordForm, self).save(commit)
|
||||||
|
if commit:
|
||||||
|
actions.superuser_run(
|
||||||
|
'change-user-password',
|
||||||
|
[user.username, self.cleaned_data['new_password1']])
|
||||||
|
return user
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import update_session_auth_hash
|
from django.contrib.auth import update_session_auth_hash
|
||||||
from django.contrib.auth.forms import SetPasswordForm
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.core.urlresolvers import reverse, reverse_lazy
|
from django.core.urlresolvers import reverse, reverse_lazy
|
||||||
@ -27,7 +26,7 @@ from django.views.generic.edit import (CreateView, DeleteView, UpdateView,
|
|||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from .forms import CreateUserForm
|
from .forms import CreateUserForm, UserChangePasswordForm
|
||||||
|
|
||||||
|
|
||||||
subsubmenu = [{'url': reverse_lazy('users:index'),
|
subsubmenu = [{'url': reverse_lazy('users:index'),
|
||||||
@ -112,7 +111,7 @@ class UserDelete(ContextMixin, DeleteView):
|
|||||||
class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
|
class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
|
||||||
"""View to change user password."""
|
"""View to change user password."""
|
||||||
template_name = 'users_change_password.html'
|
template_name = 'users_change_password.html'
|
||||||
form_class = SetPasswordForm
|
form_class = UserChangePasswordForm
|
||||||
title = _('Change Password')
|
title = _('Change Password')
|
||||||
success_message = _('Password changed successfully.')
|
success_message = _('Password changed successfully.')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user