Guest User

Untitled

a guest
May 29th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.  
  3.     protected function _update() {
  4.         if (isset($this->_modifiedFields['password']) &&
  5.             $this->_modifiedFields['password'] &&
  6.             strlen($this->_data['password'])
  7.         ){
  8.             $this->_data['password'] =  sha1($this->_modifiedFields['password'].$this->_data['salt']);
  9.         }
  10.     }
  11.   public function editAction() {
  12.         // action body
  13.         $this->view->title = "Edit User";
  14.         $this->view->headTitle($this->view->title, 'PREPEND');
  15.         $form = new Application_Form_Admin();
  16.         $form->submit->setLabel('Save');
  17.         $this->view->form = $form;
  18.         if ($this->getRequest()->isPost()) {
  19.             $formData = $this->getRequest()->getPost();
  20.             if ($form->isValid($formData)) {
  21.                 $id = (int) $form->getValue('id');
  22.         $data = array(
  23.                     'username' => $form->getValue('username'),
  24.                     'real_name' => $form->getValue('real_name'),
  25.                     'admin' => $form->getValue('admin')
  26.         );
  27.        
  28.         $password = $form->getValue('password');
  29.         if (!empty($password)) {
  30.             $data['password'] = $password;
  31.         }
  32.  
  33.                 $users = new Application_Model_DbTable_Users();
  34.                 $user = $users->getUser($id);
  35.                 $user->setFromArray($data);
  36.                 $user->save();
  37.                 $this->_helper->redirector('index');
  38.             } else {
  39.                 $form->populate($formData);
  40.             }
  41.         } else {
  42.             $id = $this->_getParam('id', 0);
  43.             if ($id > 0) {
  44.                 $users = new Application_Model_DbTable_Users();
  45.                 $form->populate($users->getUser($id)->toArray());
  46.             }
  47.         }
  48.     }
  49.  
  50. ?>
Add Comment
Please, Sign In to add comment