本文整理汇总了PHP中HTTP_Exception类的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Exception类的具体用法?PHP HTTP_Exception怎么用?PHP HTTP_Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTP_Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_login
public function action_login()
{
$this->view->username = '';
$this->view->return_to = Arr::get($_REQUEST, 'return_to', '');
if ($this->request->post('login') !== NULL) {
Auth::instance()->logout();
// Just in case we're logged in.
$this->view->username = trim($this->request->post('username'));
$password = trim($this->request->post('password'));
Auth::instance()->login($this->view->username, $password);
if (Auth::instance()->logged_in()) {
try {
$dbms = new WebDB_DBMS();
$dbms->refresh_cache();
$this->add_flash_message('You are now logged in.', 'info');
Kohana::$log->add(Kohana_Log::INFO, $this->view->username . ' logged in.');
} catch (Exception $e) {
$msg = 'Unable to log in as :username.';
throw HTTP_Exception::factory(500, $msg, array(':username' => $this->view->username), $e);
}
$this->redirect($this->view->return_to);
} else {
Kohana::$log->add(Kohana_Log::INFO, 'Failed log in: ' . $this->view->username);
$this->add_template_message('Login failed. Please try again.');
}
}
// if ($this->request->post('login') !== NULL)
}
示例2: action_index
public function action_index()
{
try {
if ($token = $this->grantAccessToken()) {
// @see http://tools.ietf.org/html/rfc6749#section-5.1
// server MUST disable caching in headers when tokens are involved
$this->response->status(200);
$this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
$this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
$this->response->body(JSON::encode($token));
return;
}
} catch (Oauth2_Exception $e) {
// Throw an exception because there was a problem with the client's request
$response = array('error' => $e->getError(), 'error_description' => $e->getMessage());
$this->response->status($e->getCode());
$this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
$this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
$this->response->body(json_encode($response));
return;
} catch (Exception $e) {
/**
* Something went wrong!
*
* Throw an error when a non-library specific exception has been thrown
*
* You should probably show a nice error page :)
*
* Do NOT redirect the user back to the client.
*/
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
示例3: action_share
/**
* REST endpoint for sharing droplets via email
*/
public function action_share()
{
$this->template = '';
$this->auto_render = FALSE;
if ($this->request->method() != "POST") {
throw HTTP_Exception::factory(405)->allowed('POST');
}
// Extract the input data to be used for sending the email
$post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code'));
$csrf_token = $this->request->headers('x-csrf-token');
// Setup validation
$validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url');
// Validate
if (!CSRF::valid($csrf_token) or !$validation->check()) {
Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure");
throw HTTP_Exception::factory(400);
} else {
list($recipient, $subject) = array($post['recipient'], $post['drop_title']);
// Modify the mail body to include the email address of the
// use sharing content
$mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url']));
// Send the email
Swiftriver_Mail::send($recipient, $subject, $mail_body);
}
}
示例4: action_index
/**
* View users profile
*/
public function action_index()
{
$id = $this->request->param('id');
$user = ORM::factory('User', $id);
if (!$user->loaded()) {
throw HTTP_Exception::Factory('404', 'No such user');
}
$container = new Tabs();
$about = new Tab('About me');
$about->add_content(new Tab_Text($user->get_property('about')));
$about->add_content(new Tab_Text($user->get_property('signature')));
$container->add_tab($about);
Event::fire('user.profile_tabs', array($user, $container));
$this->view = new View_User_Profile();
$this->view->user = $user;
$this->view->tabs = $container->render();
/*
// @TODO, This belongs to the pet module, better to use events?
$pets = ORM::factory('User_Pet')
->where('user_id', '=', $user->id)
->order_by('active', 'desc');
$paginate = Paginate::factory($pets)
->execute();
$this->view = new View_User_Profile;
$this->view->pagination = $paginate->render();
$this->view->profile_user = $user;
// $this->view->pets = ORM::factory('User_Pet')->where('user_id', '=', $user->id)->order_by('active', 'desc')->find_all()->as_array();
$this->view->pets = $paginate->result();
*/
}
示例5: action_reply
/**
* Handle incoming SMS from Twilio
*/
public function action_reply()
{
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['twilio']) {
throw HTTP_Exception::factory(403, 'The Twilio data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
if ($this->request->method() != 'POST') {
// Only POST is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
}
$provider = DataProvider::factory('twilio');
// Authenticate the request
$options = $provider->options();
if ($this->request->post('AccountSid') !== $options['account_sid']) {
throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
$from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
$message_text = $this->request->post('Body');
$message_sid = $this->request->post('MessageSid');
// @todo use other info from twillio, ie: location, media
$provider->receive(Message_Type::SMS, $from, $message_text, $to, NULL, $message_sid);
// If we have an auto response configured, return the response messages
if (!empty($options['sms_auto_response'])) {
$body = View::factory('twillio/sms_response')->set('response', $options['sms_auto_response'])->render();
// Set the correct content-type header
$this->response->headers('Content-Type', 'text/xml');
$this->response->body($body);
}
}
示例6: action_index
public function action_index()
{
try {
// Validating
$this->validateRevokeRequest();
if ($this->token_info['access_token'] == $this->token && !empty($this->token_info['refresh_token'])) {
$result = Model::factory('oauth')->revoke_access_refresh($this->token);
} elseif ($this->token_info['access_token'] == $this->token && empty($this->token_info['refresh_token'])) {
$result = Model::factory('oauth')->revoke_access($this->token);
} elseif ($this->token_info['refresh_token'] == $this->token) {
$result = Model::factory('oauth')->revoke_refresh($this->token);
}
$this->response->body(json_encode(array('Response' => "Status Code: 200")));
return;
} catch (Oauth2_Exception $e) {
// Throw an exception because there was a problem with the client's request
$response = array('error' => $e->getError(), 'error_description' => $e->getMessage());
$this->response->status($e->getCode());
$this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
$this->response->body(json_encode($response));
} catch (Exception $e) {
/**
* Something went wrong!
*
* Throw an error when a non-library specific exception has been thrown
*
* You should probably show a nice error page :)
*
* Do NOT redirect the user back to the client.
*/
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
示例7: create_email
/**
* creates a user from email if exists doesn't...
* @param string $email
* @param string $name
* @param string $password
* @return Model_User
*/
public static function create_email($email, $name = NULL, $password = NULL)
{
$user = new self();
$user->where('email', '=', $email)->limit(1)->find();
if (!$user->loaded()) {
if ($password === NULL) {
$password = Text::random('alnum', 8);
}
$user->email = $email;
$user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
$user->status = self::STATUS_ACTIVE;
$user->id_role = Model_Role::ROLE_USER;
$user->seoname = $user->gen_seo_title($user->name);
$user->password = $password;
$user->subscriber = 1;
$user->last_ip = ip2long(Request::$client_ip);
$user->country = euvat::country_code();
//geo info EU
try {
$user->save();
//send welcome email
$url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE);
$user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url));
} catch (ORM_Validation_Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
return $user;
}
示例8: action_complete
public function action_complete()
{
// Get the transaction details.
$fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
$data = $fetch->getData();
// Add the buyer email to parameters.
$parameters = $this->_payment_vars() + array('email' => $data['EMAIL']);
/** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */
$request = $this->_gateway->createRecurringPaymentsProfile($parameters);
// Overwrite Item Category.
$data = $request->getData();
$data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory'];
/** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */
$response = $request->sendData($data);
if ($response->isSuccessful()) {
$response_data = $response->getData();
// Get the transaction details.
// $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
// $data = $fetch->getData();
ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create();
Hint::success(Kohana::message('payment', 'payment.success'));
$this->redirect(Route::get('payment')->uri());
} else {
// Log the error.
Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData()));
throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!');
}
}
示例9: action_index
public function action_index()
{
// Log the output
Kohana::$log->add(Log::DEBUG, IPN::array_to_string($this->request->post()));
$this->_IPN = new IPN();
$this->_IPN->process($this->request->post());
// If the request did not come from PayPal show a 404 page.
if (!$this->_IPN->is_verified()) {
throw HTTP_Exception::factory('404', 'File not found!');
}
// TODO: We want to log all IPN actions and ensure we do not process the same action TWICE!
// Find the correct subscription.
$this->_subscription = ORM::factory('Payment_Subscription')->where('recurring_payment_id', '=', $this->_IPN->get_data('recurring_payment_id'))->find();
Kohana::$log->add(Log::DEBUG, $this->_IPN->get_transaction_type());
switch ($this->_IPN->get_transaction_type()) {
case IPN::RECURRING_PAYMENT_PROFILE_CREATED:
Kohana::$log->add(Log::DEBUG, 'PROFILE CREATED');
$this->_profile_created();
break;
case IPN::RECURRING_PAYMENT:
Kohana::$log->add(Log::DEBUG, 'PAYMENT RECEIVED');
$this->_payment();
break;
case IPN::RECURRING_PAYMENT_PROFILE_CANCEL:
Kohana::$log->add(Log::DEBUG, 'PROFILE CANCEL');
$this->_profile_cancel();
break;
}
$this->response->status(200);
$this->response->body('OK');
}
示例10: action_index
/**
* Serve the file to the browser AND cache it for direct access if in STAGING OR PRODUCTION.
*/
public function action_index()
{
$file = $this->request->param('file');
$ext = pathinfo($file, PATHINFO_EXTENSION);
$path = Kohana::find_file('assets', $file, FALSE);
if ($path === FALSE) {
throw HTTP_Exception::factory('404', 'File not found!');
}
$dir = DOCROOT . 'assets' . DIRECTORY_SEPARATOR;
// Set the proper headers for browser caching
$this->response->headers('content-type', File::mime_by_ext($ext));
$this->response->headers('last-modified', date('r', filemtime($path)));
$content = file_get_contents($path);
$this->response->body($content);
// Don't cache the assets unless we are in STAGING OR PRODUCTION.
if (Kohana::$environment >= Kohana::STAGING) {
return;
}
// Only cache for specific extensions.
if (!in_array($ext, $this->_cache_extensions)) {
return;
}
// Check if assets sub dir exist.
$parts = explode('/', $file);
$file = array_pop($parts);
foreach ($parts as $part) {
$dir .= $part . DIRECTORY_SEPARATOR;
if (!is_dir($dir)) {
mkdir($dir);
}
}
file_put_contents($dir . $file, $content);
}
示例11: action_view
/**
* List of pages (blogs/posts/etc.) with a specific tag
*
* @throws HTTP_Exception_404
*
* @uses Log::add
* @uses Text::ucfirst
* @uses ACL::check
* @uses Meta::links
* @uses URL::canonical
* @uses Route::url
*/
public function action_view()
{
$id = (int) $this->request->param('id', 0);
$tag = ORM::factory('tag', $id);
if (!$tag->loaded()) {
throw HTTP_Exception::factory(404, 'Tag :tag not found!', array(':tag' => $id));
}
$this->title = __(':title', array(':title' => Text::ucfirst($tag->name)));
$view = View::factory('tag/view')->set('teaser', TRUE)->bind('pagination', $pagination)->bind('posts', $posts);
$posts = $tag->posts;
if (!ACL::check('administer tags') and !ACL::check('administer content')) {
$posts->where('status', '=', 'publish');
}
$total = $posts->reset(FALSE)->count_all();
if ($total == 0) {
Log::info('No posts found.');
$this->response->body(View::factory('page/none'));
return;
}
$pagination = Pagination::factory(array('current_page' => array('source' => 'cms', 'key' => 'page'), 'total_items' => $total, 'items_per_page' => 15, 'uri' => $tag->url));
$posts = $posts->order_by('created', 'DESC')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
$this->response->body($view);
// Set the canonical and shortlink for search engines
if ($this->auto_render === TRUE) {
Meta::links(URL::canonical($tag->url, $pagination), array('rel' => 'canonical'));
Meta::links(Route::url('tag', array('action' => 'view', 'id' => $tag->id)), array('rel' => 'shortlink'));
}
}
示例12: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
if ($this->request->method() != 'GET') {
// Only GET is allowed as FrontlineSms does only GET request
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::GET))->allowed(Http_Request::GET);
}
$provider = DataProvider::factory('frontlinesms');
// Authenticate the request
$options = $provider->options();
if (!isset($options['key']) or empty($options['key'])) {
throw HTTP_Exception::factory(403, 'Key value has not been configured');
}
if (!$this->request->query('key') or $this->request->query('key') != $options['key']) {
throw HTTP_Exception::factory(403, 'Incorrect or missing key');
}
if (!$this->request->query('m')) {
throw HTTP_Exception::factory(403, 'Missing message');
}
// Remove Non-Numeric characters because that's what the DB has
$from = preg_replace('/\\D+/', "", $this->request->post('from'));
$message_text = $this->request->query('m');
// If receiving an SMS Message
if ($from and $message_text) {
$provider->receive(Message_Type::SMS, $from, $message_text, $to);
}
$json = array('payload' => array('success' => TRUE, 'error' => NULL));
// Set the correct content-type header
$this->response->headers('Content-Type', 'application/json');
$this->response->body(json_encode($json));
}
示例13: action_gather
/**
* Callback for 'gather' response on call to Twilio
*/
public function action_gather()
{
if ($this->request->method() != 'POST') {
// Only POST is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
}
$provider = DataProvider::factory('twilio');
// Authenticate the request
$options = $provider->options();
if ($this->request->post('AccountSid') !== $options['account_sid']) {
// Could not authenticate the request?
throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
$from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
$message_sid = $this->request->post('CallSid');
$digits = $this->request->post('Digits');
if ($digits == 1) {
$message_text = 'IVR: Okay';
} else {
if ($digits == 2) {
$message_text = 'IVR: Not Okay';
} else {
// HALT
Kohana::$log->add(Log::ERROR, __("':digits' is not a valid IVR response", array(":digits" => $digits)));
return;
}
}
$provider->receive(Message_Type::IVR, $from, $message_text, $to, NULL, $message_sid);
}
示例14: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['smssync']) {
throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
$methods_with_http_request = [Http_Request::POST, Http_Request::GET];
if (!in_array($this->request->method(), $methods_with_http_request)) {
// Only POST or GET is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
}
$this->_provider = DataProvider::factory('smssync');
$this->options = $this->_provider->options();
// Ensure we're always returning a payload..
// This will be overwritten later if incoming or task methods are run
$this->_json['payload'] = ['success' => TRUE, 'error' => NULL];
// Process incoming messages from SMSSync only if the request is POST
if ($this->request->method() == 'POST') {
$this->_incoming();
}
// Attempt Task if request is GET and task type is 'send'
if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
$this->_task();
}
// Set the response
$this->_set_response();
}
示例15: before
/**
* Ensure we are calling this controller from the install.php by checking the MG_INSTALL constant.
* And throw a HTTP 404 exception if that is not the case.
*
* @throws HTTP_Exception
*/
public function before()
{
// Ensure we are in the install.php file.
if (!defined('MG_INSTALL') or MG_INSTALL !== TRUE) {
throw HTTP_Exception::factory(404, 'File not found!');
}
}