public function execute() { // Prevent the page fron being embeded in an iframe header('X-Frame-Options: DENY'); $service_url = requestUtils::getHost(); $service_url = str_replace("http://", "", $service_url); if (kConf::get('kmc_secured_login')) { $service_url = 'https://' . $service_url; if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && $_SERVER['SERVER_PORT'] != 443) { header('Location:' . $service_url . '/' . $_SERVER['REQUEST_URI']); die; } } else { $service_url = 'http://' . $service_url; header('Location:' . $service_url . '/' . $_SERVER['REQUEST_URI']); die; } $this->service_url = $service_url; $this->kmc_login_version = kConf::get('kmc_login_version'); $this->setPassHashKey = $this->getRequestParameter("setpasshashkey"); $this->hashKeyErrorCode = null; $this->hashKeyLoginId = null; if ($this->setPassHashKey) { try { if (!UserLoginDataPeer::isHashKeyValid($this->setPassHashKey)) { $this->hashKeyErrorCode = kUserException::NEW_PASSWORD_HASH_KEY_INVALID; } else { $userLoginDataId = UserLoginDataPeer::getIdFromHashKey($this->setPassHashKey); $userLoginData = UserLoginDataPeer::retrieveByPK($userLoginDataId); if (!$userLoginData) { $this->hashKeyLoginId = ""; } $this->hashKeyLoginId = $userLoginData->getLoginEmail(); } } catch (kCoreException $e) { $this->hashKeyErrorCode = $e->getCode(); } } sfView::SUCCESS; }
/** * @dataProvider providerTestMigration */ public function testMigration($kuserId) { $this->assertNull($this->kuser); $this->kuser = kuserPeer::retrieveByPK($kuserId); $this->assertNotNull($this->kuser); $this->assertEquals($this->kuser->getFullName(), trim($this->kuser->getFirstName() . ' ' . $this->kuser->getLastName())); if ($this->kuser->getSalt() && $this->kuser->getSha1Password() && in_array($this->kuser->getPartnerId(), $this->loginPartnerIds)) { $this->assertTrue($this->kuser->getLoginDataId()); $loginData1 = UserLoginDataPeer::retrieveByPK($this->kuser->getLoginDataId()); $this->assertNotNull($loginData1); $loginData2 = UserLoginDataPeer::getByEmail($this->kuser->getEmail()); $this->assertNotNull($loginData2); $this->assertEquals($loginData1->getId(), $loginData2->getId()); $this->assertEquals($this->kuser->getSalt(), $loginData2->getSalt()); $this->assertEquals($this->kuser->getSha1Password(), $loginData2->getSha1Password()); $this->assertEquals($this->kuser->getEmail(), $loginData2->getLoginEmail()); $c = new Criteria(); $c->addAnd(UserLoginDataPeer::LOGIN_EMAIL, $this->kuser->getEmail()); $loginDatas = UserLoginDataPeer::doSelect($c); $this->assertEquals(count($loginDatas), 1); $this->assertEquals($loginDatas[0]->getId(), $loginData1->getId()); $allKusers = kuserPeer::getByLoginDataAndPartner($this->kuser->getLoginDataId(), $this->kuser->getPartnerId()); $this->assertEquals(count($allKusers), 1); } else { if ($this->kuser->getPartnerId() != $this->adminConsolePartnerId && substr($this->kuser->getPuserId(), 0, 9) != '__ADMIN__') { $this->assertNull($this->kuser->getLoginDataId()); } } if ($this->kuser->getPartnerId() == $this->adminConsolePartnerId || substr($this->kuser->getPuserId(), 0, 9) == '__ADMIN__') { $this->assertTrue($this->kuser->getIsAdmin()); } else { $this->assertFalse($this->kuser->getIsAdmin()); } if ($this->kuser->getIsAdmin()) { $this->assertTrue($this->kuser->getIsAdmin()); } }
/** * Return user's login data object if valid */ public function getLoginData() { $loginDataId = $this->getLoginDataId(); if (!$loginDataId) { return null; } return UserLoginDataPeer::retrieveByPK($loginDataId); }
/** * 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()); }
/** * Tests UserService->deleteAction() */ public function testDeleteAction() { // create a new user $this->startSession(KalturaSessionType::ADMIN, null); $newUser = $this->createUser(true, true, __FUNCTION__); $addedUser = $this->addUser($newUser); $this->assertType('KalturaUser', $addedUser); // try to delete with user ks - should fail $this->startSession(KalturaSessionType::USER, null); $exceptionThrown = false; try { $this->client->user->delete($newUser->id); } catch (Exception $e) { $exceptionThrown = $e; } $this->checkException($exceptionThrown, 'SERVICE_FORBIDDEN'); // check that can get user $this->startSession(KalturaSessionType::ADMIN, null); $getUser = $this->client->user->get($newUser->id); $this->assertType('KalturaUser', $getUser); $this->assertEquals(KalturaUserStatus::ACTIVE, $getUser->status); // check delete user with admin ks $deletedUser = $this->client->user->delete($newUser->id); $this->assertEquals(KalturaUserStatus::DELETED, $deletedUser->status); // delete user -> check no get $exceptionThrown = false; try { $this->client->user->get($newUser->id); } catch (Exception $e) { $exceptionThrown = $e; } $this->checkException($exceptionThrown, 'INVALID_USER_ID'); // delete user -> check no list with and without filter $userList = $this->client->user->listAction(); foreach ($userList->objects as $user) { if ($user->id == $newUser->id) { $this->fail('user->list returned a deleted user!'); } } $userFilter = new KalturaUserFilter(); $userFilter->idEqual = $newUser->id; $userList = $this->client->user->listAction($userFilter); $this->assertEquals(0, count($userList->objects)); $this->assertEquals(0, $userList->totalCount); // check that can add a new user with same id $addedUser = $this->addUser($newUser); $this->assertType('KalturaUser', $addedUser); $this->assertEquals($newUser->id, $addedUser->id); // delete user from one partner only $this->startSession(KalturaSessionType::ADMIN, null); $this->startSession2(KalturaSessionType::ADMIN, null); $newUser = $this->createUser(false, true, __FUNCTION__); $createdUser1 = $this->addUser($newUser); $this->assertType('KalturaUser', $createdUser1); $newUser->isAdmin = false; // make the user not admin on the 2nd partner $createdUser2 = $this->addUser2($newUser); $this->assertType('KalturaUser', $createdUser2); $this->assertEquals(self::TEST_PARTNER_ID, $createdUser1->partnerId); $this->assertEquals(self::TEST_PARTNER_ID_2, $createdUser2->partnerId); $deletedUser = $this->client->user->delete($newUser->id); $this->assertEquals(KalturaUserStatus::DELETED, $deletedUser->status); $exceptionThrown = false; try { $this->client->user->get($newUser->id); } catch (Exception $e) { $exceptionThrown = $e; } $this->checkException($exceptionThrown, 'INVALID_USER_ID'); $getUser2 = $this->client2->user->get($newUser->id); $this->assertEquals($createdUser2, $getUser2); $this->assertEquals(self::TEST_PARTNER_ID_2, $getUser2->partnerId); $this->assertEquals($newUser->id, $getUser2->id); // create user with login id on 2 partners $newUser = $this->createUser(true, false, __FUNCTION__); $createdUser1 = $this->addUser($newUser); $this->assertType('KalturaUser', $createdUser1); $newUser->isAdmin = true; // make the user admin on the 2nd partner $createdUser2 = $this->addUser2($newUser); $this->assertType('KalturaUser', $createdUser2); $this->assertEquals(self::TEST_PARTNER_ID, $createdUser1->partnerId); $this->assertEquals(self::TEST_PARTNER_ID_2, $createdUser2->partnerId); // check that login data exists $dbUser = kuserPeer::getKuserByPartnerAndUid(self::TEST_PARTNER_ID, $newUser->id); $loginDataId = $dbUser->getLoginDataId(); $loginData = UserLoginDataPeer::retrieveByPK($loginDataId); $this->assertNotNull($loginData); // delete from 1st partner and verify that login data still exists $this->client->user->delete($newUser->id); $loginData = UserLoginDataPeer::retrieveByPK($loginDataId); $this->assertNotNull($loginData); // verify that user now logs in to the 2nd partner $newClient = $this->getClient(null); $ks = $newClient->user->loginByLoginId($newUser->email, $newUser->password); $this->assertNotNull($ks); $ks = kSessionUtils::crackKs($ks); $this->assertNotNull($ks); $this->assertEquals(self::TEST_PARTNER_ID_2, $ks->partner_id); // delete user with login id when it's the last one $this->client2->user->delete($newUser->id); UserLoginDataPeer::clearInstancePool(); $loginData = UserLoginDataPeer::retrieveByPK($loginDataId); $this->assertNull($loginData); }
/** * * @action resetUserPassword * @param string $userId * @param int $partnerId * @param string $newPassword * @throws KalturaAPIException */ public function resetUserPasswordAction($userId, $partnerId, $newPassword) { if ($partnerId == Partner::ADMIN_CONSOLE_PARTNER_ID || $partnerId == Partner::BATCH_PARTNER_ID) { throw new KalturaAPIException(KalturaErrors::CANNOT_RESET_PASSWORD_FOR_SYSTEM_PARTNER); } //get loginData using userId and PartnerId $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $userId); if (!$kuser) { throw new KalturaAPIException(KalturaErrors::USER_NOT_FOUND); } $userLoginDataId = $kuser->getLoginDataId(); $userLoginData = UserLoginDataPeer::retrieveByPK($userLoginDataId); // check if login data exists if (!$userLoginData) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } try { UserLoginDataPeer::checkPasswordValidation($newPassword, $userLoginData); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $passwordRules = $userLoginData->getInvalidPasswordStructureMessage(); $passwordRules = str_replace("\\n", "<br>", $passwordRules); $passwordRules = "<br>" . $passwordRules; // Add a newline prefix throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID, $passwordRules); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_ALREADY_USED); } } throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } // update password if requested if ($newPassword) { $password = $userLoginData->resetPassword($newPassword); } $userLoginData->save(); }
private function createNewAdminKuser($newPartner, $existing_password) { // generate a new password if not given if ($existing_password != null) { $password = $existing_password; } else { $password = UserLoginDataPeer::generateNewPassword(); } // create the user $kuser = new kuser(); $kuser->setEmail($newPartner->getAdminEmail()); list($firstName, $lastName) = kString::nameSplit($newPartner->getAdminName()); $kuser->setFirstName($firstName); $kuser->setLastName($lastName); $kuser->setPartnerId($newPartner->getId()); $kuser->setIsAdmin(true); $kuser->setPuserId($newPartner->getAdminEmail()); $kuser = kuserPeer::addUser($kuser, $password, false, false); //this also saves the kuser and adds a user_login_data record $loginData = UserLoginDataPeer::retrieveByPK($kuser->getLoginDataId()); return array($password, $loginData->getPasswordHashKey(), $kuser->getId()); }