private function assertKuser() { // check copied values $this->assertEquals($this->systemUser->getFirstName(), $this->kuser->getFirstName(), 'first_name for ' . $this->getParams()); $this->assertEquals($this->systemUser->getLastName(), $this->kuser->getLastName(), 'last_name for ' . $this->getParams()); $this->assertEquals($this->systemUser->getEmail(), $this->kuser->getPuserId(), 'puserid for ' . $this->getParams()); $this->assertEquals($this->adminConsolePartnerId, $this->kuser->getPartnerId(), 'partner_id for ' . $this->getParams()); $this->assertEquals($this->systemUser->getEmail(), $this->kuser->getEmail(), 'email for ' . $this->getParams()); $this->assertEquals($this->systemUser->getName(), $this->kuser->getScreenName(), 'screen_name for ' . $this->getParams()); $this->assertEquals($this->systemUser->getName(), $this->kuser->getFullName(), 'full_name for ' . $this->getParams()); if ($this->systemUser->getStatus == systemUser::SYSTEM_USER_ACTIVE) { $this->assertEquals(KuserStatus::ACTIVE, $this->kuser->getStatus(), 'status ' . $this->getParams()); } else { $this->assertEquals(KuserStatus::BLOCKED, $this->kuser->getStatus(), 'status ' . $this->getParams()); } $this->assertEquals($this->systemUser->getDeletedAt(), $this->kuser->getDeletedAt(), 'deleted_at ' . $this->getParams()); $partnerData = unserialize($this->kuser->getPartnerData()); var_dump($partnerData); $this->assertTrue(get_class($partnerData) === 'Kaltura_AdminConsoleUserPartnerData', 'PartnerData is not of type Kaltura_AdminConsoleUserPartnerData'); $this->assertEquals($this->systemUser->getIsPrimary(), $partnerData->isPrimary, 'is_primary ' . $this->getParams()); $this->assertEquals($this->systemUser->getRole(), $partnerData->role, 'role ' . $this->getParams()); // check new values $this->assertEquals(true, $this->kuser->getIsAdmin(), 'is_admin for ' . $this->getParams()); $this->assertEquals($this->kuser->getLoginDataId(), $this->loginData->getId()); }
private function assertKuser() { // check copied values $this->assertEquals($this->adminKuser->getFullName(), $this->kuser->getFullName(), 'full_name for ' . $this->getParams()); $this->assertEquals($this->adminKuser->getIcon(), $this->kuser->getIcon(), 'icon for ' . $this->getParams()); $this->assertEquals('__ADMIN__' . $this->adminKuser->getId(), $this->kuser->getPuserId(), 'puserid for ' . $this->getParams()); $this->assertEquals($this->adminKuser->getPartnerId(), $this->kuser->getPartnerId(), 'partner_id for ' . $this->getParams()); $this->assertEquals($this->adminKuser->getPicture(), $this->kuser->getPicture(), 'picture for ' . $this->getParams()); $this->assertEquals($this->adminKuser->getEmail(), $this->kuser->getEmail(), 'email for ' . $this->getParams()); $this->assertEquals($this->adminKuser->getScreenName(), $this->kuser->getScreenName(), 'screen_name for ' . $this->getParams()); // check new values $this->assertEquals(true, $this->kuser->getIsAdmin(), 'is_admin for ' . $this->getParams()); $this->assertEquals($this->kuser->getLoginDataId(), $this->loginData->getId()); }
/** * Tests UserLoginData->getPreviousPasswords() & UserLoginData->setPreviousPasswords() */ public function testGetSetPreviousPasswords() { // check clean $this->assertNull($this->UserLoginData->getPreviousPasswords()); // check basic set + get $random = ''; for ($i = 0; $i < rand(100, 1000); $i++) { $random .= uniqid(); } $this->UserLoginData->setPreviousPasswords($random); $this->assertEquals($random, $this->UserLoginData->getPreviousPasswords()); // check set + get after db save $random = ''; for ($i = 0; $i < rand(100, 1000); $i++) { $random .= uniqid(); } $this->UserLoginData->setPreviousPasswords($random); $this->UserLoginData->save(); $this->assertEquals($random, $this->UserLoginData->getPreviousPasswords()); $fromDb = UserLoginDataPeer::retrieveByPK($this->UserLoginData->getId()); $this->assertEquals($random, $fromDb->getPreviousPasswords()); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param UserLoginData $value A UserLoginData object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(UserLoginData $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('UserLoginDataPeer'); } } }
private static function userLogin(UserLoginData $loginData = null, $password, $partnerId = null, $validatePassword = true) { $requestedPartner = $partnerId; if (!$loginData) { throw new kUserException('', kUserException::LOGIN_DATA_NOT_FOUND); } // check if password is valid if ($validatePassword && !$loginData->isPasswordValid($password)) { if (time() < $loginData->getLoginBlockedUntil(null)) { throw new kUserException('', kUserException::LOGIN_BLOCKED); } if ($loginData->getLoginAttempts() + 1 >= $loginData->getMaxLoginAttempts()) { $loginData->setLoginBlockedUntil(time() + $loginData->getLoginBlockPeriod()); $loginData->setLoginAttempts(0); $loginData->save(); throw new kUserException('', kUserException::LOGIN_RETRIES_EXCEEDED); } $loginData->incLoginAttempts(); $loginData->save(); throw new kUserException('', kUserException::WRONG_PASSWORD); } if (time() < $loginData->getLoginBlockedUntil(null)) { throw new kUserException('', kUserException::LOGIN_BLOCKED); } $loginData->setLoginAttempts(0); $loginData->save(); $passUpdatedAt = $loginData->getPasswordUpdatedAt(null); if ($passUpdatedAt && time() > $passUpdatedAt + $loginData->getPassReplaceFreq()) { throw new kUserException('', kUserException::PASSWORD_EXPIRED); } if (!$partnerId) { $partnerId = $loginData->getLastLoginPartnerId(); } if (!$partnerId) { throw new kUserException('', kUserException::INVALID_PARTNER); } $partner = PartnerPeer::retrieveByPK($partnerId); $kuser = kuserPeer::getByLoginDataAndPartner($loginData->getId(), $partnerId); if (!$kuser || $kuser->getStatus() != KuserStatus::ACTIVE || !$partner || $partner->getStatus() != Partner::PARTNER_STATUS_ACTIVE) { // if a specific partner was requested - throw error if ($requestedPartner) { if ($partner && $partner->getStatus() != Partner::PARTNER_STATUS_ACTIVE) { throw new kUserException('', kUserException::USER_IS_BLOCKED); } else { if ($kuser && $kuser->getStatus() == KuserStatus::BLOCKED) { throw new kUserException('', kUserException::USER_IS_BLOCKED); } else { throw new kUserException('', kUserException::USER_NOT_FOUND); } } } // if kuser was found, keep status for following exception message $kuserStatus = $kuser ? $kuser->getStatus() : null; // if no specific partner was requested, but last logged in partner is not available, login to first found partner $kuser = null; $kuser = self::findFirstValidKuser($loginData->getId(), $partnerId); if (!$kuser) { if ($kuserStatus === KuserStatus::BLOCKED) { throw new kUserException('', kUserException::USER_IS_BLOCKED); } throw new kUserException('', kUserException::USER_NOT_FOUND); } } if ($kuser->getIsAdmin() && !in_array($kuser->getPartnerId(), kConf::get('no_save_of_last_login_partner_for_partner_ids'))) { $loginData->setLastLoginPartnerId($kuser->getPartnerId()); } $loginData->save(); $kuser->setLastLoginTime(time()); $kuser->save(); return $kuser; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param UserLoginData $value A UserLoginData object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(UserLoginData $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }