/** * @return User */ public function getUser() { if ($this->user === null) { $this->user = Environment::getUser(); } return $this->user; }
public function beforeRender() { $filters = $this->getUniqueValues(array('works' => array('year', 'award', 'type'), 'authors' => array('class'))); $temp = $filters['authors']; unset($filters['authors']); //$filters['works']['category'] = Model::palicky();// + array(5=>'palice'); // 'category'=>'Kategorie', $filters['works']['grade'] = Model::rocniky(); $filters['palicka']['category'] = Model::palicky(); $filters['authors'] = $temp; //{link :Front:Default:works "category"=>palicka} $this->template->filters = $filters; $this->template->schoolYear = Model::getSchoolYear(); $newest = dibi::query('SELECT url, title, CONCAT_WS(" ", name, surname) as authorName FROM [works] join [authors] on author = authorId', 'ORDER BY %by', array('added' => 'desc'), 'LIMIT %i', 2)->fetchAll(); $this->template->newest = $newest; $mostread = dibi::query('SELECT url, title, CONCAT_WS(" ", name, surname) as authorName FROM [works] join [authors] on author = authorId', 'ORDER BY %by', array('read' => 'desc'), 'LIMIT %i', 3)->fetchAll(); $this->template->mostread = $mostread; $user = Environment::getUser(); if ($user->isLoggedIn()) { $this->template->adminMode = true; } }
public function handleLogout() { $user = Environment::getUser(); // odhlášení $user->signOut(); $this->redirect(':Front:Default:'); }
public function formLoginAjaxSubmitted($form) { $values = $form->getValues(); if ($form->isValid()) { $login = $values['login']; $password = $values['password']; $user = Environment::getUser(); $user->setAuthenticationHandler(new Admin_UserModel()); try { $user->authenticate($login, $password); $session_conf = Environment::getVariable('session'); $user->setExpiration($session_conf['expiration'], true); //$session = $this->getSession('backlink'); //$session->in_application = true; //$this->getApplication()->restoreRequest($session['backlink']); //$this->redirect('Dashboard:default'); $this->payload->cmds = array(); $this->payload->cmds[] = 'login_ok'; $this->flash('Login OK'); if ($this->isAjax()) { $this->sendPayload(); $this->terminate(); } } catch (AuthenticationException $e) { $form->setValues($values); $this->invalidateControl('frmLogin'); if ($this->isAjax()) { $this->invalidateControl('formLoginAjax'); } //$this->flash('Error: '. $e->getMessage()); $this->payload->error = $e - getMessage(); } } }
public function actionDefault() { if (Environment::getUser()->getIdentity()->role == 'super admin') { $this->config_data = ConfigAdapterIni::load(APP_DIR . '/config/admin.ini', 'admin'); $this->profile_data = $this->config_data['admin']; $this->mode = 'superadmin'; } $this->view = 'profile'; }
public function startup() { parent::startup(); $user = Environment::getUser(); if ($user->isAuthenticated()) { $roles = Environment::getUser()->getIdentity()->getRoles(); $role = $roles[0]; $this->redirect(":{$role}:Default:default"); } }
protected function startup() { parent::startup(); $this->model = new Model(); $this->fileModel = new FileModel(); $user = Environment::getUser(); if (!$user->isLoggedIn()) { // je uživatel přihlášen? $this->redirect(':Admin:Login:'); } }
public function loginFormSubmitted($form) { try { $user = Environment::getUser(); $user->authenticate($form['username']->getValue(), $form['password']->getValue()); $this->getApplication()->restoreRequest($this->backlink); $this->redirect('Dashboard:'); } catch (AuthenticationException $e) { $form->addError($e->getMessage()); } }
public function beforeRender() { // curly brackets $this->template->registerFilter('Nette\\Templates\\CurlyBracketsFilter::invoke'); // texy $texy = new Texy(); $this->template->registerHelper('texy', array($texy, 'process')); // user $this->template->user = Environment::getUser(); // order statuses $this->template->order_statuses = mapper::order_statuses()->findAll(); // date $this->template->registerHelper('date', array(__CLASS__, 'date')); }
public function onLoginFormSubmit(Form $form) { $user = Environment::getUser(); $user->setAuthenticationHandler(new SimpleAuthenticator(array(ADMIN_USERNAME => ADMIN_PASSWORD))); $values = $form->getValues(); try { $user->authenticate($values['username'], $values['password']); adminlog::log(__('Successfully logged in as "%s"'), Environment::getUser()->getIdentity()->getName()); $this->redirect('Dashboard:default'); $this->terminate(); } catch (AuthenticationException $e) { adminlog::log(__('Unsuccessful log in (username: "******", password: "******")'), $values['username'], $values['password']); $this->template->error = $e; } }
private function login($username, $password) { $user = Environment::getUser(); if (!$user->isAuthenticated()) { $user->setAuthenticationHandler(new Admin_UserModel()); try { $user->authenticate($username, $password); $session_conf = Environment::getVariable('session'); $user->setExpiration($session_conf['expiration'], true); return $user; } catch (AuthenticationException $e) { $this->error = new IXR_Error(403, $e->getMessage()); return false; } } return $user; }
private function checkAuthorization() { $presenter = String::lower($this->getReflection()->getName()); $user = Environment::getUser(); $user->setAuthorizationHandler(MokujiServiceLocator::getService('UserAuthorizator')); //if(Environment::getServiceLocator()->hasService('UserAuthorizator')) $user->setAuthorizationHandler(Environment::getService('UserAuthorizator')); //else $user->setAuthorizationHandler(new Admin_UserModel()); if ($this->formatActionMethod($this->action) == 'actiondeny') { return; } if ($user->isAllowed($presenter, $this->formatActionMethod($this->action)) === true) { if ($user->isAllowed($presenter, $this->formatSignalMethod($this->signal)) === false) { throw new AuthenticationException('This action is not allowed'); } } else { throw new AuthenticationException('This action is not allowed'); } }
public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL) { if ($privilege == 'actionDeny') { return true; } $data = Environment::getUser()->getIdentity()->permissions; if (isset($data[String::lower($resource)])) { if ($privilege == null) { return true; } foreach ($data[String::lower($resource)] as $user_privilege) { if (String::lower($privilege) == String::lower($user_privilege)) { return true; } } return false; } else { return false; } }
public function formLoginSubmitted($form) { $modul = explode(':', $this->getName()); $module = $modul[0]; $user = Environment::getUser(); $user->setAuthenticationHandler(new Authenticator()); $values = $form->getValues(); if ($form->isValid()) { $email = $values['email']; $password = $values['password']; try { $user->authenticate($email, $password, $module); $user->setExpiration('+ 30 minutes'); $this->redirect(":{$module}:default:default"); } catch (AuthenticationException $e) { $this->flashMessage('Error: ' . $e->getMessage(), 'error'); $this->invalidateControl('flash'); if (!$this->isAjax()) { $this->redirect('this'); } } } }
public function actionLogout() { Environment::getUser()->signOut(); $this->flashMessage('You have been logged off.'); $this->redirect('Auth:login'); }
public function handleLogout() { Environment::getUser()->signOut(); $this->flashMessage('You have been logged off.'); $this->redirect(':Default:Select:default'); }
/** * @param Form $form */ public function onLoginSubmitted(Form $form) { try { $values = $form->getValues(); $username = $values['user']; if ($username == '__guest') { $this->user->logout(TRUE); } else { $password = $this->credentials[$username]; Environment::getUser()->login($username, $password); } $this->redirect('this'); } catch (AuthenticationException $e) { Environment::getApplication()->presenter->flashMessage($e->getMessage(), 'error'); $this->redirect('this'); } }
/** * support for @http://forum.nette.org/cs/1231-2009-01-21-sikovnejsi-permission */ public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL) { // set roleId to currently logged user's id for later assertions $roleClassName = ucfirst($role) . "Role"; if (class_exists($roleClassName)) { $userId = intval(Environment::getUser()->getIdentity()->data['id']); $role = new $roleClassName($userId); } return parent::isAllowed($role, $resource, $privilege); }
protected function beforeRender() { $user = Environment::getUser(); $this->template->user = $user->isAuthenticated() ? $user->getIdentity() : NULL; }
/** * @return User */ protected function getUser() { return Environment::getUser(); }
/** * updates identity data, call after each possible data change * * @param array $data */ public static function updateIdentity($data) { foreach ($data as $col => $value) { Environment::getUser()->getIdentity()->{$col} = $value; } }
public function onChangeLoginFormSubmit(Form $form) { if (!$form->isValid()) { return; } if ($form['old_password']->getValue() !== Environment::expand('%adminPassword%')) { $form->addError(__('Bad old password.')); return; } $content = "<?php\nreturn " . var_export(array('username' => $form['username']->getValue(), 'password' => $form['new_password']->getValue()), TRUE) . ";\n"; if (!@file_put_contents(Environment::expand('%adminLoginFile%'), $content)) { $form->addError(__('Cannot write new login settings.')); return; } Environment::getUser()->signOut(TRUE); adminlog::log(__('Changed login credentials, logging out')); $this->redirect('this'); $this->terminate(); }
public function handleLogout() { Environment::getUser()->signOut(); $session = $this->getSession('backlink'); $session['backlink'] = null; $this->flashMessage('You have been logged off because: ' . Environment::getUser()->getSignOutReason()); $this->redirect(':Admin:Login:default'); }
public static function isAllowed($resource, $privilege, $userId) { if (Environment::getUser()->isAllowed($resource, $privilege)) { return true; } if (Environment::getUser()->getIdentity()->id == $userId) { return true; } return false; }
$factory_name = 'createComponent' . String::capitalize($name); return $this->{$factory_name}($name); } catch (MemberAccessException $e) { if (class_exists($name)) { return new $name($this, $name); } else { return new DummyComponent($this, $name, 'Component with name "' . $name . '" does not exist.'); } } } public function beforeRender() { $this->template->user = Environment::getUser(); $this->translator = new Translator($this->lang); $this->template->setTranslator($this->translator); $this->template->website = Environment::getVariable('website'); $this->template->domain = 'http://' . Environment::getVariable('website'); $this->template->keywords = Environment::getVariable('keywords'); $this->template->description = Environment::getVariable('description'); $this->data->content = $this->compileTemplate($this->data->content); $this->data->css_files = explode(" ", $this->data->css_files); foreach ($this->data->css_files as $key => $file) { if ($file == '') { unset($this->data->css_files[$key]); } }
public function startup() { parent::startup(); $this->teacher = Environment::getUser()->getIdentity(); }