Example #1
0
 public function on_page_load()
 {
     $email_ctx_id = $this->get('email_id_ctx', 'email');
     $email = $this->_ctx->get($email_ctx_id);
     $referrer_page = Request::current()->referrer();
     $next_page = $this->get('next_url', Request::current()->referrer());
     if (!Valid::email($email)) {
         Messages::errors(__('Use a valid e-mail address.'));
         HTTP::redirect($referrer_page);
     }
     $user = ORM::factory('user', array('email' => $email));
     if (!$user->loaded()) {
         Messages::errors(__('No user found!'));
         HTTP::redirect($referrer_page);
     }
     $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE)));
     if (!$reflink) {
         Messages::errors(__('Reflink generate error'));
         HTTP::redirect($referrer_page);
     }
     Observer::notify('admin_login_forgot_before', $user);
     try {
         Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink));
         Messages::success(__('Email with reflink send to address set in your profile'));
     } catch (Exception $e) {
         Messages::error(__('Something went wrong'));
     }
     HTTP::redirect($next_page);
 }
Example #2
0
 /**
  * 
  * @param Datasource_Section $ds
  * @param Datasource_Document $doc
  */
 public function action_post()
 {
     $id = (int) $this->request->post('id');
     $doc = $this->_get_document($id);
     Session::instance()->set('post_data', $this->request->post());
     try {
         $doc->read_values($this->request->post())->read_files($_FILES)->validate();
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (DataSource_Exception_Document $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     if ($doc->loaded()) {
         $this->section()->update_document($doc);
     } else {
         $doc = $this->section()->create_document($doc);
     }
     Messages::success(__('Document saved'));
     Session::instance()->delete('post_data');
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'data')) . URL::query(array('ds_id' => $this->section()->id()), FALSE));
     } else {
         $this->go(Route::get('datasources')->uri(array('directory' => $this->section()->type(), 'controller' => 'document', 'action' => 'view')) . URL::query(array('ds_id' => $this->section()->id(), 'id' => $doc->id), FALSE));
     }
 }
Example #3
0
 public function action_index()
 {
     $code = $this->request->param('code');
     if ($code === NULL) {
         Model_Page_Front::not_found();
     }
     $reflink_model = ORM::factory('user_reflink', $code);
     if (!$reflink_model->loaded()) {
         Messages::errors(__('Reflink not found'));
         $this->go_home();
     }
     $next_url = Arr::get($reflink_model->data, 'next_url');
     try {
         Database::instance()->begin();
         Reflink::factory($reflink_model)->confirm();
         $reflink_model->delete();
         Database::instance()->commit();
     } catch (Kohana_Exception $e) {
         Database::instance()->rollback();
         Messages::errors($e->getMessage());
     }
     if (Valid::url($next_url)) {
         $this->go($next_url);
     }
     $this->go_home();
 }
Example #4
0
 private function _login()
 {
     $array = $this->request->post('login');
     $array = Validation::factory($array)->label('username', 'Username')->label('password', 'Password')->label('email', 'Email')->rules('username', array(array('not_empty')))->rules('password', array(array('not_empty')));
     $fieldname = Valid::email(Arr::get($array, 'username')) ? Auth::EMAIL : Auth::USERNAME;
     // Get the remember login option
     $remember = isset($array['remember']);
     Observer::notify('admin_login_validation', $array);
     if ($array->check()) {
         Observer::notify('admin_login_before', $array);
         if (Auth::instance()->login($array['username'], $array['password'], $remember)) {
             Observer::notify('admin_login_success', $array['username']);
             Session::instance()->delete('install_data');
             Kohana::$log->add(Log::INFO, ':user login')->write();
             if ($next_url = Flash::get('redirect')) {
                 $this->go($next_url);
             }
             // $this->go to defaut controller and action
             $this->go_backend();
         } else {
             Observer::notify('admin_login_failed', $array);
             Messages::errors(__('Login failed. Please check your login data and try again.'));
             $array->error($fieldname, 'incorrect');
             Kohana::$log->add(Log::ALERT, 'Try to login with :field: :value. Incorrect data', array(':field' => $fieldname, ':value' => $array['username']))->write();
         }
     } else {
         Messages::errors($array->errors('validation'));
     }
     $this->go(Route::get('user')->uri(array('action' => 'login')));
 }
 public static function setErrors($filename)
 {
     $array = array();
     foreach (file($filename) as $line) {
         list($key, $value) = explode(' ', $line, 2) + array(NULL, NULL);
         if ($value !== NULL) {
             $array[$key] = $value;
         }
     }
     self::$errors = $array;
 }
Example #6
0
 private function _apply_patch()
 {
     $patch = $this->request->post('patch');
     try {
         Patch::apply($patch);
     } catch (Validation_Exception $ex) {
         Messages::errors($ex->errors());
     } catch (Kohana_Exception $ex) {
         Messages::errors($ex->getMessage());
     }
     $this->go_back();
 }
Example #7
0
 protected function _login(Validation $validation, $remember)
 {
     if ($validation->check()) {
         Observer::notify('login_before', $validation);
         if (Auth::instance()->login($validation[$this->get('login_field')], $validation[$this->get('password_field')], $remember)) {
             Observer::notify('login_success', $validation[$this->get('login_field')]);
             HTTP::redirect($this->get_next_url());
         } else {
             Observer::notify('login_failed', $validation);
             Messages::errors(__('Login failed. Please check your login data and try again.'));
         }
     }
     HTTP::redirect(Request::current()->referrer());
 }
Example #8
0
 /**
  * 
  * @throws Installer_Exception
  */
 public function action_go()
 {
     $this->auto_render = FALSE;
     $post = $this->request->post('install');
     try {
         $this->_installer->install($post);
         Observer::notify('after_install', $post);
         Cache::clear_file();
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (Exception $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     $this->go($post['admin_dir_name'] . '/login');
 }
Example #9
0
     $plugin = Plugins::get_registered($plugin_id);
     if ($this->request->method() == Request::POST) {
         return $this->_settings_save($plugin);
     }
     $this->template->content = View::factory('plugins/settings', array('content' => View::factory($plugin->id() . '/settings', array('plugin' => $plugin))));
     $this->set_title(__('Plugin :title settings', array(':title' => $plugin->title())));
 }
 protected function _settings_save($plugin)
 {
     $data = Arr::get($this->request->post(), 'setting', array());
     try {
         $plugin->set_settings($data)->validate()->save_settings();
         Kohana::$log->add(Log::INFO, ':user change settings for plugin :name ', array(':name' => $plugin->title()))->write();
         Messages::success(__('Plugin settings saved!'));
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     }
Example #10
0
 /**
  * 
  * @param integer $id
  * @return DataSource_Section
  * @throws HTTP_Exception_404
  */
 public function section($id = NULL)
 {
     if ($this->_section instanceof DataSource_Section) {
         return $this->_section;
     }
     if ($id === NULL) {
         Messages::errors(__('Datasource section not loaded'));
         $this->go_home();
     }
     $this->_section = Datasource_Data_Manager::load((int) $id);
     if ($this->request->action() == 'index' and !$this->_section->has_access_view()) {
         $this->_deny_access();
     }
     if (empty($this->_section)) {
         Messages::errors(__('Datasource section :id not found', array(':id' => $id)));
         $this->go_home();
     }
     return $this->_section;
 }
Example #11
0
 public function action_upload()
 {
     $this->auto_render = FALSE;
     $errors = array();
     # Проверяем файл
     if (!isset($_FILES['file'])) {
         $this->go_back();
     }
     $file = $_FILES['file'];
     if (!is_dir(BACKUP_PLUGIN_FOLDER)) {
         $errors[] = __('Folder (:folder) not exist!', array(':folder' => BACKUP_PLUGIN_FOLDER));
     }
     if (!is_writable(BACKUP_PLUGIN_FOLDER)) {
         $errors[] = __('Folder (:folder) must be writable!', array(':folder' => BACKUP_PLUGIN_FOLDER));
     }
     # Проверяем на пустоту
     if (!Upload::not_empty($file)) {
         $errors[] = __('File is not attached!');
     }
     # Проверяем на расширение
     if (!Upload::type($file, array('sql', 'zip'))) {
         $errors[] = __('Bad format of file!');
     }
     if (!empty($errors)) {
         Messages::errors($errors);
         $this->go_back();
     }
     $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
     # Имя файла
     $filename = 'uploaded-' . date('YmdHis') . '-' . $file['name'];
     Upload::$default_directory = BACKUP_PLUGIN_FOLDER;
     # Cохраняем оригинал и продолжаем работать, если ок:
     if ($file = Upload::save($file, $filename, NULL, 0777)) {
         Messages::success(__('File :filename uploaded successfully', array(':filename' => $filename)));
         Kohana::$log->add(Log::ALERT, 'Backup file :filename uploaded by :user', array(':filename' => $filename))->write();
         $this->go_back();
     }
 }
Example #12
0
 private function _edit($field)
 {
     try {
         $field->set($this->request->post());
         DataSource_Hybrid_Field_Factory::update_field(clone $field, $field);
     } catch (Validation_Exception $e) {
         Session::instance()->set('post_data', $this->request->post());
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (Kohana_Exception $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     Session::instance()->delete('post_data');
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'section', 'action' => 'edit', 'id' => $field->ds_id)));
     } else {
         $this->go_back();
     }
 }
Example #13
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $snippet_name = $this->request->param('id');
     $snippet = new Model_File_Snippet($snippet_name);
     // find the user to delete
     if ($snippet->is_exists()) {
         if ($snippet->delete()) {
             Kohana::$log->add(Log::INFO, 'Snippet :name has been deleted by :user', array(':name' => $snippet_name))->write();
             Messages::success(__('Snippet has been deleted!'));
             Observer::notify('snippet_after_delete', $snippet_name);
         } else {
             Messages::errors(__('Something went wrong!'));
         }
     } else {
         Messages::errors(__('Snippet not found!'));
     }
     $this->go();
 }
