public function action_view() { $uri = $this->request->detect_uri(); if ($uri == '') { $this->redirect(URL::to('page@view:home')); } $id = $this->request->param('id'); $query = $this->request->query(); $username = $this->request->post('username'); $password = $this->request->post('password'); $login = $this->request->post('login'); $identity = Identity::instance(); $info = ORM::factory('Page')->filter('alias', $id)->load(); if ($info->loaded()) { //downloads if ($id == 'download') { $downloads = true; } //contact if ($id == 'contact') { $form = Form::factory('Contact'); //$form = Form:: if ($form->valid()) { //var_dump($form->values()); $this->redirect(URL::to('page@view:contact') . '?form=sent'); } } else { $form = FALSE; } //login mechanism if (empty($username) && $login == 'Login') { $this->redirect(URL::current() . '?auth=nameError'); } elseif (empty($password) && $login == 'Login') { $this->redirect(URL::current() . '?auth=false'); } elseif (!empty($username) && !empty($password) && $login == 'Login') { $auth = $identity->authenticate($username, $password); if ($auth) { $this->redirect(URL::current()); } else { $this->redirect(URL::current() . '?auth=false'); } } //logout mechanism if ($login == 'Logout') { $identity->destroy(); $this->redirect(URL::current()); } $view = View::factory('page/item', array('item' => Viewer::factory($info), 'form' => $form, 'query' => $query, 'downloads' => isset($downloads) ? $downloads : null)); $this->response->body($view->render()); } else { throw HTTP_Exception::factory(404, 'Page not found'); } }
/** * update */ public function action_update() { // get model $model = Identity::instance()->user; // create form $form = Form::factory($this->_settings->get('form')); // add request to form $form->request($this->request); // add model to form $form->model($model); // add text to form $form->text(Text::instance()); // add urls $form->urls(array('submit' => URL::to($this->request->controller() . '@update'), 'back' => URL::to($this->request->controller()))); $form->user($model); // do the action if ($this->update($model, $form)) { //redirect $this->redirect_done('updated'); } }
/** * init */ public function init() { // raise event Event::raise($this, Event::BEFORE_INIT); // get website and feed it the current uri so we can figure out the ->id() $website = Website::instance()->uri(Request::initial()->uri()); // set controller vars $this->_website = $website->id(); $this->_directory = Request::current()->directory(); $this->_controller = Request::current()->controller(); $this->_action = Request::current()->action(); $this->_language = isset(Identity::instance()->user) ? Identity::instance()->user->language : 'nl'; // manually set website in Website // this will be used by alias Website::instance()->id($this->_website); // set state session // get state instance for this website / controller State::session(Session::instance('database')); $this->_state = State::instance($this->_website . '.' . $this->_controller); // set route in URL helper URL::route('backend'); // Let Filereader cache results Reader::cache(Cache::instance('reader_backend'), 'backend'); // set default language Text::language($this->_language); // get that language's text instance and configure it Text::instance($this->_language)->load(array_keys(Settings::factory('modules')->as_array()))->group($this->_controller)->substitutes('module'); // set URL presets $base = URL::base(); URL::set('base', $base); URL::set('library', $base . 'library/'); URL::set('vendor', $base . 'vendor/'); URL::set('files', $base . 'files/'); // set website in view View::set_global('_website', $this->_website); // set language in view View::set_global('_language', $this->_language); }
/** * copy * */ protected function copy($model) { // check rights if (!Acl::instance()->allowed($this->_controller, 'copy', $model->owner_id, $model->website_id)) { throw HTTP_Exception::factory(403, 'Copy not allowed on :controller :id', array(':controller' => $this->_controller, ':id' => $model->id)); } // create copied values $values = $model->as_array(); unset($values['id']); $values['title'] = 'Copy ' . $values['title']; $values['owner_id'] = Identity::instance()->id; $values['editor_id'] = Identity::instance()->id; // create copy $copy = ORM::factory($this->_settings->get('model')); $copy->values($values); // call hook Event::raise($this, Event::BEFORE_COPY, array('model' => $model, 'copy' => $copy)); // save copy $copy->save(); // call hook Event::raise($this, Event::AFTER_COPY, array('model' => $model, 'copy' => $copy)); // return copy return $copy; }
} ?> </ul> </li> <?php } ?> </ul> <ul class="nav navbar-nav navbar-right"> <!-- user options --> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <?php echo Identity::instance()->username; ?> <b class="caret"></b> </a> <ul class="dropdown-menu"> <li> <a href="<?php echo URL::to('Settings'); ?> "><?php echo text('section.settings'); ?> </a> </li> <li> <a href="<?php
/** * do logout and redirect to login */ public function action_logout() { $identity = Identity::instance(); $identity->destroy(); $url = URL::to('Auth@login'); $this->redirect($url, 302); }
/** * create files in db */ protected function store($form, $hash) { // get files in the temp/hash dir $files = FS::files($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR); // set the files in the form $form->files($files); Event::raise($this, Event::BEFORE_STORE_FORM_PARSE, array('form' => $form)); if ($form->valid()) { // get the hash of the temp dir from qs $hash = $this->request->param('id'); // get the form values $values = $form->values(); // loop through temp files for ($i = 0; $i < count($files); $i++) { // createmodel $model = ORM::factory($this->_settings->get('model')); // set group if one is active if ($group = $this->_state->get('group', FALSE)) { $model->group_id = $group; } // undouble filename $file = FS::name_unique($files[$i], $this->_settings->get('path_files')); // store it FS::move($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR . $files[$i], $this->_settings->get('path_files') . $file); // permissions FS::permissions($this->_settings->get('path_files') . $file, 0744); // set item properties $model->created = date('y-m-d H:i:s', time()); $model->owner_id = Identity::instance()->id; $model->editor_id = Identity::instance()->id; $model->website_id = $this->_website; // set file $model->file = $file; // set additional info (mostly title) foreach ($values as $key => $value) { if (is_array($value) && isset($value[$i])) { $model->{$key} = $value[$i]; } } // call hook Event::raise($this, Event::BEFORE_STORE, array('model' => $model, 'form' => $form)); //save $model->save(); // call hook Event::raise($this, Event::AFTER_STORE, array('model' => $model, 'form' => $form)); } // return true return TRUE; } else { // create viewer $viewer = Viewer::factory('Form', $form)->text(Text::instance()); // render form $view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer)); // event Event::raise($this, Event::BEFORE_STORE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view)); // render $this->response->body($view->render()); // return false return FALSE; } }
<?php $identity = Identity::instance(); //set error messages if ($message == 'nameError') { $message = 'Voer uw inlog gegevens in'; } elseif ($message == 'false') { $message = 'Onjuiste naam of wachtwoord'; } if (!$identity->authenticated()) { ?> <form method="post"> Inlognaam:<br> <input type="text" name="username"> <br> Wachtwoord: <br> <input type="password" name="password"> <?php echo '<br>' . $message; ?> <br><br> <input type="submit" name="login" value="Login"> </form> <?php } else { ?> <form method="post"> U bent ingelogd als: <br>