/** * * @param string $login * @param string $password * @param string $autologin_key * @return type * @throws Exception */ public static function checkUser($login, $password, $autologin_key = '') { $passwordCheck = true; $extraParams = array('is_activated' => '1', 'is_locked' => '0'); if (!empty($autologin_key)) { $extraParams['autologin_key'] = $autologin_key; $passwordCheck = false; } $userId = User::getIdByParameter('login', array($login), $extraParams); if (!is_array($userId) || count($userId) == 0) { throw new Exception("User '" . $login . "' is not enable for reaching centreon", 4404); } $user = User::get($userId[0]); if ($passwordCheck) { if (!self::checkPassword($login, $password)) { throw new Exception("User '" . $login . "' doesn't match with password", 4403); } } return $user; }
public function testGet() { $testResult = array('user_id', 'login', 'password', 'is_admin', 'is_locked', 'is_activated', 'is_password_old', 'language_id', 'timezone_id', 'contact_id', 'createdat', 'updatedat', 'firstname', 'lastname', 'auth_type', 'autologin_key'); $result = User::get(1); $this->assertEquals($testResult, $result); $testResult = array('login' => 'User 1'); $result = User::get(2, 'login'); $this->assertEquals($testResult, $result); $testResult = array('login' => 'Template user', 'user_comment' => 'Default template user'); $result = User::get(1, array('login', 'user_comment')); $this->assertEquals($testResult, $result); $this->setExpectedException('\\Centreon\\Internal\\Exception', "Object not in database.", 0); User::get(42); }