/**
  * @dataProvider provideValidConstruction
  */
 public function testValidConstruction($user, $pass, $domain = null)
 {
     $apiUser = new ApiUser($user, $pass, $domain);
     $this->assertEquals($user, $apiUser->getUsername());
     $this->assertEquals($pass, $apiUser->getPassword());
     $this->assertEquals($domain, $apiUser->getDomain());
 }
 /**
  * @since 0.1
  *
  * @param ApiUser $apiUser
  *
  * @throws UsageException
  * @return bool success
  */
 public function login(ApiUser $apiUser)
 {
     $this->log(LogLevel::DEBUG, 'Logging in');
     $credentials = array('lgname' => $apiUser->getUsername(), 'lgpassword' => $apiUser->getPassword());
     if (!is_null($apiUser->getDomain())) {
         $credentials['lgdomain'] = $apiUser->getDomain();
     }
     $result = $this->postRequest(new SimpleRequest('login', $credentials));
     if ($result['login']['result'] == "NeedToken") {
         $result = $this->postRequest(new SimpleRequest('login', array_merge(array('lgtoken' => $result['login']['token']), $credentials)));
     }
     if ($result['login']['result'] == "Success") {
         $this->isLoggedIn = $apiUser->getUsername();
         return true;
     }
     $this->isLoggedIn = false;
     $this->throwLoginUsageException($result);
     return false;
 }
Esempio n. 3
0
 /**
  * @param ApiUser $apiUser
  *
  * @return string[]
  */
 private function getLoginParams(ApiUser $apiUser)
 {
     $params = array('lgname' => $apiUser->getUsername(), 'lgpassword' => $apiUser->getPassword());
     if (!is_null($apiUser->getDomain())) {
         $params['lgdomain'] = $apiUser->getDomain();
     }
     return $params;
 }