Ejemplo n.º 1
0
 /**
  * authentication
  *
  * @param string $_username
  * @param string $_password
  */
 public function authenticate($_username, $_password)
 {
     $authResult = Tinebase_Auth::getInstance()->authenticate($_username, $_password);
     if ($authResult->isValid()) {
         $accountsController = Tinebase_User::getInstance();
         try {
             $account = $accountsController->getFullUserByLoginName($authResult->getIdentity());
         } catch (Tinebase_Exception_NotFound $e) {
             echo 'account ' . $authResult->getIdentity() . ' not found in account storage' . "\n";
             exit;
         }
         Tinebase_Core::set('currentAccount', $account);
         $ipAddress = '127.0.0.1';
         $account->setLoginTime($ipAddress);
         Tinebase_AccessLog::getInstance()->create(new Tinebase_Model_AccessLog(array('sessionid' => 'cli call', 'login_name' => $authResult->getIdentity(), 'ip' => $ipAddress, 'li' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'lo' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'result' => $authResult->getCode(), 'account_id' => Tinebase_Core::getUser()->getId(), 'clienttype' => 'TineCli')));
     } else {
         echo "Wrong username and/or password.\n";
         exit;
     }
 }
Ejemplo n.º 2
0
 /**
  * authenticate user by username and password
  *
  * @param  string $username the username
  * @param  string $password the password
  * @return array
  */
 public function authenticate($username, $password)
 {
     $authResult = Tinebase_Auth::getInstance()->authenticate($username, $password);
     if ($authResult->isValid()) {
         $response = array('status' => 'success', 'msg' => 'authentication succseed');
     } else {
         $response = array('status' => 'fail', 'msg' => 'authentication failed');
     }
     return $response;
 }
 /**
  * change user password
  *
  * @param string $_oldPassword
  * @param string $_newPassword
  * @throws  Tinebase_Exception_AccessDenied
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public function changePassword($_oldPassword, $_newPassword)
 {
     if (!Tinebase_Config::getInstance()->get(Tinebase_Config::PASSWORD_CHANGE, TRUE)) {
         throw new Tinebase_Exception_AccessDenied('Password change not allowed.');
     }
     $loginName = Tinebase_Core::getUser()->accountLoginName;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " change password for {$loginName}");
     }
     if (!Tinebase_Auth::getInstance()->isValidPassword($loginName, $_oldPassword)) {
         throw new Tinebase_Exception_InvalidArgument('Old password is wrong.');
     }
     Tinebase_User::getInstance()->setPassword(Tinebase_Core::getUser(), $_newPassword, true, false);
 }
 /**
  * test imap authentication
  */
 public function testImapAuth()
 {
     // use imap config for the auth config
     $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray();
     if (empty($imapConfig)) {
         $this->markTestSkipped('No IMAP config found.');
     }
     $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']);
     Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP);
     Tinebase_Auth::setBackendConfiguration($authConfig);
     Tinebase_Auth::saveBackendConfiguration();
     Tinebase_Auth::getInstance()->setBackend();
     $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend());
     $testCredentials = TestServer::getInstance()->getTestCredentials();
     // valid authentication
     $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], $testCredentials['password']);
     $this->assertTrue($authResult->isValid());
     // invalid authentication
     $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], 'some pw');
     $this->assertFalse($authResult->isValid());
     $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode());
     $this->assertEquals(array('Invalid credentials for user ' . $this->_getEmailAddress(), ''), $authResult->getMessages());
 }
