From 76f5b3678c3f2fefcac0da1af2e681239b9c3210 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Fri, 16 Sep 2011 00:16:44 +0200 Subject: [PATCH] Use MY_Controller instead of global hook --- application/config/hooks.php | 6 --- application/controllers/about.php | 8 ++-- application/controllers/ajax.php | 7 ++- application/controllers/api.php | 5 +-- application/controllers/auth.php | 30 ++++++++++--- application/controllers/dashboard.php | 6 +-- application/controllers/experiments.php | 2 +- application/controllers/jobs.php | 2 +- application/controllers/license.php | 8 ++-- application/controllers/programs.php | 8 ++-- application/controllers/projects.php | 7 ++- application/controllers/results.php | 9 ++-- application/controllers/search.php | 23 +++++++++- application/controllers/users.php | 5 +-- application/controllers/xmlrpc.php | 18 ++++++-- application/core/MY_Controller.php | 59 +++++++++++++++++++++++++ 16 files changed, 151 insertions(+), 52 deletions(-) create mode 100644 application/core/MY_Controller.php diff --git a/application/config/hooks.php b/application/config/hooks.php index d8d81ab..38379ba 100755 --- a/application/config/hooks.php +++ b/application/config/hooks.php @@ -10,12 +10,6 @@ | */ -$hook['post_controller_constructor'] = array( - 'class' => '', - 'function' => 'check_login', - 'filename' => 'global.php', - 'filepath' => 'hooks' -); /* End of file hooks.php */ /* Location: ./application/config/hooks.php */ diff --git a/application/controllers/about.php b/application/controllers/about.php index 0e7f09c..ae30294 100644 --- a/application/controllers/about.php +++ b/application/controllers/about.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,11 +22,11 @@ */ /** - * Static about page + * Static about page. * * @author Karsten Heiken */ -class About extends CI_Controller { +class About extends MY_Controller { /** * Constructor. diff --git a/application/controllers/ajax.php b/application/controllers/ajax.php index ad4304d..3c50de1 100644 --- a/application/controllers/ajax.php +++ b/application/controllers/ajax.php @@ -1,7 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +27,7 @@ * @author Karsten Heiken * @author Eike Foken */ -class Ajax extends CI_Controller { +class Ajax extends MY_Controller { /** * Constructor. diff --git a/application/controllers/api.php b/application/controllers/api.php index eccb96b..db19d94 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -1,7 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/application/controllers/auth.php b/application/controllers/auth.php index fcedc58..b7c5cec 100644 --- a/application/controllers/auth.php +++ b/application/controllers/auth.php @@ -1,20 +1,39 @@ - */ -class Auth extends CI_Controller { +class Auth extends MY_Controller { /** * Constructor. */ public function __construct() { parent::__construct(); - $this->load->library('access'); $this->load->library('form_validation'); - $this->load->model('user'); } /** @@ -114,9 +133,6 @@ class Auth extends CI_Controller { if ($this->input->post('new_password') != '') { $username = $this->session->userdata('username'); $change = $this->access->changePassword($username, $this->input->post('old_password'), $this->input->post('new_password')); -// if ($change) { -// $this->logout(); -// } } // update users table diff --git a/application/controllers/dashboard.php b/application/controllers/dashboard.php index 3dde900..9732d15 100644 --- a/application/controllers/dashboard.php +++ b/application/controllers/dashboard.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,7 +24,7 @@ /** * @author Karsten Heiken */ -class Dashboard extends CI_Controller { +class Dashboard extends MY_Controller { /** * Constructor. diff --git a/application/controllers/experiments.php b/application/controllers/experiments.php index 4aecec2..6fd3e5e 100644 --- a/application/controllers/experiments.php +++ b/application/controllers/experiments.php @@ -27,7 +27,7 @@ * @author Karsten Heiken * @author Eike Foken */ -class Experiments extends CI_Controller { +class Experiments extends MY_Controller { /** * Constructor. diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index 9c6e2c8..5de1a5f 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -26,7 +26,7 @@ * @author Karsten Heiken * @author Eike Foken */ -class Jobs extends CI_Controller { +class Jobs extends MY_Controller { /** * Constructor. diff --git a/application/controllers/license.php b/application/controllers/license.php index a0166ed..3c931f0 100644 --- a/application/controllers/license.php +++ b/application/controllers/license.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,11 +22,11 @@ */ /** - * Static license page + * Static license page. * * @author Karsten Heiken */ -class License extends CI_Controller { +class License extends MY_Controller { /** * Constructor. diff --git a/application/controllers/programs.php b/application/controllers/programs.php index 4cc6067..f2cf20b 100644 --- a/application/controllers/programs.php +++ b/application/controllers/programs.php @@ -1,7 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,9 +22,10 @@ */ /** + * * @author Karsten Heiken */ -class Programs extends CI_Controller { +class Programs extends MY_Controller { /** * Constructor. diff --git a/application/controllers/projects.php b/application/controllers/projects.php index 54c41c3..87f73d2 100644 --- a/application/controllers/projects.php +++ b/application/controllers/projects.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ * @author Karsten Heiken * @author Eike Foken */ -class Projects extends CI_Controller { +class Projects extends MY_Controller { /** * Constructor. @@ -36,7 +36,6 @@ class Projects extends CI_Controller { $this->load->library('form_validation'); $this->load->model('experiment'); $this->load->model('job'); - $this->load->model('share'); } /** diff --git a/application/controllers/results.php b/application/controllers/results.php index 96ca61d..977c642 100644 --- a/application/controllers/results.php +++ b/application/controllers/results.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ * * @author Karsten Heiken */ -class Results extends CI_Controller { +class Results extends MY_Controller { /** * Constructor. @@ -38,6 +38,9 @@ class Results extends CI_Controller { $this->load->model('server'); } + /** + * + */ public function index() { } diff --git a/application/controllers/search.php b/application/controllers/search.php index 6b550ff..eea3d68 100644 --- a/application/controllers/search.php +++ b/application/controllers/search.php @@ -1,11 +1,32 @@ */ -class Search extends CI_Controller { +class Search extends MY_Controller { /** * Calls the parent constructor. diff --git a/application/controllers/users.php b/application/controllers/users.php index 22a60b9..de1eb47 100644 --- a/application/controllers/users.php +++ b/application/controllers/users.php @@ -1,6 +1,6 @@ + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,14 +25,13 @@ * * @author Eike Foken */ -class Users extends CI_Controller { +class Users extends MY_Controller { /** * Calls the parent constructor. */ public function __construct() { parent::__construct(); - $this->load->model('user'); } /** diff --git a/application/controllers/xmlrpc.php b/application/controllers/xmlrpc.php index f965559..f7aa196 100644 --- a/application/controllers/xmlrpc.php +++ b/application/controllers/xmlrpc.php @@ -1,6 +1,6 @@ - + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,8 +26,11 @@ * * @author Karsten Heiken */ -class Xmlrpc extends CI_Controller { +class Xmlrpc extends MY_Controller { + /** + * Calls the parent constructor. + */ function __construct() { parent::__construct(); @@ -120,6 +123,11 @@ class Xmlrpc extends CI_Controller { return $this->xmlrpc->send_response($response); } + /** + * + * @param mixed $request + * @return mixed + */ function _job_done($request) { $this->load->model('job'); $parameters = $request->output_parameters(); @@ -142,5 +150,7 @@ class Xmlrpc extends CI_Controller { ), 'struct'); return $this->xmlrpc->send_response($response); } - } + +/* End of file xmlrpc.php */ +/* Location: ./application/controllers/xmlrpc.php */ diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php new file mode 100644 index 0000000..24016a3 --- /dev/null +++ b/application/core/MY_Controller.php @@ -0,0 +1,59 @@ + + */ +class MY_Controller extends CI_Controller { + + /** + * Contains a list of public controllers. + * + * @var array + */ + private $public_controllers = array('auth', 'xmlrpc'); + + /** + * Calls the parent contructor. + */ + public function __construct() { + parent::__construct(); + + if (!in_array($this->router->class, $this->public_controllers)) { + // redirect if the user is not logged in + if (!$this->input->is_ajax_request() && !$this->access->isLoggedIn()) { + redirect('auth/login'); + } + + // show message if side is marked as offline + if ($this->setting->get('offline') == 1 && !$this->access->isAdmin()) { + show_error($this->setting->get('offline_message')); + } + } + } +} + +/* End of file MY_Controller.php */ +/* Location: ./application/core/MY_Controller.php */