Updated OSB to work with KH 3.1
This commit is contained in:
@@ -35,19 +35,19 @@ class Auth_OSB extends Auth_ORM {
|
||||
|
||||
if (! empty($role)) {
|
||||
// Get the module details
|
||||
$module = ORM::factory('module',array('name'=>Request::instance()->controller));
|
||||
$module = ORM::factory('module',array('name'=>Request::current()->controller()));
|
||||
if (! $module->loaded() OR ! $module->status) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Module is not defined or active in the Database',
|
||||
'type'=>'warning',
|
||||
'body'=>sprintf('Module not defined: %s',Request::instance()->controller),
|
||||
'body'=>sprintf('Module not defined: %s',Request::current()->controller()),
|
||||
));
|
||||
|
||||
} else {
|
||||
if (Request::instance()->directory)
|
||||
$method_name = sprintf('%s_%s',Request::instance()->directory,Request::instance()->action);
|
||||
if (Request::current()->directory())
|
||||
$method_name = sprintf('%s_%s',Request::current()->directory(),Request::current()->action());
|
||||
else
|
||||
$method_name = Request::instance()->action;
|
||||
$method_name = Request::current()->action();
|
||||
|
||||
// Get the method number
|
||||
$method = ORM::factory('module_method',array('module_id'=>$module->id,'name'=>$method_name));
|
||||
@@ -55,7 +55,7 @@ class Auth_OSB extends Auth_ORM {
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Method is not defined or active in the Database',
|
||||
'type'=>'warning',
|
||||
'body'=>sprintf('Method not defined: %s for %s',Request::instance()->action,$module->name),
|
||||
'body'=>sprintf('Method not defined: %s for %s',Request::current()->action(),$module->name),
|
||||
));
|
||||
|
||||
} else {
|
||||
@@ -93,7 +93,7 @@ class Auth_OSB extends Auth_ORM {
|
||||
'title'=>'Debug',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('A-User: <b>%s</b>, Module: <b>%s</b>, Method: <b>%s</b>, Role: <b>%s</b>, Status: <b>%s</b>, Data: <b>%s</b>',
|
||||
$user->username,Request::instance()->controller,Request::instance()->action,$role,$status,$debug)));
|
||||
$user->username,Request::current()->controller(),Request::current()->action(),$role,$status,$debug)));
|
||||
|
||||
// There is no role, so the method should be allowed to run as anonymous
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ class Auth_OSB extends Auth_ORM {
|
||||
'title'=>'Debug',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('B-User: <b>%s</b>, Module: <b>%s</b>, Method: <b>%s</b>, Status: <b>%s</b>, Data: <b>%s</b>',
|
||||
$user->username,Request::instance()->controller,Request::instance()->action,'No Role Default Access',$debug)));
|
||||
$user->username,Request::current()->controller(),Request::current()->action(),'No Role Default Access',$debug)));
|
||||
|
||||
$status = TRUE;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class Auth_OSB extends Auth_ORM {
|
||||
*/
|
||||
private function _get_token_user($token) {
|
||||
$mmto = ORM::factory('module_method_token',array('token'=>$token));
|
||||
$request = Request::instance();
|
||||
$request = Request::current();
|
||||
$user = FALSE;
|
||||
|
||||
if ($mmto->loaded()) {
|
||||
@@ -196,7 +196,7 @@ class Auth_OSB extends Auth_ORM {
|
||||
$username = $user;
|
||||
|
||||
// Load the user
|
||||
$user = ORM::factory('user');
|
||||
$user = ORM::factory('account');
|
||||
$user->where($user->unique_key($username), '=', $username)->find();
|
||||
}
|
||||
|
||||
@@ -232,8 +232,10 @@ class Auth_OSB extends Auth_ORM {
|
||||
$orm = ORM::factory($t)
|
||||
->where($c,'=',$oldsess);
|
||||
|
||||
$orm->session_id = session_id();
|
||||
$orm->save_all();
|
||||
// @todo There must be a way that ORM can update multiple records with 1 SQL
|
||||
foreach ($orm->find_all() as $o)
|
||||
$o->set('session_id',session_id())
|
||||
->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -39,21 +39,21 @@ class Controller_User_Account extends Controller_TemplateDefault {
|
||||
));
|
||||
|
||||
$ao->save();
|
||||
Request::instance()->redirect('login');
|
||||
Request::current()->redirect('login');
|
||||
|
||||
} else {
|
||||
$output = '';
|
||||
foreach ($ao->validation()->errors('forms/login') as $field => $error)
|
||||
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
|
||||
|
||||
if ($output)
|
||||
$output = sprintf('<ul>%s</ul>',$output);
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record NOT updated'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Your updates didnt pass validation.')
|
||||
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
|
||||
));
|
||||
|
||||
foreach ($ao->validate()->errors('form_errors') as $field => $error)
|
||||
SystemMessage::add(array(
|
||||
'title'=>$field,
|
||||
'type'=>'error',
|
||||
'body'=>$error,
|
||||
));
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
@@ -61,8 +61,6 @@ class Controller_User_Account extends Controller_TemplateDefault {
|
||||
'body'=>View::factory('account/password_reset')
|
||||
->set('record',$ao),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,18 +87,18 @@ class Controller_User_Account extends Controller_TemplateDefault {
|
||||
$ao->save();
|
||||
|
||||
} else {
|
||||
$output = '';
|
||||
foreach ($ao->validation()->errors('forms/login') as $field => $error)
|
||||
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
|
||||
|
||||
if ($output)
|
||||
$output = sprintf('<ul>%s</ul>',$output);
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record NOT updated'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Your updates didnt pass validation.')
|
||||
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
|
||||
));
|
||||
|
||||
foreach ($ao->validate()->errors('form_errors') as $field => $error)
|
||||
SystemMessage::add(array(
|
||||
'title'=>$field,
|
||||
'type'=>'error',
|
||||
'body'=>$error,
|
||||
));
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
@@ -108,8 +106,6 @@ class Controller_User_Account extends Controller_TemplateDefault {
|
||||
'body'=>View::factory('account/edit')
|
||||
->set('record',$ao),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -18,9 +18,6 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
'service' => array(),
|
||||
);
|
||||
|
||||
// Complete our login
|
||||
public function complete_login() {}
|
||||
|
||||
/**
|
||||
* Return an account name
|
||||
*/
|
||||
|
@@ -9,46 +9,5 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Auth_RoleDefault extends Model_Auth_Role {
|
||||
protected $_table_names_plural = false;
|
||||
|
||||
protected $_object_formated = array();
|
||||
protected $_formated = FALSE;
|
||||
protected $_formats = array();
|
||||
|
||||
/**
|
||||
* Format fields for display purposes
|
||||
*
|
||||
* @param string column name
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _format() {
|
||||
$format = Validate::factory($this->_object);
|
||||
|
||||
foreach ($this->_formats as $column => $formats)
|
||||
$format->filters($column,$formats);
|
||||
|
||||
if ($format->check())
|
||||
foreach ($format as $column => $value)
|
||||
$this->_object_formated[$column] = $value;
|
||||
|
||||
$this->_formated = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
public function display($column) {
|
||||
// Trigger a load of the record.
|
||||
$value = $this->__get($column);
|
||||
|
||||
// If some of our fields need to be formated for display purposes.
|
||||
if ($this->_loaded AND ! $this->_formated AND $this->_formats)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -9,32 +9,34 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Auth_UserDefault extends Model_Auth_User {
|
||||
protected $_table_names_plural = false;
|
||||
|
||||
// Validation rules
|
||||
protected $_rules = array(
|
||||
'username' => array(
|
||||
'not_empty' => NULL,
|
||||
'min_length' => array(4),
|
||||
'max_length' => array(32),
|
||||
),
|
||||
'password' => array(
|
||||
'not_empty' => NULL,
|
||||
'min_length' => array(5),
|
||||
'max_length' => array(42),
|
||||
),
|
||||
'password_confirm' => array(
|
||||
'matches_ifset' => array('password'),
|
||||
),
|
||||
'email' => array(
|
||||
'not_empty' => NULL,
|
||||
'min_length' => array(4),
|
||||
'max_length' => array(127),
|
||||
'email' => NULL,
|
||||
),
|
||||
);
|
||||
public function rules() {
|
||||
return array(
|
||||
'username' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
array('max_length', array(':value', 32)),
|
||||
),
|
||||
'password' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 5)),
|
||||
array('max_length', array(':value', 32)),
|
||||
),
|
||||
'email' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
array('max_length', array(':value', 127)),
|
||||
array('email'),
|
||||
),
|
||||
// @todo To test
|
||||
'password_confirm' => array(
|
||||
array('matches_ifset', array(':validation', 'password', 'password_confirm')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Validation callbacks
|
||||
// @todo _callbacks no longer used
|
||||
protected $_callbacks = array(
|
||||
'username' => array('username_available'),
|
||||
'email' => array('email_available'),
|
||||
@@ -51,6 +53,7 @@ class Model_Auth_UserDefault extends Model_Auth_User {
|
||||
* here.
|
||||
*
|
||||
* We can also do some other post-login actions here.
|
||||
* @todo Maybe we can do our session update here.
|
||||
*/
|
||||
public function complete_login() {}
|
||||
|
||||
|
Reference in New Issue
Block a user