Example #1
0
 /**
  * Tests UserLoginData->setPasswordHashKey() && UserLoginData->getPasswordHashKey()
  */
 public function testSetGetPasswordHashKey()
 {
     // check clean
     $this->assertNull($this->UserLoginData->getPasswordHashKey());
     // check basic set + get
     $random = uniqid();
     $this->UserLoginData->setPasswordHashKey($random);
     $this->assertEquals($random, $this->UserLoginData->getPasswordHashKey());
     // check set + get after db save
     $random = uniqid();
     $this->UserLoginData->setPasswordHashKey($random);
     $this->UserLoginData->save();
     $this->assertEquals($random, $this->UserLoginData->getPasswordHashKey());
     $fromDb = UserLoginDataPeer::retrieveByPK($this->UserLoginData->getId());
     $this->assertEquals($random, $fromDb->getPasswordHashKey());
 }
     }
     KalturaLog::alert('!!! ERROR - Existing login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] !!!!');
     echo '!!! ERROR - Existing login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] !!!!';
     continue;
 }
 $new_login_data->setConfigPartnerId($user->getPartnerId());
 $new_login_data->setLoginEmail($user->getEmail());
 $new_login_data->setFirstName($firstName);
 $new_login_data->setLastName($lastName);
 $new_login_data->setSalt($user->getSalt());
 $new_login_data->setSha1Password($user->getSha1Password());
 $new_login_data->setCreatedAt($user->getCreatedAt());
 $new_login_data->setUpdatedAt($user->getUpdatedAt());
 $new_login_data->setLoginBlockedUntil($user->getLoginBlockedUntil());
 $new_login_data->setLoginAttempts($user->getLoginAttempts());
 $new_login_data->setPasswordHashKey($user->getPasswordHashKey());
 $new_login_data->setPasswordUpdatedAt($user->getPasswordUpdatedAt());
 $new_login_data->setPreviousPasswords($user->getPreviousPasswords());
 $new_login_data->setLastLoginPartnerId($user->getPartnerId());
 // check for existing kusers for this admin_kuser
 $c = new Criteria();
 $c->addAnd(kuserPeer::PUSER_ID, '__ADMIN__' . $user->getId(), Criteria::EQUAL);
 $c->addAnd(kuserPeer::PARTNER_ID, $user->getPartnerId(), Criteria::EQUAL);
 $existing_kuser = kuserPeer::doSelectOne($c);
 if ($existing_kuser) {
     $existing_kuser->setFirstName($firstName);
     $existing_kuser->setLastName($lastName);
     $existing_kuser->setEmail($user->getEmail());
     $existing_kuser->setIsAdmin(true);
 } else {
     $new_kuser->setEmail($user->getEmail());
Example #3
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;
     }
 }