/** * 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; } }
/** * $notification_type - * $puser_id - the puser_id of the kuser that caused the modification * $object_data - can be either an object or an object id (if the object no longer exists * $partner_id - if exists, use this (usually in case of $object_data is an id), if not - use the partner_id from the object * $entry_id is optional */ public static function createNotification($notification_type, $object_data, $partner_id = null, $puser_id = null, $prefix = null, $extra_notification_data = null, $entry_id = null) { if (!$entry_id && $object_data instanceof entry) { $entry_id = $object_data->getId(); } if (!$partner_id) { if ($object_data instanceof BaseObject) { $partner_id = $object_data->getPartnerId(); } else { KalturaLog::log("Cannot create notification [{$notification_type}] [{$object_data}] [{$partner_id}]"); return false; } } // echo "[$partner_id]"; $nofication_config_str = null; list($nofity, $nofication_config_str) = myPartnerUtils::shouldNotify($partner_id); if (!$nofity) { return false; } $nofication_config = myNotificationsConfig::getInstance($nofication_config_str); $nofity_send_type = $nofication_config->shouldNotify($notification_type); //echo "nofication_config_str: $nofication_config_str<br>notification_type:$notification_type<br>"; if ($nofity_send_type == self::NOTIFICATION_MGR_NO_SEND) { return false; } //echo "nofity_send_type: $nofity_send_type<br>"; // now check what type of notification to use - none / synch / a-synch // Remarked by Tan-Tan, Nov 5 2009 to support the new batches // // $not = new notification(); // $not->setType( $notification_type ); // if ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH) // { // // // the notification should be in status pending so it will be sent in the // $not->setStatus( BatchJob::BATCHJOB_STATUS_PENDING ); // } // elseif ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH ) // { // $not->setStatus( BatchJob::BATCHJOB_STATUS_FINISHED ); // } // // // return the notification to the caller // $retrun_notification = ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH ); // ////echo "retrun_notification: $retrun_notification<br>"; // // $not->setPartnerId( $partner_id ); // $not->setPuserId( $puser_id ); // $not->setDc ( kDataCenterMgr::getCurrentDcId() ); // if ( $object_data instanceof BaseObject ) // { // $not->setObjectId($object_data->getId() ); // $not->setData( self::createNotificationData ( $notification_type , $object_data, $extra_notification_data ) ); // // if ( $object_data instanceof entry ) // { // if (defined("KALTURA_API_V3")) // $puser_id = $object_data->getKuser()->getPuserId(); // else // $puser_id = PuserKuserPeer::getByKuserId( $object_data->getKuserId() , 1 ); // // $not->setPuserId( $puser_id ); // // } // } // else // { // // in this case all we have is the object data which is the id // // this is probably the case of some delete and we mifght not have the object in hand but only the id // $not->setObjectId( $object_data ); // } // $not->save(); // Added by Tan-Tan, Nov 2009 to support the new batches // if ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH) // { // // // the notification should be in status pending so it will be sent in the // $job->setStatus( BatchJob::BATCHJOB_STATUS_PENDING ); // } // else $dontSend = false; if ($nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH) { $dontSend = true; } // return the notification to the caller $retrun_notification = $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH; $objectId = null; $notificationData = null; if ($object_data instanceof BaseObject) { $objectId = $object_data->getId(); $notificationData = self::createNotificationData($notification_type, $object_data, $extra_notification_data); if ($object_data instanceof entry) { if (defined("KALTURA_API_V3")) { $kuser = $object_data->getKuser(); if ($kuser) { $puser_id = $kuser->getPuserId(); } else { $puser_id = null; KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not find kuser [' . $object_data->getKuserId() . '] from object [' . $object_data->getId() . ']'); } } else { $puser_id = PuserKuserPeer::getByKuserId($object_data->getKuserId(), 1); // in flatten (or maybe other old batches), KALTURA_API_V3 is not defined, but entry user could have // been created through api v3, in that case there will not be a record in puser_kuser table if (is_null($puser_id)) { $puser_id = $object_data->getPuserId(); // if entry was created on PS2 and from some reason puserId is still missing if (is_null($puser_id)) { $kuser = kuserPeer::retrieveByPK($object_data->getKuserId()); if ($kuser) { $puser_id = $kuser->getPuserId(); } } } if (is_null($puser_id)) { KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not get puser_id out of api_v3 context puserId from entry:[' . $object_data->getPuserId() . '] kuser ID:[' . $object_data->getKuserId() . '] entry:[' . $object_data->getId() . ']'); } } } } else { // in this case all we have is the object data which is the id // this is probably the case of some delete and we mifght not have the object in hand but only the id $objectId = $object_data; } $job = kJobsManager::addNotificationJob(null, $entry_id, $partner_id, $notification_type, $nofity_send_type, $puser_id, $objectId, $notificationData); if ($retrun_notification) { // return the notification id, notification object , url & the serialized data $partner = partnerPeer::retrieveByPK($partner_id); list($url, $signature_key) = self::getPartnerNotificationInfo($partner); list($params, $raw_signature) = self::prepareNotificationData($url, $signature_key, $job, $prefix); $serialized_params = http_build_query($params, "", "&"); return array($job->getId(), $job, $url, $params, $serialized_params); } else { return $job->getId(); } }