本文整理汇总了PHP中App::session方法的典型用法代码示例。如果您正苦于以下问题:PHP App::session方法的具体用法?PHP App::session怎么用?PHP App::session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->session = \App::session();
// Get user defined locale
$this->currentLocale = $this->getCurrentLocale();
$this->cachePath = CACHE_PATH . 'locale';
}
示例2: getFilters
/**
* Get the user filters
*
* @return array The user filters
*/
public function getFilters()
{
if (App::request()->getHeaders('X-List-Filter')) {
App::session()->getUser()->setOption('admin.user-filter', App::request()->getHeaders('X-List-Filter'));
}
return json_decode(App::session()->getUser()->getOptions('admin.user-filter'), true);
}
示例3: baseCondition
public static function baseCondition()
{
$bid = \App::session('bid', 'adm');
if (!$bid) {
return '';
}
return "bid={$bid}";
}
示例4: captcha
protected function captcha(array $option)
{
$session = \App::session();
if (isset($option['value']) && $session->has('captcha') && strtoupper($session->get('captcha')) == strtoupper($option['value'])) {
return true;
}
$this->error[] = _s('The security code is not correct');
return false;
}
示例5: verifyCaptcha
function verifyCaptcha($value)
{
$sess_verify = \App::session('verify');
$sess_verify_time = \App::session('verify_time');
if (empty($sess_verify) || empty($sess_verify_time)) {
return [0, '已失效'];
}
if (time() > $sess_verify_time + 60) {
return [0, '已过期'];
}
if (md5(strtolower($value)) != $sess_verify) {
return [0, '错误'];
}
return true;
}
示例6: __construct
public function __construct(array $option)
{
$this->session = \App::session();
$this->form = $option;
if (!isset($this->form['name'])) {
$this->form['name'] = 'form';
}
if (isset($option['method']) && $option['method'] == 'get') {
$this->form['method'] = 'get';
$this->input = filter_input_array(INPUT_GET);
} else {
$this->form['method'] = 'post';
$this->input = filter_input_array(INPUT_POST);
}
$this->successMessage = _s('Data saved successfully');
$this->errorMessage = _s('Errors occurred');
}
示例7: edit
/**
* Create or edit an user
*/
public function edit()
{
$roles = array_map(function ($role) {
return $role->getLabel();
}, Role::getAll('id'));
$user = User::getByUsername($this->username);
$param = array('id' => 'user-form', 'upload' => true, 'model' => 'User', 'reference' => array('username' => $this->username), 'fieldsets' => array('general' => array('nofieldset' => true, new TextInput(array('name' => 'username', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id === App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-username-label'))), new EmailInput(array('name' => 'email', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id !== App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-email-label'))), new CheckboxInput(array('name' => 'active', 'label' => Lang::get($this->_plugin . '.user-form-active-label'))), new SelectInput(array('name' => 'roleId', 'options' => $roles, 'label' => Lang::get($this->_plugin . '.user-form-roleId-label'))), $user ? null : new PasswordInput(array('name' => 'password', 'required' => true, 'label' => Lang::get($this->_plugin . '.user-form-password-label'), 'encrypt' => array('Hawk\\Crypto', 'saltHash'))), $user ? null : new PasswordInput(array('name' => 'passagain', 'label' => Lang::get($this->_plugin . '.user-form-passagain-label'), 'required' => true, 'compare' => 'password', 'independant' => true)), new HiddenInput(array('name' => 'createTime', 'default' => time()))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => !($user && $user->isRemovable()))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.lists["admin-users-list"].refresh();');
$form = new Form($param);
if (!$form->submitted()) {
return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('page' => $form, 'title' => Lang::get($this->_plugin . '.user-form-title'), 'icon' => 'user'));
} else {
if ($form->submitted() == "delete") {
$this->remove();
} else {
if ($form->check()) {
return $form->register();
}
}
}
}
示例8: loginAction
/**
* 登录页面
*
* @return \Core\Http\Response
*/
public function loginAction()
{
if ($this->adminId > 0) {
return $this->goHome();
}
$session = \App::session();
if ($this->request->isMethod('post')) {
$userName = $this->getPost('username');
$password = $this->getPost('password');
$remember = $this->getPost('remember', 0);
$adminInfo = AdminModel::getInstance()->getAdminByName($userName);
if ($adminInfo && $adminInfo['password'] == md5($password . $adminInfo['salt'])) {
$this->setLoginAuth($adminInfo['id'], $adminInfo['password'], $remember);
AdminModel::getInstance()->updateAdmin($adminInfo['id'], array('last_login' => NOW, 'last_ip' => $this->request->getClientIp()));
return $this->redirect(URL('main/index'));
}
$session->setFlash('error', '帐号或密码错误');
}
$this->assign(['error' => $session->getFlash('error')]);
return $this->display();
}
示例9: getAvailableItems
/**
* Get the items available for a specific user
*
* @param User $user The user. If not set, the current session user is set
*
* @return array The list of items
*/
public static function getAvailableItems($user = null)
{
if ($user == null) {
$user = App::session()->getUser();
}
// Get all items
$items = self::getListByExample(new DBExample(array('active' => 1)), self::$primaryColumn, array(), array('parentId' => 'ASC', 'order' => 'ASC'));
// Filter unavailable items (that are not active or not accessible)
$items = array_filter($items, function ($item) use($user) {
return $item->isVisible($user);
});
// Put the sub items under their parent item
foreach ($items as $item) {
if ($item->parentId) {
$items[$item->parentId]->visibleItems[$item->order] = $item;
unset($items[$item->id]);
}
}
$items = array_values($items);
foreach ($items as $item) {
$item->visibleItems = array_values($item->visibleItems);
}
return $items;
}
示例10: testSession
/**
* @covers \Phix\App::session
*/
public function testSession()
{
$app = new App();
$this->assertNull($app->session('foo'));
$app->session('foo', 'bar');
$this->assertSame('bar', $app->session('foo'));
$app->session('foo', null);
$this->assertArrayNotHasKey('foo', $_SESSION);
$ret = $app->session('foo', function () {
return array('bar', 'baz');
});
$this->assertSame(array('bar', 'baz'), $app->session('foo'));
$this->assertEquals($ret, $app);
}
示例11: resetPassword
/**
* Display and treat the form to reset the user's password
*/
public function resetPassword()
{
$form = new Form(array('id' => 'reset-password-form', 'fieldsets' => array('form' => array(new TextInput(array('name' => 'code', 'required' => true, 'label' => Lang::get($this->_plugin . '.reset-pwd-form-code-label'))), new PasswordInput(array('name' => 'password', 'required' => true, 'label' => Lang::get($this->_plugin . '.reset-pwd-form-password-label'), 'encrypt' => array('\\Hawk\\Crypto', 'saltHash'))), new PasswordInput(array('name' => 'confirmation', 'required' => true, 'compare' => 'password', 'label' => Lang::get($this->_plugin . '.reset-pwd-form-confirmation-label')))), 'submits' => array(new SubmitInput(array('name' => 'valid', 'label' => Lang::get($this->_plugin . '.valid-button'))), new ButtonInput(array('name' => 'cancel', 'label' => Lang::get($this->_plugin . '.cancel-button'), 'href' => App::router()->getUri('login'), 'target' => 'dialog')))), 'onsuccess' => 'app.dialog(app.getUri("login"));'));
if (!$form->submitted()) {
return Dialogbox::make(array('title' => Lang::get($this->_plugin . '.reset-pwd-form-title'), 'icon' => 'lock-alt', 'page' => $form));
} else {
if ($form->check()) {
// Check the verficiation code
if ($form->getData('code') !== Crypto::aes256Decode(App::session()->getData('forgottenPassword.code'))) {
$form->error('code', Lang::get($this->_plugin . '.reset-pwd-form-bad-verification-code'));
return $form->response(Form::STATUS_CHECK_ERROR);
}
try {
$user = User::getByEmail(App::session()->getData('forgottenPassword.email'));
if ($user) {
$user->set('password', $form->inputs['password']->dbvalue());
$user->save();
} else {
return $form->response(Form::STATUS_ERROR, App::session()->getData('forgottenPassword.email'));
}
return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.reset-pwd-form-success'));
} catch (\Exception $e) {
return $form->response(Form::STATUS_ERROR, Lang::get($this->_plugin . '.reset-pwd-form-error'));
}
}
}
}
示例12: route
/**
* Compute the routing, and execute the controller method associated to the URI
*/
public function route()
{
$path = str_replace(BASE_PATH, '', parse_url(App::request()->getUri(), PHP_URL_PATH));
// Scan each row
foreach ($this->routes as $route) {
if ($route->match($path)) {
// The URI matches with the route
$this->currentRoute =& $route;
// Check if the route is accessible with the current method
if (!$route->isCallableBy(App::request()->getMethod())) {
throw new BadMethodException($route->url, App::request()->getMethod());
}
// Emit an event, saying the routing action is finished
$event = new Event('after-routing', array('route' => $route));
$event->trigger();
$route = $event->getData('route');
if (!$route->isAccessible()) {
// The route is not accessible
App::logger()->warning(sprintf('A user with the IP address %s tried to access %s without the necessary privileges', App::request()->clientIp(), App::request()->getUri()));
if (!App::session()->isLogged()) {
throw new UnauthorizedException();
} else {
throw new ForbiddenException();
}
}
// The route authentications are validated
list($classname, $method) = explode(".", $route->action);
// call a controller method
$this->currentController = $classname::getInstance($route->getData());
App::logger()->debug(sprintf('URI %s has been routed => %s::%s', App::request()->getUri(), $classname, $method));
// Set the controller result to the HTTP response
App::response()->setBody($this->currentController->{$method}());
return;
}
}
App::logger()->warning('The URI ' . App::request()->getUri() . ' has not been routed');
throw new PageNotFoundException();
}
示例13: array
App::router()->get('delete-plugin', 'plugins/{plugin}/remove', array('where' => array('plugin' => Plugin::NAME_PATTERN), 'action' => 'PluginController.delete'));
// Create a new plugin structure
App::router()->any('create-plugin', 'plugins/_new', array('action' => 'PluginController.create'));
// Update a plugin
App::router()->get('update-plugin', 'plugins/{plugin}/update', array('where' => array('plugin' => Plugin::NAME_PATTERN), 'action' => 'PluginController.update'));
// Display number of updates in menu
if (App::session()->isAllowed('admin.all')) {
Event::on(\Hawk\Plugins\Main\MainController::EVENT_AFTER_GET_MENUS, function (Event $event) {
SearchUpdatesWidget::getInstance()->display();
});
}
});
/**
* Manage the languages and languages keys
*/
App::router()->auth(App::session()->isAllowed('admin.languages'), function () {
// list all the supported languages
App::router()->any('manage-languages', 'languages/', array('action' => 'LanguageController.index'));
App::router()->get('language-keys-list', 'languages/keys', array('action' => 'LanguageController.listKeys'));
// Save the translations
App::router()->post('save-language-keys', 'languages/keys/save', array('action' => 'LanguageController.editKeys'));
// Edit a language
App::router()->any('edit-language', 'languages/{tag}', array('where' => array('tag' => '[a-z]{2}|new'), 'action' => 'LanguageController.editLanguage'));
// Delete a language
App::router()->get('delete-language', 'languages/{tag}/delete', array('where' => array('tag' => '[a-z]{2}'), 'action' => 'LanguageController.deleteLanguage'));
// Add a language key
App::router()->post('add-language-key', 'languages/keys/add', array('action' => 'LanguageController.addKey'));
// Delete a translation
App::router()->any('delete-translation', 'languages/keys/{plugin}/{key}/{tag}/clean', array('where' => array('plugin' => '[\\w\\-]+', 'key' => '[\\w\\-]+', 'tag' => '[a-z]{2}'), 'action' => 'LanguageController.deleteTranslation'));
// Import language file
App::router()->any('import-language-keys', 'languages/import', array('action' => 'LanguageController.import'));
示例14: __construct
/**
* Constructor
*
* @param arary $params The parameter of the list
*/
public function __construct($params)
{
// Default values
$this->emptyMessage = Lang::get('main.list-no-result');
$this->action = getenv('REQUEST_URI');
$this->refresh = !!App::request()->getParams('refresh');
// Get the values from the parameters array
$this->map($params);
if ($this->data === null) {
if (!class_exists($this->model)) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$reflection = new \ReflectionClass($trace[1]['class']);
$this->model = $reflection->getNamespaceName() . '\\' . $this->model;
}
if ($this->model == self::DEFAULT_MODEL) {
if (!isset($this->table)) {
throw new \Exception('ItemList contructor expects property "table" or "model" to be set');
}
if (!isset($this->reference)) {
$this->reference = 'id';
}
} else {
$model = $this->model;
if (!isset($this->reference)) {
$this->reference = $model::getPrimaryColumn();
}
if (!isset($this->table)) {
$this->table = $model::getTable();
}
$this->dbname = $model::getDbName();
}
$this->refAlias = is_array($this->reference) ? reset($this->reference) : $this->reference;
$this->refField = is_array($this->reference) ? reset(array_keys($this->reference)) : $this->reference;
$this->dbo = DB::get($this->dbname);
}
// initialize controls
foreach ($this->controls as &$button) {
if (!empty($button['template'])) {
switch ($button['template']) {
case 'refresh':
$button = array('icon' => 'refresh', 'type' => 'button', 'onclick' => 'app.lists["' . $this->id . '"].refresh();');
break;
case 'print':
$button = array('icon' => 'print', 'type' => 'button', 'onclick' => 'app.lists["' . $this->id . '"].print();');
break;
}
}
}
// Get the filters sent by POST or registered in COOKIES
$parameters = array('searches', 'sorts', 'lines', 'page');
if (!$this->navigation) {
$this->lines = self::ALL_LINES;
}
if (App::request()->getHeaders('X-List-Filter-' . $this->id)) {
App::session()->getUser()->setOption('main.list-' . $this->id, App::request()->getHeaders('X-List-Filter-' . $this->id));
}
$this->userParam = json_decode(App::session()->getUser()->getOptions('main.list-' . $this->id), true);
foreach ($parameters as $name) {
if (!empty($this->userParam[$name])) {
$this->{$name} = $this->userParam[$name];
}
}
// initialize fields default values
foreach ($this->fields as $name => &$field) {
if (is_array($field)) {
$field = new ItemListField($name, $field, $this);
if (isset($this->searches[$name])) {
$field->searchValue = $this->searches[$name];
}
if (!empty($this->sorts[$name])) {
$field->sortValue = $this->sorts[$name];
}
} else {
unset($this->fields[$name]);
}
}
$event = new Event('list.' . $this->id . '.instanciated', array('list' => $this));
$event->trigger();
}
示例15: defined
<?php
/*
* mobiCMS Content Management System (http://mobicms.net)
*
* For copyright and license information, please see the LICENSE.md
* Installing the system or redistributions of files must retain the above copyright notice.
*
* @link http://mobicms.net mobiCMS Project
* @copyright Copyright (C) mobiCMS Community
* @license LICENSE.md (see attached file)
*/
defined('MOBICMS') or die('Error: restricted access');
//TODO: может удалить?
if (App::session()->has('ref')) {
App::session()->remove('ref');
}
App::view()->total_users = App::db()->query('SELECT COUNT(*) FROM `user__`')->fetchColumn();
App::view()->setTemplate('index.php');