This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnauth/classes/lnAuth/Controller/TemplateDefault.php

69 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2014-09-29 05:15:49 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides the default template controller for rendering pages.
*
* @package lnAuth
* @category Controllers
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnAuth_Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
protected $auth_required = TRUE;
protected function _auth_required() {
// If our global configurable is disabled, then continue
if (! Kohana::$config->load('config')->method_security)
return FALSE;
if (Kohana::$config->load('debug')->method_security) {
echo Debug::vars(array(
'm'=>__METHOD__,
'POST'=>$this->request->post(),
'auth_required'=>serialize($this->auth_required),
'secure_actions'=>$this->secure_actions,
'this_action'=>$this->request->action(),
'line 1 test'=>serialize(($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE)),
'line 2 test'=>serialize($x=is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions)),
'line 3 test'=>$x ? Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__) : 'NOT EVAL',
));
die();
}
2014-09-29 07:30:54 +00:00
return parent::_auth_required();
2014-09-29 05:15:49 +00:00
}
public function before() {
if ($this->auth_required) {
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
throw HTTP_Exception::factory(403,'Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
$this->ao = Auth::instance()->get_user();
if (! is_null($this->ao) AND (is_string($this->ao)))
throw HTTP_Exception::factory(501,'Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
}
return parent::before();
}
protected function setup(array $config_items=array()) {
$mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
if (! $mo->loaded())
throw HTTP_Exception::factory(501,'Unknown module :module',array(':module'=>Request::current()->controller()));
2016-08-25 13:23:25 +00:00
if ($this->request->post() AND array_key_exists($mo->id,$this->request->post('module_config')))
Config::instance()->module_config($mo->name,$this->request->post('module_config.'.$mo->id))->save();
2014-09-29 05:15:49 +00:00
if ($config_items) {
Block::factory()
->title('Update Module Configuration')
2016-08-25 13:23:25 +00:00
->title_icon('fa fa-wrench')
2014-09-29 05:15:49 +00:00
->type('form-horizontal')
->body(View::factory('setup/admin/module')->set('o',Company::instance()->so())->set('mid',$mo->id));
}
}
}
?>