From 368b49091075a36259265ae77f3756b85e707d6a Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sun, 24 Aug 2014 23:46:17 +0300 Subject: [PATCH] edit user's password directly --- ipf/admin/app.php | 1 - ipf/admin/forms/changepassword.php | 38 ----------- ipf/admin/templates/admin/changepassword.html | 46 ------------- ipf/admin/views.php | 30 -------- ipf/auth/admin.php | 68 +++++++------------ 5 files changed, 26 insertions(+), 157 deletions(-) delete mode 100644 ipf/admin/forms/changepassword.php delete mode 100644 ipf/admin/templates/admin/changepassword.html diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 0a52074..1f31bbe 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -13,7 +13,6 @@ class IPF_Admin_App extends IPF_Application array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'), array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_EditItem'), array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i', 'func'=>'IPF_Admin_Views_DeleteItem'), - array('regex'=>'auth/user/([\w\_\-]+)/password/$#i', 'func'=>'IPF_Admin_Views_ChangePassword'), array('regex'=>'login/$#i', 'func'=>'IPF_Admin_Views_Login'), array('regex'=>'logout/$#i', 'func'=>'IPF_Admin_Views_Logout'), array('regex'=>'auth/user/(\d+)/impersonate/$#', 'func'=>'IPF_Admin_Views_Impersonate'), diff --git a/ipf/admin/forms/changepassword.php b/ipf/admin/forms/changepassword.php deleted file mode 100644 index bff9094..0000000 --- a/ipf/admin/forms/changepassword.php +++ /dev/null @@ -1,38 +0,0 @@ -fields['password1'] = new IPF_Form_Field_Varchar(array( - 'required' => true, - 'widget' =>'IPF_Form_Widget_PasswordInput', - )); - $this->fields['password2'] = new IPF_Form_Field_Varchar(array( - 'required' => true, - 'widget' => 'IPF_Form_Widget_PasswordInput', - 'help_text' => __('Enter the same password as above, for verification.'), - )); - } - - public function clean() - { - $data = parent::clean(); - - if ($data['password1'] != $data['password2']) - $this->errors['password2'][] = __('The two password fields didn\'t match.'); - - return $data; - } - - public function render() - { - return $this->renderLayout(new IPF_Admin_Form_Layout, false); - } - - public function unescape($html) - { - return new IPF_Template_SafeString($html, true); - } -} - diff --git a/ipf/admin/templates/admin/changepassword.html b/ipf/admin/templates/admin/changepassword.html deleted file mode 100644 index 8386b44..0000000 --- a/ipf/admin/templates/admin/changepassword.html +++ /dev/null @@ -1,46 +0,0 @@ -{extends "admin/base.html"} - -{block css} - {superblock} - -{/block} - -{block bodyclass}change-form{/block} - -{block breadcrumbs} - -{/block} - -{block content} -
-

{$page_title}

-
-
-
- {if $form.errors} -

Please correct the error below.

