protected function createAdminUser()
 {
     if (I2CE::getUserAccessProtocol() !== 'DEFAULT') {
         return true;
     }
     $admins = I2CE_User::findUsersByInfo('admin');
     if (is_array($admins) && count($admins) > 0) {
         I2CE::raiseError("Admin users already found");
         return true;
         // an admin  already exists.
     }
     if (I2CE_User::userExists('administrator', false)) {
         //do nothing. somebody has been messing around here.
         return true;
         //hopefully whoever allowed this to happen
     }
     $admin = new I2CE_User('administrator', false, false, false);
     $admin->email = '*****@*****.**';
     $admin->creator = 'administrator';
     $admin->firstname = 'Site';
     $admin->lastname = 'Administrator';
     $admin->username = '******';
     $admin->role = 'admin';
     I2CE::raiseError("Creating user 'administrator' with administrative privlages");
     return $admin->save('administrator');
 }
예제 #2
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.");
     }
 }
예제 #3
0
 /**
  * Populate a drop down of users that can be edited by the current user given his/her access level.
  * @param string $selectId
  * @global array
  */
 public function listUsersToEdit($selectId, $username = null)
 {
     $add_last = array();
     if ($username == null) {
         $usernames = I2CE_User::findUsersByInfo(false, array(), false);
         //we all users except the interal admin user regardless or role or details.
     } else {
         $userAccess = I2CE::getUserAccess();
         if (!$userAccess instanceof I2CE_UserAccess_Mechansim) {
             return false;
         }
         if (!in_array('creator', $userAccess->getAllowedDetails())) {
             return false;
         }
         $usernames = I2CE_User::findUsersByInfo(false, array('creator' => $username));
     }
     if (!is_array($usernames)) {
         return false;
     }
     foreach ($usernames as $username) {
         $user = new I2CE_User($username, true, false, false);
         if (!$user instanceof I2CE_User) {
             continue;
         }
         $role = $user->getRole();
         if ($role) {
             $role = I2CE_User_Form::getRoleNameFromShortName($role);
         }
         $disp = trim($user->displayName());
         if (!$disp) {
             $disp = "({$username})";
         }
         if ($role == "") {
             $add_last[$username] = 'No Access - ' . $disp;
         } else {
             $this->template->addOption($selectId, $username, $role . ' - ' . $disp);
         }
     }
     foreach ($add_last as $username => $dispname) {
         $this->template->addOption($selectId, $username, $dispname);
     }
 }