/** * Method for allowing a user to reset their password * @param {stdClass} $data Data passed from ActionScript * @return {array} Returns a standard response array */ public function lostPassword($data) { $response = CodeBank_ClientAPI::responseBase(); $response['login'] = true; $SQL_email = Convert::raw2sql($data->user); $member = Member::get_one('Member', "\"Email\"='{$SQL_email}'"); // Allow vetoing forgot password requests $sng = new MemberLoginForm(Controller::has_curr() ? Controller::curr() : singleton('Controller'), 'LoginForm'); $results = $sng->extend('forgotPassword', $member); if ($results && is_array($results) && in_array(false, $results, true)) { $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data['Email'])); } if ($member) { $token = $member->generateAutologinTokenAndStoreHash(); $e = Member_ForgotPasswordEmail::create(); $e->populateTemplate($member); $e->populateTemplate(array('PasswordResetLink' => Security::getPasswordResetLink($member, $token))); $e->setTo($member->Email); $e->send(); $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data->user)); } else { if (!empty($data->user)) { $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data->user)); } else { $response['status'] = 'EROR'; $response['message'] = _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'); } } return $response; }
/** * Deletes a folder * @param {stdClass} $data Data passed from ActionScript * @return {array} Standard response base */ public function moveSnippet($data) { $response = CodeBank_ClientAPI::responseBase(); //Ensure logged in if (!Permission::check('CODE_BANK_ACCESS')) { $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.PERMISSION_DENINED', '_Permission Denied'); return $response; } $snippet = Snippet::get()->byID(intval($data->id)); if (empty($snippet) || $snippet === false || $snippet->ID == 0) { $response['status'] = "EROR"; $response['message'] = _t('CodeBankAPI.SNIPPET_NOT_FOUND', '_Snippet not found'); return $response; } if ($data->folderID != 0) { $snippetFolder = SnippetFolder::get()->byID(intval($data->folderID)); if (empty($snippetFolder) || $snippetFolder === false || $snippetFolder->ID == 0) { $response['status'] = "EROR"; $response['message'] = _t('CodeBankAPI.FOLDER_DOES_NOT_EXIST', '_Folder does not exist'); return $response; } if ($snippetFolder->LanguageID != $snippet->LanguageID) { $response['status'] = "EROR"; $response['message'] = _t('CodeBankAPI.LANGUAGE_NOT_SAME', '_Folder is not in the same language as the snippet'); return $response; } } try { $snippet->FolderID = $data->folderID; $snippet->write(); $response['status'] = "HELO"; } catch (Exception $e) { $response['status'] = "EROR"; $response['message'] = "Internal Server error occured"; } return $response; }
/** * Edits a language * @param {stdClass} $data Data passed from ActionScript * @return {array} Returns a standard response array */ public function editLanguage($data) { $response = CodeBank_ClientAPI::responseBase(); try { if (SnippetLanguage::get()->filter('Name:nocase', Convert::raw2sql($data->language))->Count() > 0) { $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.LANGUAGE_EXISTS', '_Language already exists'); return $response; } $lang = SnippetLanguage::get()->byID(intval($data->id)); if (empty($lang) || $lang === false || $lang->ID == 0) { $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.LANGUAGE_NOT_FOUND', '_Language not found'); return $response; } //Update language and write if ($lang->UserLanguage == true) { $lang->Name = $data->language; $lang->FileExtension = $data->fileExtension; } $lang->Hidden = $data->hidden; $lang->write(); $response['status'] = 'HELO'; $response['message'] = "Language edited successfully"; } catch (Exception $e) { $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.SERVER_ERROR', '_Server error has occured, please try again later'); } return $response; }
/** * Gets the current php session id */ public function getSessionId() { $response = CodeBank_ClientAPI::responseBase(); $response['data'] = session_id(); return $response; }
/** * Loads a remote class or method and executes the function and returns the result * @param {string} $method Is the method to execute * @param {mixed} $param values for the method * @return {mixed} $response the result of executing the method * @throws Zend_Amf_Server_Exception */ protected function _dispatch($method, $params = null, $source = null) { if ($source) { if (($mapped = Zend_Amf_Parse_TypeLoader::getMappedClassName($source)) !== false) { $source = $mapped; } } $qualifiedName = empty($source) ? $method : $source . '.' . $method; if (!isset($this->_table[$qualifiedName])) { // if source is null a method that was not defined was called. if ($source) { $className = 'CodeBank' . str_replace('.', '_', $source); if (class_exists($className, false) && !isset($this->_classAllowed[$className])) { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Can not call "' . $className . '" - use setClass()'); } try { $this->getLoader()->load($className); } catch (Exception $e) { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Class "' . $className . '" does not exist: ' . $e->getMessage(), 0, $e); } // Add the new loaded class to the server. $this->setClass($className, $source); } if (!isset($this->_table[$qualifiedName])) { // Source is null or doesn't contain specified method require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Method "' . $method . '" does not exist'); } } $info = $this->_table[$qualifiedName]; $argv = $info->getInvokeArguments(); if (0 < count($argv)) { $params = array_merge($params, $argv); } if ($info instanceof Zend_Server_Reflection_Function) { $func = $info->getName(); $this->_checkAcl(null, $func); $return = call_user_func_array($func, $params); } else { if ($info instanceof Zend_Server_Reflection_Method) { // Get class $class = $info->getDeclaringClass()->getName(); //Check permissions if ($this->_canAccess($class) == false) { $response = CodeBank_ClientAPI::responseBase(); $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.PERMISSION_DENINED', '_Permission Denied'); return $response; } if ('static' == $info->isStatic()) { // for some reason, invokeArgs() does not work the same as // invoke(), and expects the first argument to be an object. // So, using a callback if the method is static. $this->_checkAcl($class, $info->getName()); $return = call_user_func_array(array($class, $info->getName()), $params); } else { // Object methods try { $object = $info->getDeclaringClass()->newInstance(); } catch (Exception $e) { throw new Zend_Amf_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName() . ': ' . $e->getMessage(), 621, $e); } $this->_checkAcl($object, $info->getName()); $return = $info->invokeArgs($object, $params); } } else { throw new Zend_Amf_Server_Exception('Method missing implementation ' . get_class($info)); } } return $return; }