Example #14
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $id = $this->request->param('id');
     // find the user to delete
     $user = ORM::factory('user', $id);
     if (!$user->loaded()) {
         Messages::errors(__('User not found!'));
         $this->go();
     }
     if ($user->delete()) {
         Messages::success(__('User has been deleted!'));
     } else {
         Messages::errors(__('Something went wrong!'));
     }
     $this->go();
 }
Example #15
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $id = $this->request->param('id');
     if ($id < 2) {
         Messages::success(__('Action disabled!'));
         $this->go();
     }
     $role = ORM::factory('role', $id);
     if (!$role->loaded()) {
         Messages::errors(__('Role not found!'));
         $this->go();
     }
     try {
         $role->delete();
         Messages::success(__('Role has been deleted!'));
     } catch (Kohana_Exception $e) {
         Messages::errors(__('Something went wrong!'));
     }
     $this->go();
 }
Example #16
0
 /**
  * 
  * @param Datasource_Section $ds
  */
 private function _edit($ds)
 {
     $data = $this->request->post();
     try {
         $ds->values($data);
         $ds->update();
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (DataSource_Exception_Section $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     Messages::success(__('Datasource has been saved!'));
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'data')) . URL::query(array('ds_id' => $ds->id()), FALSE));
     } else {
         $this->go_back();
     }
 }
Example #17
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $id = (int) $this->request->param('id');
     $type = ORM::factory('email_type', $id);
     if (!$type->loaded()) {
         Messages::errors(__('Email type not found!'));
         $this->go(Route::get('email_controllers')->uri(array('controller' => 'types')));
     }
     try {
         $type->delete();
         Messages::success(__('Email type has been deleted!'));
     } catch (Kohana_Exception $e) {
         Messages::errors(__('Something went wrong!'));
         $this->go_back();
     }
     $this->go(Route::get('email_controllers')->uri(array('controller' => 'types')));
 }
Example #18
0
 /**
  * Событие вызываемое в момент ошибки обновления документа
  */
 public function onUpdateException(Kohana_Exception $exception)
 {
     Messages::errors($exception->getMessage());
 }
Example #19
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $page_id = (int) $this->request->param('id');
     if ($page_id == 1) {
         Messages::errors(__('Root page can not be removed.'));
         $this->go_back();
     }
     $page = ORM::factory('page', $page_id);
     if (!$page->loaded()) {
         Messages::errors(__('Page not found!'));
         $this->go_back();
     }
     // check for permission to delete this page
     if (!Auth::has_permissions($page->get_permissions())) {
         Kohana::$log->add(Log::ALERT, 'Trying to delete page :id by :user', array(':id' => $page_id))->write();
         Messages::errors(__('You do not have permission.'));
         $this->go_back();
     }
     try {
         $page->delete();
         Messages::success(__('Page has been deleted!'));
     } catch (Kohana_Exception $e) {
         Messages::errors(__('Something went wrong!'));
         $this->go_back();
     }
     $this->go();
 }
Example #20
0
 public function action_template()
 {
     $id = (int) $this->request->param('id');
     $widget = Widget_Manager::load($id);
     if (!$widget) {
         Messages::errors(__('Widget not found!'));
         $this->go_back();
     }
     Assets::package('ace');
     $template = $widget->default_template();
     $data = file_get_contents($template);
     $this->template->content = View::factory('widgets/default_template', array('data' => $data));
 }
Example #21
0
 public function action_run()
 {
     $this->auto_render = FALSE;
     $id = (int) $this->request->param('id');
     $job = ORM::factory('job', $id);
     if (!$job->loaded()) {
         Messages::errors(__('Job not found!'));
         $this->go_back();
     }
     $job->run();
     Messages::success(__('Job run success!'));
     $this->go_back();
 }
Example #22
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $layout_name = $this->request->param('id');
     $layout = new Model_File_Layout($layout_name);
     // find the user to delete
     if (!$layout->is_used()) {
         if ($layout->delete()) {
             Kohana::$log->add(Log::INFO, 'Layout :name has been deleted by :user', array(':name' => $layout_name))->write();
             Messages::success(__('Layout has been deleted!'));
             Observer::notify('layout_after_delete', $layout_name);
         } else {
             Messages::errors(__('Something went wrong!'));
         }
     } else {
         Messages::errors(__('Layout is used! It CAN NOT be deleted!'));
     }
     $this->go();
 }
Example #23
0
 /**
  * 
  * @param Validation $validation
  * @param string $file
  * @return array
  */
 public static function validation(Validation $validation, $file = 'validation')
 {
     $errors = $validation->errors($file);
     return Messages::errors($errors);
 }