Some minor internal fixes

This commit is contained in:
Deon George 2014-10-08 23:20:27 +11:00
parent 6d914ff290
commit fc5cea470a
5 changed files with 30 additions and 11 deletions

View File

@ -98,7 +98,7 @@ abstract class lnApp_Auth_ORM extends Kohana_Auth_ORM {
* @return boolean TRUE if authorised, FALSE if not.
*/
public function authorised(Model_Account $ao) {
return (($uo = $this->get_user()) AND $uo->loaded() AND ($uo == $ao OR in_array($ao->id,$uo->RTM->customers($uo->RTM))));
return (($uo = $this->get_user()) AND $uo->loaded() AND ($uo == $ao OR ($uo->admin > $ao->admin)));
}
public function get_groups() {
@ -158,6 +158,7 @@ abstract class lnApp_Auth_ORM extends Kohana_Auth_ORM {
// If we are not a valid user object, then we are not logged in
if (is_object($uo) AND ($uo instanceof Model_Account) AND $uo->loaded())
if (empty($role) OR ($role <= $uo->admin))
$status = TRUE;
return $status;

View File

@ -68,8 +68,16 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
* @uses meta
*/
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));
}
// Actions that start with ajax, should only be ajax
if (! Kohana::$config->load('debug')->ajax AND preg_match('/^ajax/',Request::current()->action()) AND ! Request::current()->is_ajax())
throw HTTP_Exception::factory(412,_('Unable to fulfil request.'));
@ -82,7 +90,7 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
return;
}
if ($this->ao AND $this->ao->loaded() AND ! $this->ao->activated() AND ($this->request->controller() != 'Account' OR $this->request->action() != 'activate'))
if ($this->ao AND is_object($this->ao) AND $this->ao->loaded() AND ! $this->ao->activated() AND ($this->request->controller() != 'Account' OR $this->request->action() != 'activate'))
HTTP::redirect('login/activate');
// Check user auth and role

View File

@ -22,6 +22,9 @@ abstract class lnApp_Form extends Kohana_Form {
return '%s';
}
if (! isset($attributes['class']))
$attributes['class'] = 'form-control';
$output = '';
$output .= '<div class="form-group">';
@ -43,9 +46,9 @@ abstract class lnApp_Form extends Kohana_Form {
}
$classdiv = FALSE;
if (isset($attributes['class'])) {
$output .= sprintf('<div class="%s">',$attributes['class']);
unset($attributes['class']);
if (isset($attributes['divclass'])) {
$output .= sprintf('<div class="%s">',$attributes['divclass']);
unset($attributes['divclass']);
$classdiv = TRUE;
}
@ -84,7 +87,7 @@ abstract class lnApp_Form extends Kohana_Form {
* @usedby Form::image
*/
public static function input($name,$value=NULL,array $attributes=NULL) {
return (isset($attributes['type']) AND $attributes['type'] == 'hidden') ? parent::input($name,$value,$attributes) : sprintf(self::_controlgroup($name,$attributes),parent::input($name,$value,Arr::merge($attributes,array('class'=>'form-control'))));
return (isset($attributes['type']) AND $attributes['type'] == 'hidden') ? parent::input($name,$value,$attributes) : sprintf(self::_controlgroup($name,$attributes),parent::input($name,$value,$attributes));
}
public static function select($name,array $options=NULL,$selected=NULL,array $attributes=NULL) {

View File

@ -10,12 +10,13 @@
* @license http://dev.leenooks.net/license.html
*/
class lnApp_Menu {
public static function items($type) {
public static function items($type,array $list=array()) {
$result = array();
if (empty(URL::$method_directory[$type]))
return NULL;
if (! $list)
$list = Kohana::list_files('classes/Controller/'.ucfirst($type));
// This will be used a lot!
@ -23,7 +24,7 @@ class lnApp_Menu {
foreach ($list as $name => $path)
if (is_array($path)) {
$result += self::items($path);
$result += self::items($type,$path);
} elseif (substr($name, -$ext_length) === EXT) {
// Remove "classes/" and the extension

6
views/errors/400.php Normal file
View File

@ -0,0 +1,6 @@
<h1>Oops!</h1>
<h2>400 Bad Request?</h2>
<?php echo $message; ?>
<div class="error-details">
Sorry, the request couldnt be actioned.
</div>