1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Base authenticated controller for NINJA
4 * All controllers requiring authentication should
5 * extend this controller
7 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
8 * or registered trademarks of op5 AB.
9 * All other trademarks, servicemarks, registered trademarks, and registered
10 * servicemarks mentioned herein may be the property of their respective owner(s).
11 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
12 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
15 class Authenticated_Controller
extends Ninja_Controller
{
17 public $widgets = array();
19 public function __construct()
21 parent
::__construct();
22 # make sure user is authenticated
24 # Check if user is accessing through PHP CLI
25 if (PHP_SAPI
=== "cli") {
26 $cli_access = Kohana
::config('config.cli_access');
27 if ($cli_access === true) {
28 # username should be passed as argv[2]
29 if (!empty($_SERVER['argc']) && isset($_SERVER['argv'][2])) {
30 Auth
::instance()->force_login($_SERVER['argv'][2]);
32 } else if ($cli_access !== false) {
33 Auth
::instance()->force_login($cli_access);
35 echo "CLI access denied or not configured\n";
39 if (!Auth
::instance()->logged_in()) {
40 $auth_method = $this->input
->get('auth_method', false);
41 $username = $this->input
->get('username', false);
42 $password = $this->input
->get('password', false);
43 if (Kohana
::config('auth.use_get_auth') === true && $username !== false && $password !== false) {
44 $res = ninja_auth
::login_user($username, $password, $auth_method);
46 die('The provided authentication is invalid');
48 # store requested uri in session for later redirect
49 if (!request
::is_ajax() && $this->session
)
50 $this->session
->set('requested_uri', url
::current(true));
52 if (Router
::$controller != 'default') {
53 return url
::redirect(Kohana
::config('routes.log_in_form'));
59 # user might not be logged in due to CLI scripts, be quiet
60 $current_skin = config
::get('config.current_skin', '*', true);
62 $current_skin = 'default/';
64 else if (substr($current_skin, -1, 1) != '/') {
68 if (!file_exists(APPPATH
."views/css/".$current_skin)) {
69 op5log
::instance('ninja')->log('notice', 'Wanted to use skin "'. $current_skin.'", could not find it');
70 $current_skin = 'default/';
72 $this->template
->current_skin
= $current_skin;