本文整理汇总了PHP中Session::checkToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::checkToken方法的具体用法?PHP Session::checkToken怎么用?PHP Session::checkToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::checkToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: featured
/**
* Method to toggle the featured setting of a list of articles.
*
* @return void
* @since 1.6
*/
function featured()
{
// Check for request forgeries
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// Initialise variables.
$ids = Request::getVar('cid', array(), '', 'array');
$values = array('featured' => 1, 'unfeatured' => 0);
$task = $this->getTask();
$value = \Hubzero\Utility\Arr::getValue($values, $task, 0, 'int');
// Access checks.
foreach ($ids as $i => $id) {
if (!$user->authorise('core.edit.state', 'com_content.article.' . (int) $id)) {
// Prune items that you can't change.
unset($ids[$i]);
Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
Notify::error(Lang::txt('JERROR_NO_ITEMS_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Publish the items.
if (!$model->featured($ids, $value)) {
throw new Exception($model->getError(), 500);
}
}
$this->setRedirect('index.php?option=com_content&view=articles');
}
示例2: setDefault
/**
* Method to set the home property for a list of items
*
* @since 1.6
*/
function setDefault()
{
// Check for request forgeries
Session::checkToken('request') or die(Lang::txt('JINVALID_TOKEN'));
// Get items to publish from the request.
$cid = Request::getVar('cid', array(), '', 'array');
$data = array('setDefault' => 1, 'unsetDefault' => 0);
$task = $this->getTask();
$value = \Hubzero\Utility\Arr::getValue($data, $task, 0, 'int');
if (empty($cid)) {
throw new Exception(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED'), 500);
} else {
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
\Hubzero\Utility\Arr::toInteger($cid);
// Publish the items.
if (!$model->setHome($cid, $value)) {
throw new Exception($model->getError(), 500);
} else {
if ($value == 1) {
$ntext = 'COM_MENUS_ITEMS_SET_HOME';
} else {
$ntext = 'COM_MENUS_ITEMS_UNSET_HOME';
}
$this->setMessage(Lang::txts($ntext, count($cid)));
}
}
$this->setRedirect(Route::url('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}
示例3: delete
/**
* Removes an item
*/
function delete()
{
// Check for request forgeries
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// Initialise variables.
$ids = Request::getVar('cid', array(), '', 'array');
// Access checks.
foreach ($ids as $i => $id) {
if (!User::authorise('core.delete', 'com_content.article.' . (int) $id)) {
// Prune items that you can't delete.
unset($ids[$i]);
Notify::warning(Lang::txt('JERROR_CORE_DELETE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
Notify::error(Lang::txt('JERROR_NO_ITEMS_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Remove the items.
if (!$model->featured($ids, 0)) {
throw new Exception($model->getError(), 500);
}
}
$this->setRedirect('index.php?option=com_content&view=featured');
}
示例4: remind
/**
* Method to request a username reminder.
*
* @since 1.6
*/
public function remind()
{
// Check the request token.
Session::checkToken('post') or exit(Lang::txt('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$model = $this->getModel('Remind', 'UsersModel');
$data = Request::getVar('jform', array(), 'post', 'array');
// Submit the password reset request.
$return = $model->processRemindRequest($data);
// Check for a hard error.
if ($return == false) {
// The request failed.
// Get the route to the next page.
$itemid = UsersHelperRoute::getRemindRoute();
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
$route = 'index.php?option=com_users&view=remind' . $itemid;
// Go back to the request form.
$message = Lang::txt('COM_USERS_REMIND_REQUEST_FAILED', $model->getError());
$this->setRedirect(Route::url($route, false), $message, 'warning');
return false;
} else {
// The request succeeded.
// Get the route to the next page.
$itemid = UsersHelperRoute::getRemindRoute();
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
$route = 'index.php?option=com_users&view=login' . $itemid;
// Proceed to step two.
$message = Lang::txt('COM_USERS_REMIND_REQUEST_SUCCESS');
$this->setRedirect(Route::url($route, false), $message);
return true;
}
}
示例5: batch
/**
* Method to run batch operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 2.5
*/
public function batch($model = null)
{
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// Set the model
$model = $this->getModel('Newsfeed', '', array());
// Preset the redirect
$this->setRedirect(Route::url('index.php?option=com_newsfeeds&view=newsfeeds' . $this->getRedirectToListAppend(), false));
return parent::batch($model);
}
示例6: rebuild
/**
* Rebuild the menu tree.
*
* @return bool False on failure or error, true on success.
*/
public function rebuild()
{
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
$this->setRedirect('index.php?option=com_menus&view=menus');
// Initialise variables.
$model = $this->getModel('Item');
if ($model->rebuild()) {
// Reorder succeeded.
$this->setMessage(Lang::txt('JTOOLBAR_REBUILD_SUCCESS'));
return true;
} else {
// Rebuild failed.
$this->setMessage(Lang::txt('JTOOLBAR_REBUILD_FAILED', $model->getMessage()));
return false;
}
}
示例7: setDefault
/**
* task to set the default language
*/
function setDefault()
{
// Check for request forgeries
Session::checkToken() or exit(Lang::txt('JInvalid_Token'));
$cid = Request::getCmd('cid', '');
$model = $this->getModel('installed');
if ($model->publish($cid)) {
$msg = Lang::txt('COM_LANGUAGES_MSG_DEFAULT_LANGUAGE_SAVED');
$type = 'message';
} else {
$msg = $this->getError();
$type = 'error';
}
$client = $model->getClient();
$clientId = $model->getState('filter.client_id');
$this->setredirect('index.php?option=com_languages&view=installed&client=' . $clientId, $msg, $type);
}
示例8: duplicate
/**
* Method to clone an existing module.
* @since 1.6
*/
public function duplicate()
{
// Check for request forgeries
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// Initialise variables.
$pks = Request::getVar('cid', array(), 'post', 'array');
\Hubzero\Utility\Arr::toInteger($pks);
try {
if (empty($pks)) {
throw new Exception(Lang::txt('COM_MODULES_ERROR_NO_MODULES_SELECTED'));
}
$model = $this->getModel();
$model->duplicate($pks);
$this->setMessage(Lang::txts('COM_MODULES_N_MODULES_DUPLICATED', count($pks)));
} catch (Exception $e) {
Notify::error($e->getMessage());
}
$this->setRedirect(Route::url('index.php?option=com_modules&view=modules', false));
}
示例9: delete
/**
* Method for deleting one or more overrides
*
* @return void
*
* @since 2.5
*/
public function delete()
{
// Check for request forgeries
Session::checkToken() or die(Lang::txt('JINVALID_TOKEN'));
// Get items to dlete from the request
$cid = Request::getVar('cid', array(), '', 'array');
if (!is_array($cid) || count($cid) < 1) {
$this->setMessage(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED'), 'warning');
} else {
// Get the model
$model = $this->getModel('overrides');
// Remove the items
if ($model->delete($cid)) {
$this->setMessage(Lang::txts($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
} else {
$this->setMessage($model->getError());
}
}
$this->setRedirect(Route::url('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}
示例10: unsetDefault
/**
* Method to unset the default template for a client and for a language
*
* @since 1.6
*/
public function unsetDefault()
{
// Check for request forgeries
Session::checkToken('request') or exit(Lang::txt('JINVALID_TOKEN'));
// Initialise variables.
$pks = Request::getVar('cid', array(), 'get', 'array');
\Hubzero\Utility\Arr::toInteger($pks);
try {
if (empty($pks)) {
throw new Exception(Lang::txt('COM_TEMPLATES_NO_TEMPLATE_SELECTED'));
}
// Pop off the first element.
$id = array_shift($pks);
$model = $this->getModel();
$model->unsetHome($id);
$this->setMessage(Lang::txt('COM_TEMPLATES_SUCCESS_HOME_UNSET'));
} catch (Exception $e) {
Notify::error(500, $e->getMessage());
}
$this->setRedirect('index.php?option=com_templates&view=styles');
}
示例11: delete
/** Deletes and returns correctly.
*
* @return void
* @since 2.5.12
*/
public function delete()
{
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = Request::getVar('cid', array(), '', 'array');
$extension = Request::getVar('extension', null);
if (!is_array($cid) || count($cid) < 1) {
Notify::error(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
\Hubzero\Utility\Arr::toInteger($cid);
// Remove the items.
if ($model->delete($cid)) {
$this->setMessage(Lang::txts($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
} else {
$this->setMessage($model->getError());
}
}
$this->setRedirect(Route::url('index.php?option=' . $this->option . '&extension=' . $extension, false));
}
示例12: delete
/**
* Method to remove a record.
*/
public function delete()
{
// Check for request forgeries.
Session::checkToken() or exit(Lang::txt('JInvalid_Token'));
// Initialise variables.
$ids = Request::getVar('cid', array(), '', 'array');
if (!User::authorise('core.admin', $this->option)) {
throw new Exception(Lang::txt('JERROR_ALERTNOAUTHOR'), 403);
} elseif (empty($ids)) {
throw new Exception(Lang::txt('COM_USERS_NO_LEVELS_SELECTED'), 500);
} else {
// Get the model.
$model = $this->getModel();
\Hubzero\Utility\Arr::toInteger($ids);
// Remove the items.
if (!$model->delete($ids)) {
throw new Exception($model->getError(), 500);
} else {
$this->setMessage(Lang::txts('COM_USERS_N_LEVELS_DELETED', count($ids)));
}
}
$this->setRedirect('index.php?option=com_users&view=levels');
}
示例13: resend
/**
* Method to login a user.
*
* @since 1.6
*/
public function resend()
{
// Check for request forgeries
Session::checkToken('post');
}
示例14: complete
/**
* Method to complete the password reset process.
*
* @since 1.6
*/
public function complete()
{
// Check for request forgeries
Session::checkToken('post') or exit(Lang::txt('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$model = $this->getModel('Reset', 'UsersModel');
$data = Request::getVar('jform', array(), 'post', 'array');
// Complete the password reset request.
$return = $model->processResetComplete($data);
// Check for a hard error.
if ($return instanceof Exception) {
// Get the error message to display.
if ($app->getCfg('error_reporting')) {
$message = $return->getMessage();
} else {
$message = Lang::txt('COM_USERS_RESET_COMPLETE_ERROR');
}
// Get the route to the next page.
$itemid = UsersHelperRoute::getResetRoute();
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
$route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid;
// Go back to the complete form.
$this->setRedirect(Route::url($route, false), $message, 'error');
return false;
} elseif ($return === false) {
// Complete failed.
// Get the route to the next page.
$itemid = UsersHelperRoute::getResetRoute();
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
$route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid;
// Go back to the complete form.
$message = Lang::txt('COM_USERS_RESET_COMPLETE_FAILED', $model->getError());
$this->setRedirect(Route::url($route, false), $message, 'error');
return false;
} else {
// Complete succeeded.
// Get the route to the next page.
$itemid = UsersHelperRoute::getLoginRoute();
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
$route = 'index.php?option=com_users&view=login' . $itemid;
// Proceed to the login form.
$message = Lang::txt('COM_USERS_RESET_COMPLETE_SUCCESS');
$this->setRedirect(Route::url($route, false), $message);
return true;
}
}
示例15: register
/**
* Method to register a user.
*
* @return boolean True on success, false on failure.
* @since 1.6
*/
public function register()
{
App::abort(403, Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
return false;
// Check for request forgeries.
Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN'));
// If registration is disabled - Redirect to login page.
if (Component::params('com_users')->get('allowUserRegistration') == 0) {
$this->setRedirect(Route::url('index.php?option=com_users&view=login', false));
return false;
}
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('Registration', 'UsersModel');
// Get the user data.
$requestData = Request::getVar('jform', array(), 'post', 'array');
// Validate the posted data.
$form = $model->getForm();
if (!$form) {
App::abort(500, $model->getError());
return false;
}
$data = $model->validate($form, $requestData);
// Check for validation errors.
if ($data === false) {
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
if ($errors[$i] instanceof Exception) {
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
} else {
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState('com_users.registration.data', $requestData);
// Redirect back to the registration screen.
$this->setRedirect(Route::url('index.php?option=com_users&view=registration', false));
return false;
}
// Attempt to save the data.
$return = $model->register($data);
// Check for errors.
if ($return === false) {
// Save the data in the session.
$app->setUserState('com_users.registration.data', $data);
// Redirect back to the edit screen.
$this->setMessage($model->getError(), 'warning');
$this->setRedirect(Route::url('index.php?option=com_users&view=registration', false));
return false;
}
// Flush the data from the session.
$app->setUserState('com_users.registration.data', null);
// Redirect to the profile screen.
if ($return === 'adminactivate') {
$this->setMessage(Lang::txt('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
$this->setRedirect(Route::url('index.php?option=com_users&view=registration&layout=complete', false));
} elseif ($return === 'useractivate') {
$this->setMessage(Lang::txt('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
$this->setRedirect(Route::url('index.php?option=com_users&view=registration&layout=complete', false));
} else {
$this->setMessage(Lang::txt('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
$this->setRedirect(Route::url('index.php?option=com_users&view=login', false));
}
return true;
}