Пример #1
0
 /**
  * Override method: Setup needs additional initialisation
  * 
  * @see tine20/Setup/Setup_Initialize#_initialize($_application)
  */
 protected function _initialize(Tinebase_Model_Application $_application, $_options = null)
 {
     parent::_initialize($_application, $_options);
     $initialAdminUserOptions = $this->_parseInitialAdminUserOptions($_options);
     if (Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) {
         Tinebase_User::syncUsers(true);
     } else {
         Tinebase_User::createInitialAccounts($initialAdminUserOptions);
     }
     // set current user
     $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
     Tinebase_Core::set(Tinebase_Core::USER, $initialUser);
     parent::_initialize($_application, $_options);
 }
 /**
  * Override method: Setup needs additional initialisation
  * 
  * @see tine20/Setup/Setup_Initialize#_initialize($_application)
  */
 protected function _initialize(Tinebase_Model_Application $_application, $_options = null)
 {
     $initialAdminUserOptions = $this->_parseInitialAdminUserOptions($_options);
     if (Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) {
         Tinebase_User::syncUsers(array('syncContactData' => TRUE));
     }
     try {
         $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Could not find initial admin account in user backend. Creating new one ...');
         }
         Tinebase_User::createInitialAccounts($initialAdminUserOptions);
         $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
     }
     Tinebase_Core::set(Tinebase_Core::USER, $initialUser);
     parent::_initialize($_application, $_options);
 }
 /**
  * create admin user / activate existing user / allow to reset password
  * 
  * @param Zend_Console_Getopt $_opts
  * 
  * @todo check role by rights and not by name
  * @todo replace echos with stdout logger
  */
 protected function _createAdminUser(Zend_Console_Getopt $_opts)
 {
     if (!Setup_Controller::getInstance()->isInstalled('Tinebase')) {
         die('Install Tinebase first.');
     }
     echo "Please enter a username. If the user already exists, he is reactivated and you can reset the password.\n";
     $username = strtolower(Tinebase_Server_Cli::promptInput('Username'));
     $tomorrow = Tinebase_DateTime::now()->addDay(1);
     try {
         $user = Tinebase_User::getInstance()->getFullUserByLoginName($username);
         echo "User {$username} already exists.\n";
         Tinebase_User::getInstance()->setStatus($user->getId(), Tinebase_Model_User::ACCOUNT_STATUS_ENABLED);
         echo "Activated admin user '{$username}'.\n";
         $expire = Tinebase_Server_Cli::promptInput('Should the admin user expire tomorrow (default: "no", "y" or "yes" for expiry)?');
         if ($expire === 'y' or $expire === 'yes') {
             Tinebase_User::getInstance()->setExpiryDate($user->getId(), $tomorrow);
             echo "User expires tomorrow at {$tomorrow}.\n";
         }
         $resetPw = Tinebase_Server_Cli::promptInput('Do you want to reset the password (default: "no", "y" or "yes" for reset)?');
         if ($resetPw === 'y' or $resetPw === 'yes') {
             $password = $this->_promptPassword();
             Tinebase_User::getInstance()->setPassword($user, $password);
             echo "User password has been reset.\n";
         }
         $this->_checkAdminGroupMembership($user);
         $this->_checkAdminRole($user);
     } catch (Tinebase_Exception_NotFound $tenf) {
         // create new admin user that expires tomorrow
         $password = $this->_promptPassword();
         Tinebase_User::createInitialAccounts(array('adminLoginName' => $username, 'adminPassword' => $password, 'expires' => $tomorrow));
         echo "Created new admin user '{$username}' that expires tomorrow.\n";
     }
 }
Пример #4
0
 /**
  * create admin user / activate existing user / allow to reset password
  * 
  * @param Zend_Console_Getopt $_opts
  */
 protected function _createAdminUser(Zend_Console_Getopt $_opts)
 {
     if (!Setup_Controller::getInstance()->isInstalled('Tinebase')) {
         die('Install Tinebase first.');
     }
     echo "Please enter a username. If the user already exists, he is reactivated and you can reset the password.\n";
     $username = Tinebase_Server_Cli::promptInput('Username');
     $tomorrow = Tinebase_DateTime::now()->addDay(1);
     try {
         $user = Tinebase_User::getInstance()->getFullUserByLoginName($username);
         echo "User {$username} already exists.\n";
         $user->accountExpires = $tomorrow;
         $user->accountStatus = Tinebase_Model_User::ACCOUNT_STATUS_ENABLED;
         Tinebase_User::getInstance()->updateUser($user);
         echo "Activated admin user '{$username}' (expires tomorrow).\n";
         $resetPw = Tinebase_Server_Cli::promptInput('Do you want to reset the password (default: "no", "y" or "yes" for reset)?');
         if ($resetPw === 'y' or $resetPw === 'yes') {
             $password = $this->_promptPassword();
             Tinebase_User::getInstance()->setPassword($user, $password);
             echo "User password has been reset.\n";
         }
         // check admin group membership
         $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
         $memberships = Tinebase_Group::getInstance()->getGroupMemberships($user);
         if (!in_array($adminGroup->getId(), $memberships)) {
             try {
                 Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
                 echo "Added user to default admin group\n";
             } catch (Zend_Ldap_Exception $zle) {
                 echo "Could not add user to default admin group: " . $zle->getMessage();
             }
         }
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_User::getConfiguredBackend() === Tinebase_User::LDAP) {
             die('It is not possible to create a new user with LDAP user backend here.');
         }
         // create new admin user that expires tomorrow
         $password = $this->_promptPassword();
         Tinebase_User::createInitialAccounts(array('adminLoginName' => $username, 'adminPassword' => $password, 'expires' => $tomorrow));
         echo "Created new admin user '{$username}' that expires tomorrow.\n";
     }
 }