/**
  * IS: -
  * FS: -
  * Desc: Fungsi untuk mereset password
  */
 private function _resetPassword($userId)
 {
     $userDb = new Model_DbTable_User();
     $updateData = array('password' => md5($this->_getParam('password')));
     $userDb->updateUser($updateData, $userId);
 }
Ejemplo n.º 2
0
 /**
  * Edit a local user.
  *
  * This does not affect the user's corresponding SoftLayer user account.
  */
 public function edituserAction()
 {
     $user = null;
     /*
      * Get user info.
      */
     try {
         $user = new Model_DbTable_User($this->_getParam('id'));
     } catch (Exception $e) {
         $this->view->errorMessage = $this->translate->_('Unable to locate user.') . ' ' . $e->getMessage();
     }
     if ($user != null) {
         /*
          * Build the delete form. Only show it if the user isn't trying to
          * delete themselves.
          */
         $deleteForm = null;
         if ($user->id != $this->view->currentUser->id) {
             $deleteForm = new Zend_Form();
             $deleteForm->setMethod('post');
             $hidden = $deleteForm->createElement('hidden', 'mode');
             $hidden->setValue('delete');
             $deleteForm->addElement($hidden);
             $deleteForm->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         }
         /*
          * Build the edit form.
          */
         $skins = Model_Skin::getAllSkins();
         $languages = Model_Language::getAllLanguages();
         /*
          * Turn the skin and language lists into something more Zend_Form
          * friendly.
          */
         foreach ($skins as $skin) {
             $skinList[$skin->name] = $skin->name;
         }
         foreach ($languages as $language) {
             $languageList[$language->name] = $language->name;
         }
         $form = new Zend_Form();
         $form->setMethod('post');
         $username = $form->createElement('text', 'username');
         $username->setLabel(ucfirst($this->view->translate->_('username')));
         $username->setRequired(true);
         $username->addValidator('alnum');
         $username->setValue($user->username);
         $apiKey = $form->createElement('text', 'apiKey');
         $apiKey->setLabel(ucfirst($this->view->translate->_('API key')));
         $apiKey->setRequired(true);
         $apiKey->addValidator('alnum');
         $apiKey->setValue($user->apiKey);
         $skin = $form->createElement('select', 'skin');
         $skin->setLabel(ucfirst($this->view->translate->_('skin')));
         $skin->addMultiOptions($skinList);
         $skin->setValue($user->skin);
         $skin->setRequired(true);
         $language = $form->createElement('select', 'language');
         $language->setLabel(ucfirst($this->view->translate->_('language')));
         $language->addMultiOptions($languageList);
         $language->setValue($user->language);
         $language->setRequired(true);
         $isAdmin = $form->createElement('checkbox', 'isAdmin');
         $isAdmin->setLabel(ucfirst($this->view->translate->_('administrator')));
         $isAdmin->setChecked($user->isAdmin);
         $hidden = $form->createElement('hidden', 'mode');
         $hidden->setValue('edit');
         $form->addElement($username);
         $form->addElement($apiKey);
         $form->addElement($skin);
         $form->addElement($language);
         $form->addElement($isAdmin);
         $form->addElement($hidden);
         $form->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         /*
          * Process form submission.
          */
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             /*
              * Delete the user.
              */
             if ($formData['mode'] == 'delete') {
                 /*
                  * Users may not delete themselves.
                  */
                 if ($user->id == $this->view->currentUser->id) {
                     $this->view->errorMessage = $this->view->translate->_('You may not delete your user account.');
                 } else {
                     try {
                         $user->deleteUser();
                         $this->_helper->_redirector->goToRouteAndExit(array('controller' => 'admin', 'action' => 'users', 'id' => null));
                     } catch (Exception $e) {
                         $this->view->errorMessage = $this->view->translate->_('Unable to delete user.') . ' ' . $e->getMessage();
                     }
                 }
                 /*
                  * Edit the user.
                  */
             } else {
                 if ($form->isValid($formData)) {
                     /*
                      * Try out the username and API key to make sure they
                      * entered a good one.
                      */
                     $account = null;
                     $client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $form->getValue('username'), $form->getValue('apiKey'));
                     try {
                         $account = $client->getObject();
                     } catch (Exception $e) {
                         $this->view->errorMessage = $this->view->translate->_('Please enter a valid username and API key combination.');
                     }
                     /*
                      * If the user is editing themself then make sure they
                      * don't take away their own admin privileges.
                      */
                     if ($user->id == $this->view->currentUser->id && $form->getValue('isAdmin') != $this->view->currentUser->isAdmin) {
                         $account = null;
                         $this->view->errorMessage = $this->view->translate->_('You may not change your administrative status.');
                     }
                     /*
                      * Update the user.
                      */
                     if ($account != null) {
                         try {
                             $user->updateUser($form->getValue('username'), $form->getValue('apiKey'), $form->getValue('skin'), $form->getValue('language'), $form->getValue('isAdmin'));
                             $this->view->statusMessage = $this->view->translate->_('User saved.');
                         } catch (Exception $e) {
                             $this->view->errorMessage = $this->view->translate->_('Unable to save user.') . ' ' . $e->getMessage();
                         }
                     }
                 } else {
                     $this->view->errorMessage = $this->view->translate->_('Please completely fill out the configuration form.');
                 }
             }
             $form->populate($formData);
         }
         $this->view->pageTitle = $this->view->translate->_('Edit') . ' ' . $user->username;
         $this->view->headTitle($this->view->translate->_('Edit') . ' ' . $user->username);
         $this->view->deleteForm = $deleteForm;
         $this->view->form = $form;
     }
     $this->view->user = $user;
 }