From c0ba6d4e987c163c9663abcb98ec8eaac1580b34 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 10 May 2013 20:48:10 +1000 Subject: [PATCH] Application cleanup --- application/classes/Auth/OSB.php | 120 ++++++------ application/classes/Config.php | 2 - application/classes/Controller/Account.php | 2 +- .../classes/Controller/Admin/Account.php | 1 - application/classes/Controller/Login.php | 19 +- .../classes/Controller/TemplateDefault.php | 22 +-- application/classes/Controller/Welcome.php | 12 +- application/classes/Country.php | 19 -- application/classes/Editor.php | 52 ----- application/classes/Kohana.php | 16 -- application/classes/Menu.php | 32 ++-- application/classes/Minion/Task.php | 3 + application/classes/Model/Account.php | 4 +- .../classes/Model/Auth/UserDefault.php | 17 +- application/classes/Model/Country.php | 8 +- application/classes/Model/Group.php | 13 -- application/classes/Model/Module.php | 7 +- application/classes/Model/RTM.php | 1 - application/classes/Model/Record/ID.php | 4 +- application/classes/ORM.php | 72 +++---- application/classes/ORM/OSB.php | 177 ++++++++---------- application/classes/StaticList.php | 4 - application/classes/Task.php | 20 -- application/classes/Task/Account/Complete.php | 7 +- application/classes/URL.php | 30 +-- application/classes/XML.php | 3 +- application/config/cache.php | 32 ---- application/config/userguide.php | 46 ----- application/views/login.php | 16 -- application/views/login_reset.php | 14 -- application/views/login_reset_sent.php | 13 -- application/views/pages/login_reset.php | 21 +++ application/views/pages/login_reset_sent.php | 19 ++ application/views/{ => pages}/register.php | 0 application/views/template.php | 0 .../invoice}/config/invoice.php | 0 36 files changed, 284 insertions(+), 544 deletions(-) delete mode 100644 application/classes/Country.php delete mode 100644 application/classes/Editor.php delete mode 100644 application/classes/Task.php delete mode 100644 application/config/cache.php delete mode 100644 application/config/userguide.php delete mode 100644 application/views/login.php delete mode 100644 application/views/login_reset.php delete mode 100644 application/views/login_reset_sent.php create mode 100644 application/views/pages/login_reset.php create mode 100644 application/views/pages/login_reset_sent.php rename application/views/{ => pages}/register.php (100%) delete mode 100644 application/views/template.php rename {application => modules/invoice}/config/invoice.php (100%) diff --git a/application/classes/Auth/OSB.php b/application/classes/Auth/OSB.php index 549d1b6e..73de132e 100644 --- a/application/classes/Auth/OSB.php +++ b/application/classes/Auth/OSB.php @@ -10,65 +10,6 @@ * @license http://dev.osbill.net/license.html */ class Auth_OSB extends Auth_ORM { - /** - * OSB authentication is controlled via database queries. - * - * This method can be used to test two situations: - * 1) Is the user logged in? ($role == FALSE) - * 2) Can the user run the current controller->action ($role == TRUE) - * - * @param boolean If authentication should be done for this module:method (ie: controller:action). - * @return boolean - */ - public function logged_in($role=NULL,$debug=NULL) { - $status = FALSE; - - // Get the user from the session - $uo = $this->get_user(); - - // 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 (Config::sitemode() == Kohana::DEVELOPMENT) - SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role)))); - - if (! empty($role) AND Request::current()->mmo()) { - // If the role has the authorisation to run the method - $gmo = ORM::factory('Group_Method') - ->where('method_id','=',Request::current()->mmo()->id); - - foreach ($gmo->find_all() as $gm) - // $gm->group->id == 0 means all users. - if ($gm->group->id == 0 OR $uo->has_any('group',$gm->group->list_childgrps(TRUE))) { - $status = TRUE; - break; - } - - // There is no role, so the method should be allowed to run as anonymous - } else - $status = TRUE; - } - - return $status; - } - - /** - * Gets the currently logged in user from the session. - * Returns NULL if no user is currently logged in. - * - * @param boolean Check token users too - * @return mixed - */ - public function get_user($default=NULL,$tokenuser=TRUE) { - // Get the current user - $uo = parent::get_user($default); - - // If we are not logged in, see if there is token for the user - if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token'])) - $uo = $this->_get_token_user($token); - - return $uo; - } - /** * Get the user that a token applies to * @@ -103,7 +44,6 @@ class Auth_OSB extends Auth_ORM { 'type'=>'warning', 'body'=>_('Token expired'))); - // @todo Log the token deletion Session::instance()->delete('token'); $mmto->delete(); @@ -113,7 +53,6 @@ class Auth_OSB extends Auth_ORM { 'type'=>'warning', 'body'=>_('Token expired'))); - // @todo Log the token deletion Session::instance()->delete('token'); $mmto->delete(); @@ -210,5 +149,64 @@ class Auth_OSB extends Auth_ORM { 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)))); } + + /** + * Gets the currently logged in user from the session. + * Returns NULL if no user is currently logged in. + * + * @param boolean Check token users too + * @return mixed + */ + public function get_user($default=NULL,$tokenuser=TRUE) { + // Get the current user + $uo = parent::get_user($default); + + // If we are not logged in, see if there is token for the user + if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token'])) + $uo = $this->_get_token_user($token); + + return $uo; + } + + /** + * OSB authentication is controlled via database queries. + * + * This method can be used to test two situations: + * 1) Is the user logged in? ($role == FALSE) + * 2) Can the user run the current controller->action ($role == TRUE) + * + * @param boolean If authentication should be done for this module:method (ie: controller:action). + * @return boolean + */ + public function logged_in($role=NULL,$debug=NULL) { + $status = FALSE; + + // Get the user from the session + $uo = $this->get_user(); + + // 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 (Config::sitemode() == Kohana::DEVELOPMENT) + SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role)))); + + if (! empty($role) AND Request::current()->mmo()) { + // If the role has the authorisation to run the method + $gmo = ORM::factory('Group_Method') + ->where('method_id','=',Request::current()->mmo()->id); + + foreach ($gmo->find_all() as $gm) + // $gm->group->id == 0 means all users. + if ($gm->group->id == 0 OR $uo->has_any('group',$gm->group->list_childgrps(TRUE))) { + $status = TRUE; + break; + } + + // There is no role, so the method should be allowed to run as anonymous + } else + $status = TRUE; + } + + return $status; + } } ?> diff --git a/application/classes/Config.php b/application/classes/Config.php index 9a26fea5..a55e4405 100644 --- a/application/classes/Config.php +++ b/application/classes/Config.php @@ -115,8 +115,6 @@ class Config extends Kohana_Config { // We need to know our site here, so that we can subsequently load our enabled modules. if (PHP_SAPI === 'cli') { if (! ($site = Minion_CLI::options('site'))) { - // @todo Need to figure out how to make this CLI error nicer. - #throw new Minion_Exception_InvalidTask(_('Cant figure out the site, use --site= for CLI')); echo _('Cant figure out the site, use --site= for CLI')."\n"; die(); diff --git a/application/classes/Controller/Account.php b/application/classes/Controller/Account.php index 1b28e451..25a7fce2 100644 --- a/application/classes/Controller/Account.php +++ b/application/classes/Controller/Account.php @@ -10,7 +10,7 @@ * @license http://dev.osbill.net/license.html */ class Controller_Account extends Controller_TemplateDefault { - public function action_group() { + protected function group() { // List all available groups for this user. $output = ''; diff --git a/application/classes/Controller/Admin/Account.php b/application/classes/Controller/Admin/Account.php index 213d70ff..bb1b8907 100644 --- a/application/classes/Controller/Admin/Account.php +++ b/application/classes/Controller/Admin/Account.php @@ -11,7 +11,6 @@ */ class Controller_Admin_Account extends Controller_Account { protected $secure_actions = array( - 'group'=>FALSE, // @todo Testing ); } ?> diff --git a/application/classes/Controller/Login.php b/application/classes/Controller/Login.php index 2a880956..aed7c471 100644 --- a/application/classes/Controller/Login.php +++ b/application/classes/Controller/Login.php @@ -72,22 +72,21 @@ class Controller_Login extends lnApp_Controller_Login { // Show our token screen even if the email was invalid. if (isset($_POST['username'])) - Block::add(array( - 'title'=>_('Reset your password'), - 'body'=>View::factory('login_reset_sent'), - 'style'=>array('css/login.css'=>'screen'), - )); + Block::factory() + ->body(View::factory('pages/login_reset_sent')); + else HTTP::redirect('login'); } else { - Block::add(array( - 'title'=>_('Reset your password'), - 'body'=>View::factory('login_reset'), - 'style'=>array('css/login.css'=>'screen'), - )); + Block::factory() + ->body(View::factory('pages/login_reset')); } + Style::factory() + ->type('file') + ->data('media/theme/baseadmin/css/pages/login.css'); + $this->template->shownavbar = FALSE; } } diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php index b23f5d4d..06fd32c5 100644 --- a/application/classes/Controller/TemplateDefault.php +++ b/application/classes/Controller/TemplateDefault.php @@ -28,7 +28,7 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { if ($this->auth_required) { if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()]))) - throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>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(); @@ -39,8 +39,9 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { parent::before(); } + // @todo To rework public function after() { - $dc = Kohana::$config->load('config','user_default_method'); + $dc = 'u/welcome/index'; $m = sprintf('%s/%s',Request::current()->directory(),Request::current()->controller()); BreadCrumb::URL(Request::current()->directory(),sprintf('%s/%s',Request::current()->directory(),$dc),FALSE); @@ -51,21 +52,14 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { /** * This will filter a search query to only return those accounts for a reseller + * @todo Swap the order of these params and make flid necessary */ - protected function filter($o,$af,$sort=NULL,$afid=NULL) { + protected function filter($o,array $fl,$sort=NULL,$flid=NULL) { $result = array(); - foreach ($o as $x) { - if (! is_null($afid) AND isset($x->$afid)) { - if ((is_array($af) AND in_array($x->$afid,$af)) OR ($x->$afid == $af)) - array_push($result,$x); - - } elseif (method_exists($x,'list_reseller')) { - if (in_array($af,$x->list_reseller())) - array_push($result,$x); - - } - } + foreach ($o as $x) + if (! is_null($flid) AND isset($x->$flid) AND in_array($x->$flid,$fl)) + array_push($result,$x); if ($sort) Sort::MAsort($result,$sort); diff --git a/application/classes/Controller/Welcome.php b/application/classes/Controller/Welcome.php index 9e17c1e6..a36058ea 100644 --- a/application/classes/Controller/Welcome.php +++ b/application/classes/Controller/Welcome.php @@ -12,6 +12,12 @@ class Controller_Welcome extends Controller_TemplateDefault { protected $auth_required = FALSE; + public function action_breadcrumb() { + $this->auto_render = FALSE; + + $this->response->body(Session::instance()->get_once('breadcrumb')); + } + public function action_index() { if (! Kohana::$config->load('config')->appname) HTTP::redirect('guide/app'); @@ -25,11 +31,5 @@ class Controller_Welcome extends Controller_TemplateDefault { $this->template->content = $output; } - - public function action_breadcrumb() { - $this->auto_render = FALSE; - - $this->response->body(Session::instance()->get_once('breadcrumb')); - } } ?> diff --git a/application/classes/Country.php b/application/classes/Country.php deleted file mode 100644 index 3af63013..00000000 --- a/application/classes/Country.php +++ /dev/null @@ -1,19 +0,0 @@ -two_code)),array('alt'=>$co->currency()->symbol)); - } -} -?> diff --git a/application/classes/Editor.php b/application/classes/Editor.php deleted file mode 100644 index c80266b6..00000000 --- a/application/classes/Editor.php +++ /dev/null @@ -1,52 +0,0 @@ -'file', - 'data'=>'js/jquery-1.4.2.js', - )); - Script::add(array( - 'type'=>'file', - 'data'=>'js/tiny_mce/tiny_mce.js', - )); - Script::add(array( - 'type'=>'stdin', - 'data'=>' -tinyMCE.init({ - mode : "specific_textareas", - editor_selector : "mceEditor", - theme : "advanced", - plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print", - theme_advanced_buttons1_add : "fontselect,fontsizeselect", - theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor", - theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator", - theme_advanced_buttons3_add_before : "tablecontrols,separator", - theme_advanced_buttons3_add : "iespell,media,advhr", - theme_advanced_toolbar_location : "bottom", - theme_advanced_toolbar_align : "center", - plugin_insertdate_dateFormat : "%Y-%m-%d", - plugin_insertdate_timeFormat : "%H:%M:%S", - extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]", - relative_urls: "true", - width : "100%" -});')); - } -} -?> diff --git a/application/classes/Kohana.php b/application/classes/Kohana.php index 7ff34ee2..1865e16b 100644 --- a/application/classes/Kohana.php +++ b/application/classes/Kohana.php @@ -51,22 +51,6 @@ abstract class Kohana extends Kohana_Core { return $x; } - /** - * @compat Restore KH 3.1 functionality - * @var boolean True if Kohana is running from the command line - */ - public static $is_cli = FALSE; - - /** - * @compat Restore KH 3.1 functionality - */ - public static function init(array $settings = NULL) { - parent::init($settings); - - // Determine if we are running in a command line environment - Kohana::$is_cli = (PHP_SAPI === 'cli'); - } - /** * Override Kohana's shutdown_handler() * diff --git a/application/classes/Menu.php b/application/classes/Menu.php index 1b1e84d3..6c1b44d3 100644 --- a/application/classes/Menu.php +++ b/application/classes/Menu.php @@ -10,22 +10,6 @@ * @license http://dev.osbill.net/license.html */ class Menu { - public static function items($type) { - $result = array(); - - if (empty(URL::$method_directory[$type])) - return NULL; - - $uo = Auth::instance()->get_user(); - - foreach ($uo->methods() as $mmo) - if ($mmo->menu_display AND preg_match('/^'.$type.'_/',$mmo->name)) - if (empty($result[$mmo->id])) - $result[$mmo->id] = $mmo; - - return static::collapse($result); - } - private static function collapse(array $array) { $result = array(); @@ -46,6 +30,22 @@ class Menu { return $result; } + public static function items($type) { + $result = array(); + + if (empty(URL::$method_directory[$type])) + return NULL; + + $uo = Auth::instance()->get_user(); + + foreach ($uo->methods() as $mmo) + if ($mmo->menu_display AND preg_match('/^'.$type.'_/',$mmo->name)) + if (empty($result[$mmo->id])) + $result[$mmo->id] = $mmo; + + return static::collapse($result); + } + public static function ul(array $result,array $append=NULL,$sub=FALSE) { $output = $sub ? '