/** * Tests UserLoginData->resetPreviousPasswords() */ public function testResetPreviousPasswords() { $this->assertNull($this->UserLoginData->getPreviousPasswords()); $this->assertNull($this->UserLoginData->getSalt()); $this->assertNull($this->UserLoginData->getSha1Password()); $partnerId = null; $pass = uniqid(); $this->UserLoginData->setPassword($pass); $this->UserLoginData->addToPreviousPasswords($this->UserLoginData->getSha1Password(), $this->UserLoginData->getSalt(), $partnerId); $pass = uniqid(); $this->UserLoginData->setPassword($pass); $this->UserLoginData->addToPreviousPasswords($this->UserLoginData->getSha1Password(), $this->UserLoginData->getSalt(), $partnerId); $this->assertNotNull($this->UserLoginData->getPreviousPasswords()); $this->UserLoginData->resetPreviousPasswords(); $this->assertNull($this->UserLoginData->getPreviousPasswords()); }
/** * Adds a new user login data record * @param unknown_type $loginEmail * @param unknown_type $password * @param unknown_type $partnerId * @param unknown_type $firstName * @param unknown_type $lastName * @param bool $checkPasswordStructure backward compatibility - some extensions are registering a partner and setting its first password without checking its structure * * @throws kUserException::INVALID_EMAIL * @throws kUserException::INVALID_PARTNER * @throws kUserException::PASSWORD_STRUCTURE_INVALID * @throws kUserException::LOGIN_ID_ALREADY_USED * @throws kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED */ public static function addLoginData($loginEmail, $password, $partnerId, $firstName, $lastName, $isAdminUser, $checkPasswordStructure = true, &$alreadyExisted = null) { if (!kString::isEmailString($loginEmail)) { throw new kUserException('', kUserException::INVALID_EMAIL); } $partner = partnerPeer::retrieveByPK($partnerId); if (!$partner) { throw new kUserException('', kUserException::INVALID_PARTNER); } if ($isAdminUser) { $userQuota = $partner->getAdminLoginUsersQuota(); $adminLoginUsersNum = $partner->getAdminLoginUsersNumber(); // check if login users quota exceeded - value -1 means unlimited if ($adminLoginUsersNum && (is_null($userQuota) || $userQuota != -1 && $userQuota <= $adminLoginUsersNum)) { throw new kUserException('', kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED); } } $existingData = self::getByEmail($loginEmail); if (!$existingData) { if ($checkPasswordStructure && !UserLoginDataPeer::isPasswordStructureValid($password)) { throw new kUserException('', kUserException::PASSWORD_STRUCTURE_INVALID); } // create a new login data record $loginData = new UserLoginData(); $loginData->setConfigPartnerId($partnerId); $loginData->setLoginEmail($loginEmail); $loginData->setFirstName($firstName); $loginData->setLastName($lastName); $loginData->setPassword($password); $loginData->setLoginAttempts(0); $loginData->setLoginBlockedUntil(null); $loginData->resetPreviousPasswords(); $loginData->save(); // now $loginData has an id and hash key can be generated $hashKey = $loginData->newPassHashKey(); $loginData->setPasswordHashKey($hashKey); $loginData->save(); $alreadyExisted = false; return $loginData; } else { // add existing login data if password is valid $existingKuser = kuserPeer::getByLoginDataAndPartner($existingData->getId(), $partnerId); if ($existingKuser) { // partner already has a user with the same login data throw new kUserException('', kUserException::LOGIN_ID_ALREADY_USED); } KalturaLog::debug('Existing login data with the same email & password exists - returning id [' . $existingData->getId() . ']'); $alreadyExisted = true; if ($isAdminUser && !$existingData->isLastLoginPartnerIdSet()) { $existingData->setLastLoginPartnerId($partnerId); $existingData->save(); } return $existingData; } }