public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { defPartnerservices2baseAction::disableCache(); $email = trim($this->getPM("email")); try { $new_password = UserLoginDataPeer::resetUserPassword($email); } 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::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, 'email'); return null; } if ($code == kUserException::LOGIN_ID_ALREADY_USED) { $this->addException(APIErrors::LOGIN_ID_ALREADY_USED); return null; } throw $e; } if (!$new_password) { $this->addException(APIErrors::ADMIN_KUSER_NOT_FOUND); } $this->addMsg("msg", "email sent"); }
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); }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $prefix = $this->getObjectPrefix(); $entry_id = $this->getPM("{$prefix}_id"); $detailed = $this->getP("detailed", false); $version = $this->getP("version", false); $c = $this->getCriteria(); if ($c == null) { $c = new Criteria(); $c->add(entryPeer::ID, $entry_id); $c->add(entryPeer::MODERATION_STATUS, entry::ENTRY_MODERATION_STATUS_REJECTED, Criteria::NOT_EQUAL); $entry = entryPeer::doSelectOne($c); } else { $c->add(entryPeer::ID, $entry_id); $c->add(entryPeer::MODERATION_STATUS, entry::ENTRY_MODERATION_STATUS_REJECTED, Criteria::NOT_EQUAL); $entry = entryPeer::doSelectOne($c); } if (!$entry) { $this->addError(APIErrors::INVALID_ENTRY_ID, $prefix, $entry_id); } else { if ($entry->getStatus() == entryStatus::IMPORT || $entry->getStatus() == entryStatus::PRECONVERT) { defPartnerservices2baseAction::disableCache(); } if ($version) { $entry->setDesiredVersion($version); } $extra_fields = $this->getExtraFields(); $level = $detailed ? objectWrapperBase::DETAIL_LEVEL_DETAILED : objectWrapperBase::DETAIL_LEVEL_REGULAR; if ($entry->getType() == entryType::MIX) { $extra_fields = array("allVersionsFormatted"); } if ($extra_fields) { $this->addMsg("{$prefix}", objectWrapperBase::getWrapperClass($entry, $level, -3, 0, $extra_fields)); } else { $this->addMsg("{$prefix}", objectWrapperBase::getWrapperClass($entry, $level)); } $this->addData($entry); } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { defPartnerservices2baseAction::disableCache(); $partner = new Partner(); $obj_wrapper = objectWrapperBase::getWrapperClass($partner, 0); $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $partner, "partner_", $obj_wrapper->getUpdateableFields()); $c = new Criteria(); $c->addAnd(UserLoginDataPeer::LOGIN_EMAIL, $partner->getAdminEmail(), Criteria::EQUAL); $c->setLimit(1); $existingUser = UserLoginDataPeer::doCount($c) > 0; // check that mandatory fields were set // TODO if (count($fields_modified) > 0) { try { $cms_password = $this->getP("cms_password"); $partner_registration = new myPartnerRegistration(); list($pid, $subpid, $pass, $hashKey) = $partner_registration->initNewPartner($partner->getName(), $partner->getAdminName(), $partner->getAdminEmail(), $partner->getCommercialUse(), "yes", $partner->getDescription(), $partner->getUrl1(), $cms_password, $partner); $partner_from_db = PartnerPeer::retrieveByPK($pid); $partner_registration->sendRegistrationInformationForPartner($partner_from_db, false, $existingUser); } catch (SignupException $se) { $this->addError(APIErrors::PARTNER_REGISTRATION_ERROR, $se->getMessage()); return; } catch (Exception $ex) { // this assumes the partner name is unique - TODO - remove key from DB ! $this->addError(APIErrors::SERVERL_ERROR, "Partner with name already exists"); $this->addError(APIErrors::SERVERL_ERROR, $ex->getMessage()); return; } $this->addMsg("partner", objectWrapperBase::getWrapperClass($partner_from_db, objectWrapperBase::DETAIL_LEVEL_DETAILED)); $this->addMsg("subp_id", $subpid); $this->addMsg("cms_password", $pass); $this->addDebug("added_fields", $fields_modified); } else { $this->addError(APIErrors::NO_FIELDS_SET_FOR_PARTNER); } }
public function execute($add_extra_debug_data = true) { date_default_timezone_set(kConf::get("date_default_timezone")); // TODO - remove for production - use some configuration to determine kConfigTable::$should_use_cache = false; $start_impl = $end_impl = 0; $nocache = false; if ($this->getP("nocache")) { $nocache = true; $this->logMessage("Not using cache!"); objectWrapperBase::useCache(false); } $add_benchmarks = $this->getP("add_benchmarks", false); // while testing our system - will match each service agains its description // $this->matchInDescription(); $this->msg = array(); $this->error = array(); $this->debug = array(); $start_time = microtime(true); $start = microtime(true); $this->benchmarkStart("beforeImpl"); $this->response_type = $this->getP("format", self::DEFAULT_FORMAT); // /* $should_debug = $this->getP ( "should_debug" , true ); if ( $should_debug == "false" ) $this->should_debug = false; */ if ($this->should_debug && $add_extra_debug_data) { $this->benchmarkStart("signature"); $sig_type = $this->getP("sigtype", self::SIG_TYPE_POST); $signature_params = self::getParamsFromSigType($sig_type); $signatura_valid = self::validateSignature($signature_params); $this->benchmarkEnd("signature"); $this->addDebug("sigtype", $sig_type); $this->addDebug("validateSignature", $signatura_valid); $this->addDebug("signature", self::signature($signature_params)); // $this->addDebug( "rawsignature" , self::signature( $signature_params , false ) ); } $partner_id = $this->getP("partner_id"); if (!$partner_id) { $partner_id = $this->getP("partnerId"); } $subp_id = $this->getP("subp_id"); if (!$subp_id) { $subp_id = $this->getP("subpId"); } $puser_id = $this->getP("uid"); $ks_str = $this->getP("ks"); if ($ks_str == "{ks}") { $ks_str = ""; } // if the client DIDN'T replace the dynamic ks - ignore it // the $execution_cache_key can be used by services to cache the results depending on the inpu parameters // if the $execution_cache_key is not null, the rendere will search for the result of the rendering depending on the $execution_cache_key // if it doesn't find it - it will create it (per format) and store it for next time $execution_cache_key = null; // moved the renderer here to see if has the $execution_cache_key and if so - skip the implementation $renderer = new kalturaWebserviceRenderer($this->response_context); $private_partner_data = false; try { try { $arr = list($partner_id, $subp_id, $uid, $private_partner_data) = $this->validateTicketSetPartner($partner_id, $subp_id, $puser_id, $ks_str); } catch (Exception $ex) { KalturaLog::log('validateTicketSetPartner failed - not caching response'); defPartnerservices2baseAction::disableCache(); throw $ex; } // if PS2 permission validation is enabled for the current partner, only the actions defined in kConf's parameter "ps2_actions_not_blocked_by_permissions" will be allowed $currentPartner = $this->getPartner(); if ($currentPartner && $currentPartner->getEnabledService(PermissionName::FEATURE_PS2_PERMISSIONS_VALIDATION)) { if (!in_array(strtolower(get_class($this)), kConf::get('ps2_actions_not_blocked_by_permissions'))) { KalturaLog::log('PS2 action ' . get_class($this) . ' is being blocked for partner ' . $currentPartner->getId() . ' defined with FEATURE_PS2_PERMISSIONS_VALIDATION enabled'); $this->addException(APIErrors::SERVICE_FORBIDDEN, get_class($this)); } } $this->private_partner_data = $private_partner_data; //print_r ( $arr ); // TODO - validate the matchIp is ok with the user's IP $this->validateIp(); // most services should not attempt to cache the results - for them this will return null $execution_cache_key = $this->getExecutionCacheKeyWrapper($partner_id, $subp_id, $puser_id); // if the key is not null - it will be used in the renderer for using the cotent from the cache if ($nocache) { $renderer->deleteCacheKey($execution_cache_key, $this->response_type); } else { $renderer->setCacheKey($execution_cache_key); } if (!$renderer->hasContentForCacheKey($this->response_type)) { $this->benchmarkStart("applyPartnerFilters"); //init entitlement before set the default criteire by myPartnerUtils::applyPartnerFilters kEntitlementUtils::initEntitlementEnforcement(); // apply filters for Criteria so there will be no chance of exposure of date from other partners ! // TODO - add the parameter for allowing kaltura network myPartnerUtils::applyPartnerFilters($partner_id, $private_partner_data, $this->partnerGroup2(), $this->kalturaNetwork2()); $this->benchmarkEnd("applyPartnerFilters"); $this->benchmarkStart("puserKuser"); list($partner_id, $subp_id, $puser_id, $partner_prefix) = $this->preparePartnerPuserDetails($partner_id, $subp_id, $puser_id); $puser_kuser = $this->getPuserKuser($partner_id, $subp_id, $puser_id); $this->benchmarkEnd("puserKuser"); $this->benchmarkEnd("beforeImpl"); // ----------------------------- impl -------------------------- $start_impl = microtime(true); $result = $this->executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser); $end_impl = microtime(true); kEventsManager::flushEvents(); } else { /// the renderer claims to have the desired result ! just flow down the code ... ;) } // ----------------------------- impl -------------------------- } catch (APIException $api_ex) { $message = $api_ex->getMessage(); if ($this->should_debug && $message) { $this->addError(APIErrors::SERVERL_ERROR, "[{$message}]"); } elseif ($api_ex->api_code) { call_user_func_array(array(&$this, 'addError'), $api_ex->extra_data); // $this->addError ( $api_ex->api_code ,$api_ex->extra_data ); } } catch (PropelException $pex) { KalturaLog::alert($pex->getMessage()); $this->addError(APIErrors::INTERNAL_DATABASE_ERROR); } catch (Exception $ex) { $this->addError(APIErrors::INTERNAL_SERVERL_ERROR, $ex->getMessage()); KalturaLog::err($ex->getMessage()); } $execute_impl_end_time = microtime(true); // render according to the format_type $res = array(); $this->addMsg("serverTime", time()); $res['result'] = $this->msg; $res['error'] = $this->error; if ($this->should_debug) { // this specific debug line should be used $this->addDebug("execute_impl_time", $end_impl - $start_impl); $this->addDebug("execute_time", $execute_impl_end_time - $start_time); // will be used as a place holder and will be replaced after the rendering. if ($add_extra_debug_data) { $this->addDebug("total_time", self::__TOTAL_TIME__); } if ($add_benchmarks && count($this->benchmarks) > 0) { $this->addDebug("host", @$_ENV["HOSTNAME"]); $this->addDebug("benchmarks", $this->getBenchmarks()); } $res['debug'] = $this->debug; } // ignore all the errors and debug - the first msg is the only html used if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_HTML) { $res = "<html>"; foreach ($this->msg as $html_bit) { $res .= $html_bit; } $res .= "</html>"; } if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // in case of mRss - render only the result not the errors ot the debug list($response, $content_type) = $renderer->renderDataInRequestedFormat($res['result'], $this->response_type, true, self::$escape_text); } else { list($response, $content_type) = $renderer->renderDataInRequestedFormat($res, $this->response_type, true, self::$escape_text); } $end_time = microtime(true); if (is_string($response)) { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "] seconds. Response size [" . strlen($response) . "]", SF_LOG_WARNING); $this->logMessage($response, SF_LOG_WARNING); } else { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "]"); } if ($this->should_debug && $add_extra_debug_data) { // fix the total time including the render time $str_time = (string) ($end_time - $start_time); if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP) { // replcate the placehoder with the real execution time // this is a nasty hack - we replace the serialized PHP value - the length of the placeholder is 14 characters // the length of the str_time can be less - replace the whole string phrase $replace_string = 's:' . strlen($str_time) . ':"' . $str_time; $response = str_replace('s:14:"' . self::__TOTAL_TIME__, $replace_string, $response); } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_ARRAY || $this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_OBJECT) { // the $response is not a string - we can't just replace it $res["debug"]["total_time"] = $str_time; } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // do nothing to the result } else { $response = str_replace(self::__TOTAL_TIME__, $str_time, $response); } } header("Access-Control-Allow-Origin:*"); // avoid html5 xss issues $this->setContentType($content_type); // while testing our system - will match each service agains its description // $this->matchOutDescription(); return $response; }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { defPartnerservices2baseAction::disableCache(); kuserPeer::setUseCriteriaFilter(false); $email = trim($this->getPM("email")); $password = trim($this->getPM("password")); $loginData = UserLoginDataPeer::getByEmail($email); // be sure to return the same error if there are no admins in the list and when there are none matched - // so no hint about existing admin will leak if (!$loginData) { $this->addError(APIErrors::ADMIN_KUSER_NOT_FOUND); return; } try { $adminKuser = UserLoginDataPeer::userLoginByEmail($email, $password, $partner_id); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::USER_NOT_FOUND) { $this->addError(APIErrors::ADMIN_KUSER_NOT_FOUND); return null; } if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { $this->addError(APIErrors::ADMIN_KUSER_NOT_FOUND); return null; } else { if ($code == kUserException::LOGIN_RETRIES_EXCEEDED) { $this->addError(APIErrors::LOGIN_RETRIES_EXCEEDED); return null; } else { if ($code == kUserException::LOGIN_BLOCKED) { $this->addError(APIErrors::LOGIN_BLOCKED); return null; } else { if ($code == kUserException::PASSWORD_EXPIRED) { $this->addError(APIErrors::PASSWORD_EXPIRED); return null; } else { if ($code == kUserException::WRONG_PASSWORD) { $this->addError(APIErrors::USER_WRONG_PASSWORD); return null; } else { if ($code == kUserException::USER_IS_BLOCKED) { $this->addError(APIErrors::USER_IS_BLOCKED); return null; } else { $this->addError(APIErrors::INTERNAL_SERVERL_ERROR); return null; } } } } } } } if (!$adminKuser || !$adminKuser->getIsAdmin()) { $this->addError(APIErrors::ADMIN_KUSER_NOT_FOUND); return null; } if ($partner_id && $partner_id != $adminKuser->getPartnerId()) { $this->addError(APIErrors::UNKNOWN_PARTNER_ID); return; } $partner = PartnerPeer::retrieveByPK($adminKuser->getPartnerId()); if (!$partner) { $this->addError(APIErrors::UNKNOWN_PARTNER_ID); return; } $partner_id = $partner->getId(); $subp_id = $partner->getSubpId(); $admin_puser_id = $adminKuser->getPuserId(); // get the puser_kuser for this admin if exists, if not - creae it and return it - create a kuser too $puser_kuser = PuserKuserPeer::createPuserKuser($partner_id, $subp_id, $admin_puser_id, $adminKuser->getScreenName(), $adminKuser->getScreenName(), true); $uid = $puser_kuser->getPuserId(); $ks = null; // create a ks for this admin_kuser as if entered the admin_secret using the API // ALLOW A KS FOR 30 DAYS kSessionUtils::createKSessionNoValidations($partner_id, $uid, $ks, 30 * 86400, 2, "", "*"); $this->addMsg("partner_id", $partner_id); $this->addMsg("subp_id", $subp_id); $this->addMsg("uid", $uid); $this->addMsg("ks", $ks); $this->addMsg("screenName", $adminKuser->getFullName()); $this->addMsg("fullName", $adminKuser->getFullName()); $this->addMsg("email", $adminKuser->getEmail()); }