Ejemplo n.º 5
0
 /**
  * send lost password mail
  *
  * @param   string $_username
  * @return  bool
  * 
  * @todo    add more texts to mail views & translate mails
  */
 public function sendLostPasswordMail($_username)
 {
     // get full user
     $fullAccount = Tinebase_User::getInstance()->getFullUserByLoginName($_username);
     // generate new password
     $newPassword = $this->generatePassword();
     // save new password in user
     Tinebase_Auth::getInstance()->setPassword($_username, $newPassword, $newPassword);
     // send lost password mail
     $mail = new Tinebase_Mail('UTF-8');
     $mail->setSubject("New password for Tine 2.0");
     // get name from user
     //$recipientName = $fullAccount->accountFirstName." ".$fullAccount->accountLastName;
     $recipientName = $fullAccount->accountFullName;
     // get email from user
     $recipientEmail = $fullAccount->accountEmailAddress;
     // get plain and html message from views
     //-- translate text and insert correct link
     $view = new Zend_View();
     $view->setScriptPath(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'views');
     $view->mailTextWelcome = "We generated a new password for you ...";
     $view->newPassword = $newPassword;
     $messagePlain = $view->render('lostpwMailPlain.php');
     $mail->setBodyText($messagePlain);
     $messageHtml = $view->render('lostpwMailHtml.php');
     if ($messageHtml !== NULL) {
         $mail->setBodyHtml($messageHtml);
     }
     $mail->addHeader('X-MailGenerator', 'Tine 2.0');
     $mail->setFrom('*****@*****.**', 'Tine 2.0 Webmaster');
     if (!empty($recipientEmail)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' send lost password email to ' . $recipientEmail);
         }
         $mail->addTo($recipientEmail, $recipientName);
         $mail->send();
         return true;
     }
     return false;
 }
 /**
  * try to reset password
  */
 public function testResetPassword()
 {
     $userArray = $this->testSaveAccount();
     $this->_json->resetPassword($userArray, 'password', false);
     $authResult = Tinebase_Auth::getInstance()->authenticate($this->objects['user']->accountLoginName, 'password');
     $this->assertTrue($authResult->isValid());
 }
Ejemplo n.º 7
0
 /**
  * change user password
  *
  * @param string $_oldPassword
  * @param string $_newPassword
  * @throws  Tinebase_Exception_AccessDenied
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public function changePassword($_oldPassword, $_newPassword)
 {
     //error_log(print_r(Tinebase_Core::getUser()->toArray(), true));
     // check config setting
     if (!Tinebase_User::getBackendConfiguration('changepw', true)) {
         throw new Tinebase_Exception_AccessDenied('Password change not allowed.');
     }
     $loginName = Tinebase_Core::getUser()->accountLoginName;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " change password for {$loginName}");
     }
     if (!Tinebase_Auth::getInstance()->isValidPassword($loginName, $_oldPassword)) {
         throw new Tinebase_Exception_InvalidArgument('Old password is wrong.');
     }
     Tinebase_User::getInstance()->setPassword(Tinebase_Core::getUser(), $_newPassword, true, false);
 }
Ejemplo n.º 8
0
 /**
  * try to reset password
  *
  */
 public function testResetPassword()
 {
     $this->_json->resetPassword($this->objects['user']->toArray(), 'password', FALSE);
     $authResult = Tinebase_Auth::getInstance()->authenticate($this->objects['user']->accountLoginName, 'password');
     $this->assertTrue($authResult->isValid());
 }
Ejemplo n.º 9
0
 /**
  * test imap authentication
  */
 public function testImapAuth()
 {
     // use imap config for the auth config
     $imapConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::IMAP);
     if (empty($imapConfig)) {
         $this->markTestSkipped('No IMAP config found.');
     }
     $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']);
     Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP);
     Tinebase_Auth::setBackendConfiguration($authConfig);
     Tinebase_Auth::saveBackendConfiguration();
     Tinebase_Auth::getInstance()->setBackend();
     $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend());
     $testConfig = Zend_Registry::get('testConfig');
     // valid authentication
     $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, $testConfig->password);
     $this->assertTrue($authResult->isValid());
     // invalid authentication
     $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, 'some pw');
     $this->assertFalse($authResult->isValid());
     $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode());
     if ($testConfig->email) {
         $this->assertEquals(array('Invalid credentials for user ' . $testConfig->email, ''), $authResult->getMessages());
     }
 }