Exemplo n.º 1
0
 /**
  * @return User
  */
 public function getUser()
 {
     if ($this->user === null) {
         $this->user = Environment::getUser();
     }
     return $this->user;
 }
Exemplo n.º 2
0
 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;
     }
 }
Exemplo n.º 3
0
 public function handleLogout()
 {
     $user = Environment::getUser();
     // odhlášení
     $user->signOut();
     $this->redirect(':Front:Default:');
 }
Exemplo n.º 4
0
 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();
         }
     }
 }
Exemplo n.º 5
0
 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';
 }
Exemplo n.º 6
0
 public function startup()
 {
     parent::startup();
     $user = Environment::getUser();
     if ($user->isAuthenticated()) {
         $roles = Environment::getUser()->getIdentity()->getRoles();
         $role = $roles[0];
         $this->redirect(":{$role}:Default:default");
     }
 }
Exemplo n.º 7
0
 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:');
     }
 }
Exemplo n.º 8
0
 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());
     }
 }
Exemplo n.º 9
0
 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'));
 }
Exemplo n.º 10
0
 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;
     }
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 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');
     }
 }
Exemplo n.º 13
0
 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;
     }
 }
Exemplo n.º 14
0
 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');
             }
         }
     }
 }
Exemplo n.º 15
0
 public function actionLogout()
 {
     Environment::getUser()->signOut();
     $this->flashMessage('You have been logged off.');
     $this->redirect('Auth:login');
 }
Exemplo n.º 16
0
 public function handleLogout()
 {
     Environment::getUser()->signOut();
     $this->flashMessage('You have been logged off.');
     $this->redirect(':Default:Select:default');
 }
Exemplo n.º 17
0
 /**
  * @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');
     }
 }
Exemplo n.º 18
0
 /**
  * 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);
 }
Exemplo n.º 19
0
 protected function beforeRender()
 {
     $user = Environment::getUser();
     $this->template->user = $user->isAuthenticated() ? $user->getIdentity() : NULL;
 }
Exemplo n.º 20
0
 /**
  * @return User
  */
 protected function getUser()
 {
     return Environment::getUser();
 }
Exemplo n.º 21
0
 /**
  * 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;
     }
 }
Exemplo n.º 22
0
 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();
 }
Exemplo n.º 23
0
 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');
 }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
         $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]);
         }
     }
Exemplo n.º 26
0
 public function startup()
 {
     parent::startup();
     $this->teacher = Environment::getUser()->getIdentity();
 }