public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = parent::validateForSubmission($entryDistribution, $action); $maxLengthFields = array(YouTubeDistributionField::MEDIA_DESCRIPTION => self::MEDIA_DESCRIPTION_MAXIMUM_LENGTH, YouTubeDistributionField::MEDIA_TITLE => self::MEDIA_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::WEB_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_EPISODE => self::TV_METADATA_EPISODE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_EPISODE_TITLE => self::TV_METADATA_EPISODE_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_SEASON => self::TV_METADATA_SEASON_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_SHOW_TITLE => self::TV_METADATA_SHOW_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_TMS_ID => self::TV_METADATA_TMS_ID_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_TITLE => self::MOVIE_METADATA_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_TMS_ID => self::MOVIE_METADATA_TMS_ID_MAXIMUM_LENGTH); $inListOrNullFields = array(YouTubeDistributionField::MEDIA_RATING => explode(',', self::MEDIA_RATING_VALID_VALUES), YouTubeDistributionField::ALLOW_COMMENTS => explode(',', self::ALLOW_COMMENTS_VALID_VALUES), YouTubeDistributionField::ALLOW_EMBEDDING => explode(',', self::ALLOW_EMBEDDING_VALID_VALUES), YouTubeDistributionField::ALLOW_RATINGS => explode(',', self::ALLOW_RATINGS_VALID_VALUES), YouTubeDistributionField::ALLOW_RESPONSES => explode(',', self::ALLOW_RESPONSES_VALID_VALUES), YouTubeDistributionField::ADVERTISING_INVIDEO => explode(',', self::ADVERTISING_INVIDEO_VALID_VALUES), YouTubeDistributionField::ADVERTISING_ADSENSE_FOR_VIDEO => explode(',', self::ADVERTISING_ADSENSE_FOR_VIDEO_VALUES), YouTubeDistributionField::DISTRIBUTION_RESTRICTION_DISTRIBUTION_RULE => explode(',', self::DISTRIBUTION_RESTRICTION_DISTRIBUTION_RULE_VALUES), YouTubeDistributionField::URGENT_REFERENCE_FILE => explode(',', self::URGENT_REFERENCE_FILE_VALUES), YouTubeDistributionField::KEEP_FINGERPRINT => explode(',', self::KEEP_FINGERPRINT_VALUES)); $allFieldValues = $this->getAllFieldValues($entryDistribution); if (!$allFieldValues || !is_array($allFieldValues)) { KalturaLog::err('Error getting field values from entry distribution id [' . $entryDistribution->getId() . '] profile id [' . $this->getId() . ']'); return $validationErrors; } $validationErrors = array_merge($validationErrors, $this->validateMaxLength($maxLengthFields, $allFieldValues, $action)); $validationErrors = array_merge($validationErrors, $this->validateInListOrNull($inListOrNullFields, $allFieldValues, $action)); $fieldName = YouTubeDistributionField::NOTIFICATION_EMAIL; $value = $allFieldValues[$fieldName]; //multiple email support $values = explode(' ', $value); foreach ($values as $val) { if (!is_null($val) && !kString::isEmailString($val)) { $errorMsg = $this->getUserFriendlyFieldName($fieldName) . ' value must be an email string [value:' . $val . ']'; $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, $this->getUserFriendlyFieldName($fieldName)); $validationError->setValidationErrorType(DistributionValidationErrorType::CUSTOM_ERROR); $validationError->setValidationErrorParam($errorMsg); $validationErrors[] = $validationError; } } //TODO: check if MEDIA_CATEGORY is a valid YouTube category according to YouTube's XML. return $validationErrors; }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { defPartnerservices2baseAction::disableCache(); $email = trim($this->getPM("adminKuser_email")); $new_email = trim($this->getP("new_email")); $old_password = trim($this->getPM("adminKuser_password", null)); $password = trim($this->getPM("new_password", null)); if ($new_email) { if (!kString::isEmailString($new_email)) { $f_name = "new_email"; $this->addException(APIErrors::INVALID_FIELD_VALUE, $f_name); } } try { UserLoginDataPeer::updateLoginData($email, $old_password, $new_email, $password); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { $this->addException(APIErrors::ADMIN_KUSER_NOT_FOUND); return null; } if ($code == kUserException::WRONG_PASSWORD) { $this->addException(APIErrors::ADMIN_KUSER_WRONG_OLD_PASSWORD); return null; } if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $this->addException(APIErrors::PASSWORD_STRUCTURE_INVALID); return null; } if ($code == kUserException::PASSWORD_ALREADY_USED) { $this->addException(APIErrors::PASSWORD_ALREADY_USED); return null; } if ($code == kUserException::INVALID_EMAIL) { $this->addException(APIErrors::INVALID_FIELD_VALUE, 'new_email'); return null; } if ($code == kUserException::LOGIN_ID_ALREADY_USED) { $this->addException(APIErrors::LOGIN_ID_ALREADY_USED); return null; } throw $e; } if ($new_email) { $this->addMsg("new_email", $new_email); } $this->addMsg("new_password", $password); }
/** * Update admin user password and email * * @param string $email * @param string $password * @param string $newEmail Optional, provide only when you want to update the email * @param string $newPassword * * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_DATA_NOT_FOUND * @throws KalturaErrors::WRONG_OLD_PASSWORD * @throws KalturaErrors::PASSWORD_STRUCTURE_INVALID * @throws KalturaErrors::PASSWORD_ALREADY_USED * @throws KalturaErrors::LOGIN_ID_ALREADY_USED */ protected function updateLoginDataImpl($email, $password, $newEmail = "", $newPassword = "", $newFirstName, $newLastName) { KalturaResponseCacher::disableCache(); $this->validateApiAccessControlByEmail($email); if ($newEmail != "") { if (!kString::isEmailString($newEmail)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, "newEmail"); } } try { UserLoginDataPeer::updateLoginData($email, $password, $newEmail, $newPassword, $newFirstName, $newLastName); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } else { if ($code == kUserException::WRONG_PASSWORD) { if ($password == $newPassword) { throw new KalturaAPIException(KalturaErrors::USER_WRONG_PASSWORD); } else { throw new KalturaAPIException(KalturaErrors::WRONG_OLD_PASSWORD); } } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $c = new Criteria(); $c->add(UserLoginDataPeer::LOGIN_EMAIL, $email); $loginData = UserLoginDataPeer::doSelectOne($c); $invalidPasswordStructureMessage = $loginData->getInvalidPasswordStructureMessage(); throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID, $invalidPasswordStructureMessage); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_ALREADY_USED); } else { if ($code == kUserException::INVALID_EMAIL) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'email'); } else { if ($code == kUserException::LOGIN_ID_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::LOGIN_ID_ALREADY_USED); } } } } } } throw $e; } }
/** * Update admin user password and email * * @param string $email * @param string $password * @param string $newEmail Optional, provide only when you want to update the email * @param string $newPassword * * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_DATA_NOT_FOUND * @throws KalturaErrors::WRONG_OLD_PASSWORD * @throws KalturaErrors::PASSWORD_STRUCTURE_INVALID * @throws KalturaErrors::PASSWORD_ALREADY_USED * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_ID_ALREADY_USED */ protected function updateLoginDataImpl($email, $password, $newEmail = "", $newPassword = "", $newFirstName, $newLastName) { KalturaResponseCacher::disableCache(); if ($newEmail != "") { if (!kString::isEmailString($newEmail)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, "newEmail"); } } try { UserLoginDataPeer::updateLoginData($email, $password, $newEmail, $newPassword, $newFirstName, $newLastName); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } else { if ($code == kUserException::WRONG_PASSWORD) { if ($password == $newPassword) { throw new KalturaAPIException(KalturaErrors::USER_WRONG_PASSWORD); } else { throw new KalturaAPIException(KalturaErrors::WRONG_OLD_PASSWORD); } } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_ALREADY_USED); } else { if ($code == kUserException::INVALID_EMAIL) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'email'); } else { if ($code == kUserException::LOGIN_ID_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::LOGIN_ID_ALREADY_USED); } } } } } } throw $e; } }
public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = parent::validateForSubmission($entryDistribution, $action); $maxLengthFields = array(YahooDistributionField::VIDEO_DESCRIPTION => self::VIDEO_DESCRIPTION_MAXIMUM_LENGTH, YahooDistributionField::VIDEO_FEEDITEM_ID => self::FEED_ITEM_ID_MAXIMUM_LENGTH); $inListOrNullFields = array(); $allFieldValues = $this->getAllFieldValues($entryDistribution); if (!$allFieldValues || !is_array($allFieldValues)) { KalturaLog::err('Error getting field values from entry distribution id [' . $entryDistribution->getId() . '] profile id [' . $this->getId() . ']'); return $validationErrors; } $validationErrors = array_merge($validationErrors, $this->validateMaxLength($maxLengthFields, $allFieldValues, $action)); $validationErrors = array_merge($validationErrors, $this->validateInListOrNull($inListOrNullFields, $allFieldValues, $action)); $validationErrors = array_merge($validationErrors, $this->validateTwoThumbnailsExist($entryDistribution, $action)); //$validationErrors = array_merge($validationErrors, $this->validateVideoStreamFormatAndBitrate($entryDistribution, $action)); //$validationErrors = array_merge($validationErrors, $this->validateThumbnailsDimensions($entryDistribution, $action)); //TODO: validate only video stream formats and remove bitrate and thumb dimensions $emailField = YahooDistributionField::CONTACT_EMAIL; $emailValue = $allFieldValues[$emailField]; if ($emailValue && !kString::isEmailString($emailValue)) { $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, $this->getUserFriendlyFieldName($emailField)); $validationError->setValidationErrorType(DistributionValidationErrorType::INVALID_FORMAT); $validationError->setValidationErrorParam('email'); $validationError->setDescription('Not an email string'); $validationErrors[] = $validationError; } //TODO: validate that if contact_email is given, contact_telephone is given $telephoneField = YahooDistributionField::CONTACT_TELEPHONE; $telephoneValue = $allFieldValues[$telephoneField]; //if Email is given than telephone must be given too if ($emailValue && !$telephoneValue) { $validationError = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, $this->getUserFriendlyFieldName($telephoneField)); $validationError->setValidationErrorType(DistributionValidationErrorType::CUSTOM_ERROR); $validationError->setValidationErrorParam('Telephone is missing'); $validationError->setDescription('Telephone is required'); $validationErrors[] = $validationError; } return $validationErrors; }
private function updateLoginData($email, $password, $newEmail = "", $newPassword = "", $newFirstName = null, $newLastName = null) { if ($newEmail != "") { if (!kString::isEmailString($newEmail)) { throw new KalturaLoginDataException(APIErrors::INVALID_FIELD_VALUE, "newEmail"); } } try { UserLoginDataPeer::updateLoginData($email, $password, $newEmail, $newPassword, $newFirstName, $newLastName); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaLoginDataException(APIErrors::LOGIN_DATA_NOT_FOUND); } else { if ($code == kUserException::WRONG_PASSWORD) { if ($password == $newPassword) { throw new KalturaLoginDataException(APIErrors::USER_WRONG_PASSWORD); } else { throw new KalturaLoginDataException(APIErrors::WRONG_OLD_PASSWORD); } } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $c = new Criteria(); $c->add(UserLoginDataPeer::LOGIN_EMAIL, $email); $loginData = UserLoginDataPeer::doSelectOne($c); $invalidPasswordStructureMessage = $loginData->getInvalidPasswordStructureMessage(); $invalidPasswordStructureMessage = str_replace('\\n', "\n", $invalidPasswordStructureMessage); throw new KalturaLoginDataException(APIErrors::PASSWORD_STRUCTURE_INVALID, $invalidPasswordStructureMessage); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaLoginDataException(APIErrors::PASSWORD_ALREADY_USED); } else { if ($code == kUserException::INVALID_EMAIL) { throw new KalturaLoginDataException(APIErrors::INVALID_FIELD_VALUE, 'email'); } else { if ($code == kUserException::LOGIN_ID_ALREADY_USED) { throw new KalturaLoginDataException(APIErrors::LOGIN_ID_ALREADY_USED); } } } } } } throw $e; } }
/** * 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; } }
public function initNewPartner($partner_name, $contact, $email, $ID_is_for, $SDK_terms_agreement, $description, $website_url, $password = null, $partner = null, $ignorePassword = false) { // Validate input fields if ($partner_name == "") { throw new SignupException("Please fill in the Partner's name", SignupException::INVALID_FIELD_VALUE); } if ($contact == "") { throw new SignupException('Please fill in Administrator\'s details', SignupException::INVALID_FIELD_VALUE); } if ($email == "") { throw new SignupException('Please fill in Administrator\'s Email Address', SignupException::INVALID_FIELD_VALUE); } if (!kString::isEmailString($email)) { throw new SignupException('Invalid email address', SignupException::INVALID_FIELD_VALUE); } if ($description == "") { throw new SignupException('Please fill in description', SignupException::INVALID_FIELD_VALUE); } if ($ID_is_for !== CommercialUseType::COMMERCIAL_USE && $ID_is_for !== CommercialUseType::NON_COMMERCIAL_USE && $ID_is_for !== "commercial_use" && $ID_is_for !== "non-commercial_use") { //string values left for backward compatibility throw new SignupException('Invalid field value.\\nSorry.', SignupException::UNKNOWN_ERROR); } if ($SDK_terms_agreement != "yes") { throw new SignupException('You haven`t approved Terms & Conds.', SignupException::INVALID_FIELD_VALUE); } $existingLoginData = UserLoginDataPeer::getByEmail($email); if ($existingLoginData && !$ignorePassword) { // if a another user already existing with the same adminEmail, new account will be created only if the right password was given if (!$password) { throw new SignupException("User with email [{$email}] already exists in system.", SignupException::EMAIL_ALREADY_EXISTS); } else { if ($existingLoginData->isPasswordValid($password)) { KalturaLog::log('Login id [' . $email . '] already used, and given password is valid. Creating new partner with this same login id'); } else { throw new SignupException("Invalid password for user with email [{$email}].", SignupException::EMAIL_ALREADY_EXISTS); } } } // TODO: log request $newPartner = NULL; $newSubPartner = NULL; try { // create the new partner $newPartner = $this->createNewPartner($partner_name, $contact, $email, $ID_is_for, $SDK_terms_agreement, $description, $website_url, $password, $partner); // create the sub partner // TODO: when ready, add here the saving of this value, currently it will be only // a random value, being passed to the user, and never saved $newSubPartnerId = $this->createNewSubPartner($newPartner); // create a new admin_kuser for the user, // so he will be able to login to the system (including permissions) list($newAdminKuserPassword, $newPassHashKey, $kuserId) = $this->createNewAdminKuser($newPartner, $password); $newPartner->setAccountOwnerKuserId($kuserId); $newPartner->save(); $this->setAllTemplateEntriesToAdminKuser($newPartner->getId(), $kuserId); return array($newPartner->getId(), $newSubPartnerId, $newAdminKuserPassword, $newPassHashKey); } catch (Exception $e) { //TODO: revert all changes, depending where and why we failed throw $e; } }
} $new_login_data = null; if ($user->getSalt() && $user->getSha1Password() && in_array($user->getPartnerId(), $loginPartnerIds)) { $newTempEmail = $user->getEmail(); $c = new Criteria(); $c->addAnd(adminKuserPeer::EMAIL, $newTempEmail, Criteria::EQUAL); $adminKuser = adminKuserPeer::doSelectOne($c); if ($adminKuser) { if ($user->getPartnerId() === $adminKuser->getPartnerId() && $user->getPuserId() === '__ADMIN__' . $adminKuser->getId()) { continue; } $newTempEmail = 'kuser_' . $user->getId() . '_' . $user->getEmail(); $msg = 'NOTICE - kuser [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] is set with email [' . $user->getEmail() . '] already used by admin_kuser id [' . $adminKuser->getId() . '] of partner [' . $adminKuser->getPartnerId() . '] - setting kusers login email to [' . $newTempEmail . ']!'; KalturaLog::notice($msg); } if (!kString::isEmailString($user->getEmail())) { $newTempEmail = 'kuser_' . $user->getId() . '_' . $user->getEmail(); $msg = 'NOTICE - kuser [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] is set with invalid email [' . $user->getEmail() . '] - setting kusers login email to [' . $newTempEmail . ']!'; KalturaLog::notice($msg); } // user can login - add a user_login_data record $existingLoginData = UserLoginDataPeer::getByEmail($newTempEmail); if ($existingLoginData) { $msg = 'NOTICE - login data for the same email [' . $newTempEmail . '] partner id [' . $existingLoginData->getConfigPartnerId() . '] already exists - setting kusers login email to'; $newTempEmail = 'kuser_' . $user->getId() . '_' . $user->getEmail(); while ($temp = UserLoginDataPeer::getByEmail($newTempEmail)) { $newTempEmail = '_' . $newTempEmail; } $msg .= ' [' . $newTempEmail . ']!'; KalturaLog::notice($msg); }