- {/if} -
- {$form->render()} -
-
- - -
-
-
-
-
-{/block} - -{block scripts} -{foreach $extra_js as $js} -{$js|safe} -{/foreach} -{/block} - diff --git a/ipf/admin/views.php b/ipf/admin/views.php index f5b725b..6ebdc8e 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -76,36 +76,6 @@ function IPF_Admin_Views_Reorder($request, $match) return new IPF_HTTP_Response_Json('Cannot find model'); } -function IPF_Admin_Views_ChangePassword($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view', 'change')); - - $user = User::table()->find($match[1]); - - if ($request->method == 'POST') { - $form = new IPF_Admin_Forms_ChangePassword($request->POST); - if ($form->isValid()) { - $user->setPassword($form->cleaned_data['password1']); - $user->save(); - return new IPF_HTTP_Response_Redirect('../'); - } - } else { - $form = new IPF_Admin_Forms_ChangePassword(); - } - - $context = array( - 'component' => $this, - 'app' => $app, - 'page_title'=>'Change Password: '.$user->username, - 'classname'=>'User', - 'object'=>$user, - 'form' => $form, - 'extra_js' => array(), - ); - - return IPF_Admin_App::RenderToResponse('admin/changepassword.html', $context, $request); -} - function IPF_Admin_Views_Login($request, $match) { $success_url = ''; diff --git a/ipf/auth/admin.php b/ipf/auth/admin.php index d03d914..c34c882 100644 --- a/ipf/auth/admin.php +++ b/ipf/auth/admin.php @@ -14,10 +14,20 @@ class IPFAuthAdminUserForm extends IPF_Form 'label' => __('Username'), 'help_text' => __('Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).'), )); - $this->fields['password'] = new IPF_Form_Field_Varchar(array( - 'required' => true, - 'max_length' => 128, + + $this->fields['password1'] = new IPF_Form_Field_Varchar(array( 'label' => __('Password'), + 'required' => $this->isAdd, + 'max_length' => 32, + 'widget' => 'IPF_Form_Widget_PasswordInput' + )); + + $this->fields['password2'] = new IPF_Form_Field_Varchar(array( + 'label' => __('Password (again)'), + 'required' => $this->isAdd, + 'max_length' => 32, + 'widget' => 'IPF_Form_Widget_PasswordInput', + 'help_text' => __('Enter the same password as above, for verification.'), )); $this->fields['email'] = new IPF_Form_Field_Email(array( @@ -30,40 +40,17 @@ class IPFAuthAdminUserForm extends IPF_Form 'label' => __('Active'), 'help_text' => __('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.'), )); + $this->fields['is_staff'] = new IPF_Form_Field_Boolean(array( 'label' => __('Staff status'), 'help_text' => __('Designates whether the user can log into this admin site.'), )); + $this->fields['is_superuser'] = new IPF_Form_Field_Boolean(array( 'label' => __('Superuser status'), 'help_text' => __('Designates that this user has all permissions without explicitly assigning them.'), )); - if ($this->isAdd) { - unset($this->fields['password']); - - $this->fields['password1'] = new IPF_Form_Field_Varchar(array( - 'label' => __('Password'), - 'required' => true, - 'max_length' => 32, - 'widget' => 'IPF_Form_Widget_PasswordInput' - )); - - $this->fields['password2'] = new IPF_Form_Field_Varchar(array( - 'label' => __('Password (again)'), - 'required' => true, - 'max_length' => 32, - 'widget' => 'IPF_Form_Widget_PasswordInput', - 'help_text' => __('Enter the same password as above, for verification.'), - )); - - $account = array('username', 'password1', 'password2', 'email'); - } else { - $this->fields['password']->help_text = __("Use '[algo]$[salt]$[hexdigest]' or use the change password form."); - - $account = array('username', 'password', 'email'); - } - $permissions = array('is_active', 'is_staff', 'is_superuser'); if (IPF_Auth_App::ArePermissionsEnabled()) { $permissions[] = 'permissions'; @@ -86,27 +73,21 @@ class IPFAuthAdminUserForm extends IPF_Form } $this->field_groups = array( - array('fields' => $account), + array('fields' => array('username', 'password1', 'password2', 'email')), array('fields' => $permissions, 'label' => __('Permissions')), ); } - function isValid() + public function clean() { - $ok = parent::isValid(); + $data = parent::clean(); - if ($ok===true && $this->isAdd) { - if ($this->cleaned_data['password1'] != $this->cleaned_data['password2']) { - $this->is_valid = false; - $this->errors['password2'][] = "The two password fields didn't match."; - - return false; - } - - $this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']); + if ($this->isAdd || $data['password1'] || $data['password2']) { + if ($data['password1'] != $data['password2']) + $this->errors['password2'][] = __('The two password fields didn\'t match.'); } - return $ok; + return $data; } } @@ -171,7 +152,6 @@ class AdminUser extends IPF_Admin_Component if ($user) { $extra['initial'] = array( 'username' => $user->username, - 'password' => $user->password, 'email' => $user->email, 'is_active' => $user->is_active, 'is_staff' => $user->is_staff, @@ -197,6 +177,10 @@ class AdminUser extends IPF_Admin_Component /* +// $this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']); + + + \PFF\Container::databaseQuery() ->deleteFrom('auth_user_permission') ->where('user_id', $user->id) -- 2.49.0