OSB enhancements to date
This commit is contained in:
4
application/classes/controller/default.php
Normal file
4
application/classes/controller/default.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Controller_Default extends Controller_lnApp_Default {}
|
||||
?>
|
75
application/classes/controller/lnapp/default.php
Normal file
75
application/classes/controller/lnapp/default.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default controller for rendering pages.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page
|
||||
* @category Abstract/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class Controller_lnApp_Default extends Controller {
|
||||
/**
|
||||
* Controls access to this controller.
|
||||
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
|
||||
* Note that in second(array) example, user must have both 'login' AND 'admin' roles set in database
|
||||
*
|
||||
* @var boolean is authenticate required with this controller
|
||||
*/
|
||||
protected $auth_required = FALSE;
|
||||
/**
|
||||
* If redirecting to a login page, which page to redirect to
|
||||
*/
|
||||
protected $noauth_redirect = 'login';
|
||||
/**
|
||||
* Controls access for separate actions, eg:
|
||||
* 'adminpanel' => 'admin' will only allow users with the role admin to access action_adminpanel
|
||||
* 'moderatorpanel' => array('login', 'moderator') will only allow users with the roles login and moderator to access action_moderatorpanel
|
||||
*
|
||||
* @var array actions that require a valid user
|
||||
*/
|
||||
protected $secure_actions = array();
|
||||
|
||||
/**
|
||||
* Check and see if this controller needs authentication
|
||||
*
|
||||
* if $this->auth_required is TRUE, then the user must be logged in only.
|
||||
* if $this->auth_required is FALSE, AND $this->secure_actions has an array of
|
||||
* methods set to TRUE, then the user must be logged in AND a member of the
|
||||
* role.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::Config('config.method_security'))
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action]) === FALSE));
|
||||
}
|
||||
|
||||
public function before() {
|
||||
parent::before();
|
||||
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
// For AJAX/JSON requests, authorisation is controlled in the method.
|
||||
if (Request::$is_ajax && $this->request->action === 'json') {
|
||||
// Nothing required.
|
||||
|
||||
// For no AJAX/JSON requests, display an access page
|
||||
} elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
|
||||
Request::instance()->redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::instance()->uri());
|
||||
Request::instance()->redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
26
application/classes/controller/lnapp/logout.php
Normal file
26
application/classes/controller/lnapp/logout.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides logout capability
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Logout
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @also [login]
|
||||
*/
|
||||
class Controller_lnApp_Logout extends Controller {
|
||||
public function action_index() {
|
||||
# If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
Auth::instance()->logout();
|
||||
|
||||
Request::instance()->redirect('login');
|
||||
}
|
||||
|
||||
Request::instance()->redirect('welcome/index');
|
||||
}
|
||||
}
|
||||
?>
|
279
application/classes/controller/lnapp/templatedefault.php
Normal file
279
application/classes/controller/lnapp/templatedefault.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default template controller for rendering pages.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Template
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
/**
|
||||
* @var string page template
|
||||
*/
|
||||
public $template = 'lnapp/default';
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected $mediaroute = 'default/media';
|
||||
/**
|
||||
* @var object meta object information as per [meta]
|
||||
*/
|
||||
protected $meta;
|
||||
/**
|
||||
* Controls access to this controller.
|
||||
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
|
||||
* Note that in second(array) example, user must have both 'login' AND 'admin' roles set in database
|
||||
*
|
||||
* @var boolean is authenticate required with this controller
|
||||
*/
|
||||
protected $auth_required = FALSE;
|
||||
/**
|
||||
* If redirecting to a login page, which page to redirect to
|
||||
*/
|
||||
protected $noauth_redirect = 'login';
|
||||
/**
|
||||
* Controls access for separate actions, eg:
|
||||
* 'adminpanel' => 'admin' will only allow users with the role admin to access action_adminpanel
|
||||
* 'moderatorpanel' => array('login', 'moderator') will only allow users with the roles login and moderator to access action_moderatorpanel
|
||||
*
|
||||
* @var array actions that require a valid user
|
||||
*/
|
||||
protected $secure_actions = array(
|
||||
'menu' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Check and see if this controller needs authentication
|
||||
*
|
||||
* if $this->auth_required is TRUE, then the user must be logged in only.
|
||||
* if $this->auth_required is FALSE, AND $this->secure_actions has an array of
|
||||
* methods set to TRUE, then the user must be logged in AND a member of the
|
||||
* role.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::Config('config.method_security'))
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action]) === FALSE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the template [View] object.
|
||||
*
|
||||
* Page information is provided by [meta].
|
||||
* @uses meta
|
||||
*/
|
||||
public function before() {
|
||||
// Do not template media files
|
||||
if ($this->request->action === 'media') {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
parent::before();
|
||||
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
if (Kohana::$is_cli)
|
||||
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action));
|
||||
|
||||
// If auth is required and the user is logged in, then they dont have access.
|
||||
// (We have already checked authorisation.)
|
||||
if (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Insufficient Access'),
|
||||
'type'=>'debug',
|
||||
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action,'user'=>Auth::instance()->get_user()->username)),
|
||||
));
|
||||
|
||||
// @todo Login No Access redirects are not handled in JS?
|
||||
if (Request::$is_ajax) {
|
||||
echo _('You dont have enough permissions.');
|
||||
die();
|
||||
} else
|
||||
Request::instance()->redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::instance()->uri());
|
||||
Request::instance()->redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
|
||||
// For AJAX calls, we dont need to render the complete page.
|
||||
if (Request::$is_ajax) {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind our template meta variable
|
||||
$this->meta = new meta;
|
||||
View::bind_global('meta',$this->meta);
|
||||
|
||||
// Our default style sheet
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/default.css',
|
||||
));
|
||||
|
||||
// Our default scripts
|
||||
// This is in a reverse list, since we push them to the beginging of the scripts to render.
|
||||
foreach (array('file'=>array(
|
||||
'js/jquery.cookie.js',
|
||||
'js/jquery.jstree-1.0rc.js',
|
||||
'js/jquery-1.4.2.js',
|
||||
)) as $type => $datas) {
|
||||
|
||||
foreach ($datas as $data) {
|
||||
Script::add(array(
|
||||
'type'=>$type,
|
||||
'data'=>$data,
|
||||
),TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise our content
|
||||
$this->template->left = '';
|
||||
$this->template->content = '';
|
||||
$this->template->right = '';
|
||||
}
|
||||
|
||||
public function after() {
|
||||
if ($this->auto_render) {
|
||||
// Application Title
|
||||
$this->meta->title = 'Application Title';
|
||||
$this->template->title = '';
|
||||
|
||||
// Style Sheets Properties
|
||||
$this->meta->styles = Style::factory();
|
||||
|
||||
// Script Properties
|
||||
$this->meta->scripts = Script::factory();
|
||||
|
||||
// Application logo
|
||||
$this->template->logo = Config::logo();
|
||||
|
||||
// Link images on the header line
|
||||
$this->template->headimages = $this->_headimages();
|
||||
|
||||
// Control Line
|
||||
$this->template->control = $this->_control();
|
||||
|
||||
// System Messages line
|
||||
$this->template->sysmsg = $this->_sysmsg();
|
||||
|
||||
// Left Item
|
||||
$this->template->left = $this->_left();
|
||||
|
||||
// Right Item
|
||||
$this->template->right = $this->_right();
|
||||
|
||||
// Footer
|
||||
$this->template->footer = $this->_footer();
|
||||
|
||||
// For any ajax rendered actions, we'll need to capture the content and put it in the response
|
||||
} elseif (Request::$is_ajax && isset($this->template->content) && ! $this->request->response) {
|
||||
// @todo move this formatting to a view?
|
||||
if ($s = $this->_sysmsg() AND (string)$s) {
|
||||
$this->request->response = sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s);
|
||||
} else
|
||||
$this->request->response = '';
|
||||
|
||||
# In case there any style sheets or scrpits for this render.
|
||||
$this->request->response .= Style::factory();
|
||||
|
||||
# Get the response body
|
||||
$this->request->response .= sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content);
|
||||
}
|
||||
|
||||
parent::after();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Method to call from the tree menu
|
||||
*/
|
||||
public function action_menu() {
|
||||
$this->template->content = 'See menu on tree';
|
||||
}
|
||||
|
||||
protected function _headimages() {
|
||||
HeadImages::add(array(
|
||||
'url'=>'http://dev.leenooks.net',
|
||||
'img'=>'img/forum-big.png',
|
||||
'attrs'=>array('onclick'=>"target='_blank';",'title'=>'Link')
|
||||
));
|
||||
|
||||
return HeadImages::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render our control menu bar
|
||||
*/
|
||||
protected function _control() {
|
||||
return Breadcrumb::factory();
|
||||
}
|
||||
|
||||
protected function _sysmsg() {
|
||||
return SystemMessage::factory();
|
||||
}
|
||||
|
||||
protected function _left() {
|
||||
return empty($this->template->left) ? Controller_Tree::js() : $this->template->left;
|
||||
}
|
||||
|
||||
protected function _right() {
|
||||
return empty($this->template->right) ? '' : $this->template->right;
|
||||
}
|
||||
|
||||
public function _footer() {
|
||||
return sprintf('© %s',Config::SiteName());
|
||||
}
|
||||
|
||||
/**
|
||||
* This action will render all the media related files for a page
|
||||
* @return void
|
||||
*/
|
||||
final public function action_media() {
|
||||
// Generate and check the ETag for this file
|
||||
$this->request->check_cache(sha1($this->request->uri));
|
||||
|
||||
// Get the file path from the request
|
||||
$file = $this->request->param('file');
|
||||
|
||||
// Find the file extension
|
||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||
|
||||
// Remove the extension from the filename
|
||||
$file = substr($file, 0, -(strlen($ext) + 1));
|
||||
|
||||
// First try and find media files for the site_id
|
||||
if ($f = Kohana::find_file(sprintf('media/%s',Config::siteid()), $file, $ext)) {
|
||||
// Send the file content as the response
|
||||
$this->request->response = file_get_contents($f);
|
||||
|
||||
// If not found try a default media file
|
||||
} elseif ($f = Kohana::find_file('media', $file, $ext)) {
|
||||
// Send the file content as the response
|
||||
$this->request->response = file_get_contents($f);
|
||||
|
||||
} else {
|
||||
// Return a 404 status
|
||||
$this->request->status = 404;
|
||||
}
|
||||
|
||||
// Set the proper headers to allow caching
|
||||
$this->request->headers['Content-Type'] = File::mime_by_ext($ext);
|
||||
$this->request->headers['Content-Length'] = filesize($f);
|
||||
$this->request->headers['Last-Modified'] = date('r', filemtime($f));
|
||||
}
|
||||
}
|
||||
?>
|
110
application/classes/controller/lnapp/tree.php
Normal file
110
application/classes/controller/lnapp/tree.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class extends renders OSB menu tree.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Tree
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_lnApp_Tree extends Controller_Default {
|
||||
// Our tree data
|
||||
protected $treedata;
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected static $mediaroute = 'default/media';
|
||||
|
||||
public function after() {
|
||||
parent::after();
|
||||
|
||||
$this->request->headers['Content-Type'] = 'application/json';
|
||||
$this->request->response = sprintf('[%s]',json_encode($this->treedata));
|
||||
}
|
||||
|
||||
public static function js() {
|
||||
$mediapath = Route::get(static::$mediaroute);
|
||||
|
||||
return '
|
||||
<div id="tree" class=""></div>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$("#tree").jstree({
|
||||
themes : {
|
||||
"theme" : "default",
|
||||
"url" : "'.URL::site($mediapath->uri(array('file'=>'css/jquery.jstree.css'))).'",
|
||||
},
|
||||
ui : {
|
||||
"select_limit" : 1,
|
||||
"select_node" : false,
|
||||
},
|
||||
cookies : {
|
||||
"save_selected" : false,
|
||||
},
|
||||
json_data : {
|
||||
"correct_state" : "true",
|
||||
"progressive_render" : "true",
|
||||
"ajax" : {
|
||||
"url" : "'.URL::site('/tree/json').'",
|
||||
"data" : function (n) {
|
||||
return { id : n.attr ? n.attr("id") : "N_"+0 };
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins : [ "themes", "json_data", "ui", "cookies" ],
|
||||
});
|
||||
|
||||
// On selection
|
||||
$("#tree").bind("select_node.jstree", function (e, data) {
|
||||
if (a = data.rslt.obj.attr(\'id\').indexOf(\'_\')) {
|
||||
id = data.rslt.obj.attr(\'id\').substr(a+1);
|
||||
|
||||
if (href = $("#N_"+id).attr("href"))
|
||||
$("#ajBODY").load(href, function(r,s,x) {
|
||||
if (s == "error") {
|
||||
var msg = "Sorry but there was an error: ";
|
||||
$("#ajBODY").html(msg + x.status + " " + x.statusText + r);
|
||||
}
|
||||
});
|
||||
else
|
||||
alert("Unknown: "+id+" HREF:"+href);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the Tree Menu
|
||||
*
|
||||
* The incoming ID is either a Branch B_x or a Node N_x
|
||||
* Where X is actually the module.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public function action_json($id=null) {
|
||||
if ($this->_auth_required()) {
|
||||
$this->treedata = array('attr'=>array('id'=>'a_login'),
|
||||
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'login','href'=>URL::site('/login'))));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->treedata = array();
|
||||
$data = array();
|
||||
|
||||
foreach ($data as $branch) {
|
||||
array_push($this->treedata,array(
|
||||
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
||||
'state'=>$branch['state'],
|
||||
'data'=>array('title'=>$branch['name']),
|
||||
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('/%s/menu',$branch['name'])) : $branch['attr_href']),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
209
application/classes/controller/login.php
Normal file
209
application/classes/controller/login.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides login capability
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Login
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @also [logout]
|
||||
*/
|
||||
class Controller_Login extends Controller_TemplateDefault {
|
||||
public function action_index() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
// Instantiate a new user
|
||||
$user = ORM::factory('account');
|
||||
|
||||
// Check Auth
|
||||
$status = $user->login($_POST);
|
||||
|
||||
// If the post data validates using the rules setup in the user model
|
||||
if ($status) {
|
||||
// Redirect to the user account
|
||||
if ($redir = Session::instance()->get('afterlogin')) {
|
||||
Session::instance()->delete('afterlogin');
|
||||
Request::instance()->redirect($redir);
|
||||
|
||||
} else
|
||||
Request::instance()->redirect('welcome/index');
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Invalid username or password'),
|
||||
'type'=>'error',
|
||||
'body'=>_('The username or password was invalid.')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Login to server'),
|
||||
'body'=>View::factory('login'),
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Login',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
||||
public function action_register() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// Instantiate a new user
|
||||
$account = ORM::factory('account');
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
// Check Auth
|
||||
$status = $account->values($_POST)->check();
|
||||
|
||||
if (! $status) {
|
||||
foreach ($account->validate()->errors() as $f=>$r) {
|
||||
// $r[0] has our reason for validation failure
|
||||
switch ($r[0]) {
|
||||
// Generic validation reason
|
||||
default:
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Validation failed'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r[0])
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ido = ORM::factory('module')
|
||||
->where('name','=','account')
|
||||
->find();
|
||||
|
||||
$account->id = $ido->record_id->next_id($ido->id);
|
||||
// Save the user details
|
||||
if ($account->save()) {}
|
||||
|
||||
}
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Already have an account?'),
|
||||
'type'=>'info',
|
||||
'body'=>_('If you already have an account, please login..')
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Register'),
|
||||
'body'=>View::factory('bregister')
|
||||
->set('account',$account)
|
||||
->set('errors',$account->validate()->errors()),
|
||||
'style'=>array('css/bregister.css'=>'screen'),
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Register',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
$this->template->left = HTML::anchor('login','Login').'...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable user password reset
|
||||
*/
|
||||
public function action_reset() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If the user posted their details to reset their password
|
||||
if ($_POST) {
|
||||
// If the email address is correct, create a method token
|
||||
if (! empty($_POST['email']) AND ($ao=ORM::factory('account',array('email'=>$_POST['email']))) AND $ao->loaded()) {
|
||||
$mt = ORM::factory('module_method_token');
|
||||
|
||||
// Find out our password reset method id
|
||||
// @todo move this to a more generic method, so that it can be called by other methods
|
||||
$mo = ORM::factory('module',array('name'=>'account'));
|
||||
$mmo = ORM::factory('module_method',array('name'=>'user_resetpassword','module_id'=>$mo->id));
|
||||
|
||||
// Check to see if there is already a token, if so, do nothing.
|
||||
if ($mt->where('account_id','=',$ao->id)->and_where('method_id','=',$mmo->id)->find()) {
|
||||
if ($mt->date_expire < time()) {
|
||||
$mt->delete();
|
||||
$mt->clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $mt->loaded()) {
|
||||
$mt->account_id = $ao->id;
|
||||
$mt->method_id = $mmo->id;
|
||||
$mt->date_expire = time() + 15*3600;
|
||||
$mt->token = md5(sprintf('%s:%s:%s',$mt->account_id,$mt->method_id,$mt->date_expire));
|
||||
$mt->save();
|
||||
|
||||
// Send our email with the token
|
||||
$et = EmailTemplate::instance('account_reset_password');
|
||||
$et->to = array($mt->account->email=>sprintf('%s %s',$mt->account->first_name,$mt->account->last_name));
|
||||
$et->variables = array(
|
||||
'SITE'=>URL::base(TRUE,TRUE),
|
||||
'SITE_ADMIN'=>Config::sitename(),
|
||||
'SITE_NAME'=>Config::sitename(),
|
||||
'TOKEN'=>$mt->token,
|
||||
'USER_NAME'=>sprintf('%s %s',$mt->account->first_name,$mt->account->last_name),
|
||||
);
|
||||
$et->send();
|
||||
}
|
||||
|
||||
// Redirect to our password reset, the Auth will validate the token.
|
||||
} elseif (! empty($_REQUEST['token'])) {
|
||||
Request::instance()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
|
||||
}
|
||||
|
||||
// Show our token screen even if the email was invalid.
|
||||
if (isset($_POST['email']))
|
||||
Block::add(array(
|
||||
'title'=>_('Reset your password'),
|
||||
'body'=>View::factory('login_reset_sent'),
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
else
|
||||
Request::instance()->redirect('login');
|
||||
|
||||
} else {
|
||||
Block::add(array(
|
||||
'title'=>_('Reset your password'),
|
||||
'body'=>View::factory('login_reset'),
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
public function action_noaccess() {
|
||||
$this->template->content = ' ';
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('No access to requested resource'),
|
||||
'type'=>'error',
|
||||
'body'=>_('You do not have access to the requested resource, please contact your administrator.')
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
4
application/classes/controller/logout.php
Normal file
4
application/classes/controller/logout.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Controller_Logout extends Controller_lnApp_Logout {}
|
||||
?>
|
56
application/classes/controller/templatedefault.php
Normal file
56
application/classes/controller/templatedefault.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default template controller for rendering pages.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Template
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault {
|
||||
/**
|
||||
* Check and see if this controller needs authentication
|
||||
*
|
||||
* if $this->auth_required is TRUE, then the user must be logged in only.
|
||||
* if $this->auth_required is FALSE, AND $this->secure_actions has an array of
|
||||
* methods set to TRUE, then the user must be logged in AND a member of the
|
||||
* role.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::Config('config.method_security'))
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action],get_class($this).'|'.__METHOD__) === FALSE));
|
||||
}
|
||||
|
||||
protected function _left() {
|
||||
if ($this->template->left)
|
||||
return $this->template->left;
|
||||
|
||||
elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__))
|
||||
return Controller_Tree::js();
|
||||
}
|
||||
|
||||
protected function _right() {
|
||||
if ($this->template->right)
|
||||
return $this->template->right;
|
||||
else
|
||||
return $this->_cart();
|
||||
}
|
||||
|
||||
private function _cart() {
|
||||
if (! Cart::instance()->contents()->reset(FALSE)->count_all())
|
||||
return '';
|
||||
|
||||
return Cart::instance()->cart_block();
|
||||
}
|
||||
}
|
||||
?>
|
90
application/classes/controller/tree.php
Normal file
90
application/classes/controller/tree.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class extends renders OSB menu tree.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Tree
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Tree extends Controller_lnApp_Tree {
|
||||
protected $auth_required = TRUE;
|
||||
|
||||
/**
|
||||
* Draw the Tree Menu
|
||||
*
|
||||
* The incoming ID is either a Branch B_x or a Node N_x
|
||||
* Where X is actually the module.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public function action_json($id=null) {
|
||||
if ($this->_auth_required()) {
|
||||
$this->treedata = array('attr'=>array('id'=>'a_login'),
|
||||
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('login'))));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the user details
|
||||
$id = (is_null($id) && isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $id;
|
||||
$user = Auth::instance()->get_user();
|
||||
|
||||
if (! $id) {
|
||||
$modules = array();
|
||||
foreach ($user->groups() as $go)
|
||||
$modules = array_merge($modules,Module_Method::groupmodules($go->id));
|
||||
|
||||
ksort($modules);
|
||||
|
||||
$data = array();
|
||||
foreach ($modules as $module => $details)
|
||||
if (! $details['parent_id'])
|
||||
array_push($data,
|
||||
array('id'=>$details['id'],'name'=>$module,'state'=>'closed')
|
||||
);
|
||||
|
||||
} else {
|
||||
$module = preg_replace('/^N_/','',$id);
|
||||
$methods = array();
|
||||
foreach ($user->groups() as $go)
|
||||
$methods = array_merge($methods,Module_Method::groupmethods($go->id,$module));
|
||||
|
||||
ksort($methods);
|
||||
|
||||
$data = array();
|
||||
foreach ($methods as $method => $details) {
|
||||
if (preg_match('/_/',$method)) {
|
||||
list($mode,$action) = explode('_',$method);
|
||||
$url = URL::site(sprintf('/%s/%s/%s',$mode,$details['module'],$action));
|
||||
} else {
|
||||
$url = URL::site(sprintf('/%s/%s',$details['module'],$method));
|
||||
}
|
||||
|
||||
array_push($data,array(
|
||||
'id'=>sprintf('%s_%s',$module,$details['id']),
|
||||
'name'=>$method,
|
||||
'state'=>'none',
|
||||
'attr_id'=>sprintf('%s_%s',$module,$details['id']),
|
||||
'attr_href'=>(empty($details['page']) ? $url : $details['page'])
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->treedata = array();
|
||||
|
||||
foreach ($data as $branch) {
|
||||
array_push($this->treedata,array(
|
||||
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
||||
'state'=>$branch['state'],
|
||||
'data'=>array('title'=>$branch['name']),
|
||||
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('/%s/menu',$branch['name'])) : $branch['attr_href']),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,10 +1,39 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Controller_Welcome extends Controller {
|
||||
/**
|
||||
* OSB Main home page
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Page/Home
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Welcome extends Controller_TemplateDefault {
|
||||
public function action_index() {
|
||||
$block = new block;
|
||||
$block->add(array(
|
||||
'title'=>'Welcome to lnApp (public)!',
|
||||
'subtitle'=>'Using lnApp',
|
||||
'body'=>'Sample lnApp application',
|
||||
'footer'=>'lnApp makes building websites easy! '.time(),
|
||||
));
|
||||
|
||||
public function action_index()
|
||||
{
|
||||
$this->request->response = 'hello, world!';
|
||||
if (Auth::instance()->logged_in()) {
|
||||
$this->template->control = HTML::anchor('/logout',_('Logout'),array('id'=>'ajxbody'));
|
||||
} else {
|
||||
$this->template->control = HTML::anchor('/login',_('Login'),array('id'=>'ajxbody'));
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("#ajxbody").click(function() {$("#ajBODY").load("'.URL::site('/login').'",null,function(x,s,r) {}); return false;});
|
||||
$("#ajBODY").ajaxSend(function() {$(this).html(\''.sprintf('%s <span class="ajaxmsg">%s<\/span>...',HTML::image('media/img/ajax-progress.gif',array('alt'=>_('Loading Login').'...')),_('Loading Login')).'\');return true;});
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = $block;
|
||||
}
|
||||
|
||||
} // End Welcome
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user