]> git.andy128k.dev Git - ipf.git/commitdiff
edit user's password directly
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 24 Aug 2014 20:46:17 +0000 (23:46 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 24 Aug 2014 20:46:17 +0000 (23:46 +0300)
ipf/admin/app.php
ipf/admin/forms/changepassword.php [deleted file]
ipf/admin/templates/admin/changepassword.html [deleted file]
ipf/admin/views.php
ipf/auth/admin.php

index 0a52074135c66ece2ad74d10d460497ad6748e0e..1f31bbe5318be759ca250b99a87680d5bca692ec 100644 (file)
@@ -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 (file)
index bff9094..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-class IPF_Admin_Forms_ChangePassword extends IPF_Form
-{
-    function initFields($extra=array())
-    {
-        $this->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 (file)
index 8386b44..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-{extends "admin/base.html"}
-
-{block css}
-  {superblock}
-  <link rel="stylesheet" href="{$ADMIN_MEDIA_URL}css/forms.css" />
-{/block}
-
-{block bodyclass}change-form{/block}
-
-{block breadcrumbs}
-<div class="breadcrumbs">
-  <a href="{url 'IPF_Admin_Views_Index'}">{trans 'Home'}</a> &raquo;
-  <a href="{url 'IPF_Admin_Views_ListItems', array($app->slug(), $component->slug())}">{$classname}</a> &raquo;
-  <a href="{url 'IPF_Admin_Views_EditItem', array($app->slug(), $component->slug(), $object.id)}">{$object}</a> &raquo;
-  Change Password
-</div>
-{/block}
-
-{block content}
-<div id="content" class="colM">
-  <h1>{$page_title}</h1>
-  <div id="content-main">
-    <form method="post" action="">
-      <div>
-        {if $form.errors}
-          <p class="errornote">Please correct the error below.</p>
-        {/if}
-        <fieldset class="module aligned">
-          {$form->render()}
-        </fieldset>
-        <div class="submit-row">
-          <input type="submit" value="Change password" class="default" />
-          <input type="button" value="Cancel" onclick="javascript:history.back();" />
-        </div>
-      </div>
-    </form>
-  </div>
-</div>
-{/block}
-
-{block scripts}
-{foreach $extra_js as $js}
-{$js|safe}
-{/foreach}
-{/block}
-
index f5b725bc0a11f664f9693853f1cf4f02d133a64b..6ebdc8e41f2775aeae44c8c5037b73726e79e101 100644 (file)
@@ -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 = '';
index d03d9149420af9f3e8e7f9961cb3a692942054cc..c34c882decc927eda5c064755f252c8b5fbdcf40 100644 (file)
@@ -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 <a href=\"password/\">change password form</a>."); 
-
-            $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)