示例#1
0
 /**
  * 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());
 }
示例#2
0
 /**
  * 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;
     }
 }