Ejemplo n.º 1
0
 /**
  * Perform the main actions of the page.
  * @global array Get the home page from the global configuration
  */
 protected function action()
 {
     parent::action();
     if ($this->user->logged_in()) {
         $this->setRedirect('home');
         return;
     }
     $access = I2CE::getUserAccess();
     $has_email = $access instanceof I2CE_UserAccess_Mechanism && $access->canChangePassword() && I2CE_User::hasDetail('email');
     $this->template->setBodyId("loginPage");
     $this->template->setDisplayDataImmediate('has_email', $has_email);
     if (!$this->isPost() || !$has_email) {
         return;
     }
     if ($this->post('submit') == "Reset") {
         if (I2CE_Validate::checkString($this->post('username')) && I2CE_User::userExists($this->post('username'), true)) {
             $user = new I2CE_User($this->post('username'), true, false, true);
             $email = $user->email;
             $valid_email = I2CE_Validate::checkEmail($email);
             $pass = trim(I2CE_User::generatePassword());
             if ($user->getRole() != 'guest' && $valid_email && $pass && $user->setPassword($pass)) {
                 if ($this->mailPassword($email, $this->post('username'), $pass)) {
                     $this->template->addTextNode("error_message", "Your password has been reset and mailed to you.");
                 } else {
                     $this->template->addTextNode("error_message", "Your password has been reset, but could not mailed to you. Please contact your system administrator");
                 }
             } else {
                 $this->template->addTextNode("error_message", "Your password could not be reset.  Please contact your system administrator to change your password.");
             }
         } else {
             $this->template->addTextNode("error_message", "Your username could not be found in the database.  Please contact your System Administrator.");
         }
     } elseif ($this->post('submit') == "View") {
         $usernames = I2CE_User::findUsersByInfo(false, array('email' => $this->post('email')));
         if (is_array($usernames) && count($usernames) == 1) {
             reset($usernames);
             $this->template->addText('<p id="error_message">Your username is: <b>' . current($usernames) . '</b><br />Enter it below to reset your password or return to the login page to login.</p>', 'p');
         } else {
             $this->template->addTextNode("error_message", "That email address was not found in the system.  Please contact your System Administrator.");
         }
     } else {
         $this->template->addTextNode("error_message", "Please click one of the submit buttons or only enter one text field.");
     }
 }