Moved to lnApp
This commit is contained in:
parent
f8490ed97e
commit
082e280fb6
@ -1,4 +1,4 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
class Controller_Account extends lnAuth_Controller_Account {}
|
class Controller_Login extends lnAuth_Controller_Login {}
|
||||||
?>
|
?>
|
@ -1,4 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
class Controller_User_Account extends lnAuth_Controller_User_Account {}
|
|
||||||
?>
|
|
@ -1,4 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
abstract class Model_Auth_UserDefault extends lnAuth_Model_Auth_UserDefault {}
|
|
||||||
?>
|
|
@ -1,4 +1,4 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
class Model_Method_Token extends lnAuth_Model_Method_Token {}
|
class Model_Module_Method_Token extends lnAuth_Model_Module_Method_Token {}
|
||||||
?>
|
?>
|
||||||
|
@ -9,20 +9,7 @@
|
|||||||
* @copyright (c) 2014 Deon George
|
* @copyright (c) 2014 Deon George
|
||||||
* @license http://dev.leenooks.net/license.html
|
* @license http://dev.leenooks.net/license.html
|
||||||
*/
|
*/
|
||||||
class lnAuth_Auth_ORM extends Kohana_Auth_ORM {
|
abstract class lnAuth_Auth_ORM extends lnApp_Auth_ORM {
|
||||||
/**
|
|
||||||
* We need to override Kohana's __construct(), for tasks, which attempt to open a session
|
|
||||||
* and probably dont have access to PHP sessions path.
|
|
||||||
* Tasks dont need sessions anyway?
|
|
||||||
*/
|
|
||||||
public function __construct($config = array()) {
|
|
||||||
// Save the config in the object
|
|
||||||
$this->_config = $config;
|
|
||||||
|
|
||||||
if (PHP_SAPI !== 'cli')
|
|
||||||
parent::__construct($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user that a token applies to
|
* Get the user that a token applies to
|
||||||
*
|
*
|
||||||
@ -31,7 +18,7 @@ class lnAuth_Auth_ORM extends Kohana_Auth_ORM {
|
|||||||
* @param $token The token
|
* @param $token The token
|
||||||
* @return Model_Account|NULL The user that the token is valid for.
|
* @return Model_Account|NULL The user that the token is valid for.
|
||||||
*/
|
*/
|
||||||
private function _get_token_user($token) {
|
protected function _get_token_user($token) {
|
||||||
// This has been implemented, as we sometimes we seem to come here twice
|
// This has been implemented, as we sometimes we seem to come here twice
|
||||||
static $uo = NULL;
|
static $uo = NULL;
|
||||||
|
|
||||||
@ -89,104 +76,7 @@ class lnAuth_Auth_ORM extends Kohana_Auth_ORM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a user in.
|
* Authentication is controlled via database queries.
|
||||||
*
|
|
||||||
* @param string username
|
|
||||||
* @param string password
|
|
||||||
* @param boolean enable autologin
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
protected function _login($user,$password,$remember) {
|
|
||||||
if (! is_object($user)) {
|
|
||||||
$username = $user;
|
|
||||||
|
|
||||||
// Load the user
|
|
||||||
$user = ORM::factory($this->_model);
|
|
||||||
$user->where('email','=',$username)->find();
|
|
||||||
|
|
||||||
// If no user loaded, return
|
|
||||||
if (! $user->loaded())
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a hashed password
|
|
||||||
if (is_string($password))
|
|
||||||
$password = $this->hash($password);
|
|
||||||
|
|
||||||
// If we have the right password, we'll check the status of the account
|
|
||||||
if ($user->password === $password AND $user->active) {
|
|
||||||
// Record our session ID, we may need to update our DB when we get a new ID
|
|
||||||
$oldsess = session_id();
|
|
||||||
|
|
||||||
// Finish the login
|
|
||||||
$this->complete_login($user);
|
|
||||||
|
|
||||||
// Do we need to update databases with our new sesion ID
|
|
||||||
$sct = Kohana::$config->load('config')->session_change_trigger;
|
|
||||||
if (session_id() != $oldsess AND count($sct))
|
|
||||||
foreach ($sct as $t => $c)
|
|
||||||
if (Config::module_exist($t))
|
|
||||||
foreach (ORM::factory(ucwords($t))->where($c,'=',$oldsess)->find_all() as $o)
|
|
||||||
$o->set('session_id',session_id())
|
|
||||||
->update();
|
|
||||||
|
|
||||||
if (! $user->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE)))
|
|
||||||
HTTP::redirect(URL::link('user','account/activate'));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login failed
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a user is authorised to view an account
|
|
||||||
*
|
|
||||||
* @param Model_Account Account Ojbect to validate if the current user has access
|
|
||||||
* @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))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
// If we are a CLI, we are not logged in
|
|
||||||
if (PHP_SAPI === 'cli')
|
|
||||||
throw new Kohana_Exception('Calling :method from the CLI is not allowed!',array(':method'=>__METHOD__));
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_groups() {
|
|
||||||
return is_null($x=$this->get_user()) ? ORM::factory('Group')->where('id','=',0)->find_all() : $x->groups();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override Kohana Auth requirement to have a hash_key
|
|
||||||
public function hash($str) {
|
|
||||||
switch ($this->_config['hash_method']) {
|
|
||||||
case '' : return $str;
|
|
||||||
case 'md5': return md5($str);
|
|
||||||
default: return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OSB authentication is controlled via database queries.
|
|
||||||
*
|
*
|
||||||
* This method can be used to test two situations:
|
* This method can be used to test two situations:
|
||||||
* 1) Is the user logged in? ($role == FALSE)
|
* 1) Is the user logged in? ($role == FALSE)
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides account management
|
|
||||||
*
|
|
||||||
* @package lnAuth
|
|
||||||
* @category Controllers
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2014 Deon George
|
|
||||||
* @license http://dev.leenooks.net/license.html
|
|
||||||
*/
|
|
||||||
abstract class lnAuth_Controller_Account extends Controller_TemplateDefault {
|
|
||||||
}
|
|
||||||
?>
|
|
@ -74,7 +74,7 @@ abstract class lnAuth_Controller_Admin_Module extends Controller_Module {
|
|||||||
$auth_required[$cn] = $rdp['auth_required'];
|
$auth_required[$cn] = $rdp['auth_required'];
|
||||||
|
|
||||||
foreach ($r->getMethods() as $method)
|
foreach ($r->getMethods() as $method)
|
||||||
if ($method->class == $cn AND preg_match('/^action_/',$method->name))
|
if (preg_match('/^action_/',$method->name))
|
||||||
array_push($methods,str_replace('action_',strtolower($x.($sc ? '_'.$sc : '').':'),$method->name));
|
array_push($methods,str_replace('action_',strtolower($x.($sc ? '_'.$sc : '').':'),$method->name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,8 @@ abstract class lnAuth_Controller_Admin_Module_Method extends Controller_Admin_Mo
|
|||||||
Block::factory()
|
Block::factory()
|
||||||
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
|
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
|
||||||
->title_icon('icon-plus-sign')
|
->title_icon('icon-plus-sign')
|
||||||
->type('form')
|
->type('form-horizontal')
|
||||||
->body(View::factory('module/method/admin/edit')
|
->body(View::factory('module/method/admin/edit')->set('o',$mmo));
|
||||||
->set('o',$mmo)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
109
classes/lnAuth/Controller/Login.php
Normal file
109
classes/lnAuth/Controller/Login.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides Login capability
|
||||||
|
*
|
||||||
|
* @package lnAuth
|
||||||
|
* @category Controllers
|
||||||
|
* @author Deon George
|
||||||
|
* @copyright (c) 2014 Deon George
|
||||||
|
* @license http://dev.leenooks.net/license.html
|
||||||
|
*/
|
||||||
|
abstract class lnAuth_Controller_Login extends lnApp_Controller_Login {
|
||||||
|
/**
|
||||||
|
* Activate an account so that it can login and use the site
|
||||||
|
*/
|
||||||
|
public function action_activate() {
|
||||||
|
if ($this->request->post()) {
|
||||||
|
$ao = ORM::factory('Account',array('id'=>$this->request->param('id'),'email'=>$this->request->post('email')));
|
||||||
|
|
||||||
|
if ($ao->loaded()) {
|
||||||
|
if ($ao->activated())
|
||||||
|
HTTP::redirect('login');
|
||||||
|
|
||||||
|
elseif (! $ao->active) {
|
||||||
|
SystemMessage::factory()
|
||||||
|
->title(_('Account NOT Activated'))
|
||||||
|
->type('warning')
|
||||||
|
->body(_('Your account cannot been activated, please contact us.'));
|
||||||
|
|
||||||
|
} elseif ($ao->activate_code() == $this->request->post('code')) {
|
||||||
|
$go = ORM::factory('Group',array('name'=>'Registered Users'));
|
||||||
|
|
||||||
|
$ago = ORM::factory('Account_Group',array('account_id'=>$ao,'group_id'=>$go));
|
||||||
|
|
||||||
|
if (! $ago->loaded()) {
|
||||||
|
$ago->account_id=$ao;
|
||||||
|
$ago->group_id=$go;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ago->active = TRUE;
|
||||||
|
$ago->save();
|
||||||
|
|
||||||
|
SystemMessage::factory()
|
||||||
|
->title(_('Account Activated'))
|
||||||
|
->type('info')
|
||||||
|
->body(_('Your account has been activated.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
HTTP::redirect('welcome');
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif (! $this->request->param('id'))
|
||||||
|
HTTP::redirect('login/activate_resend');
|
||||||
|
|
||||||
|
Block::factory()
|
||||||
|
->title('Activate account')
|
||||||
|
->title_icon('fa-wrench')
|
||||||
|
->type('form-horizontal')
|
||||||
|
->body(View::factory('login/activate')->set('o',Session::instance()->get_once('activate'))->set('email',$this->request->query('email')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register for an account on the site
|
||||||
|
*/
|
||||||
|
public function action_register() {
|
||||||
|
$ao = ORM::factory('Account',$this->request->param('id'));
|
||||||
|
|
||||||
|
if ($this->request->post()) {
|
||||||
|
$ao->values($this->request->post());
|
||||||
|
$ao->active = "1";
|
||||||
|
|
||||||
|
if ($ao->changed() AND (! $this->save($ao)))
|
||||||
|
$ao->reload()->values($this->request->post());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ao->loaded()) {
|
||||||
|
$co = Company::instance();
|
||||||
|
|
||||||
|
// Send our email with the token
|
||||||
|
$email = Email::factory('login_activate')
|
||||||
|
->set('SITE',URL::base(TRUE,TRUE))
|
||||||
|
->set('SITE_ADMIN',$co->admin()->name())
|
||||||
|
->set('CODE',$ao->activate_code())
|
||||||
|
->set('EMAIL',$ao->email)
|
||||||
|
->set('ID',$ao->id)
|
||||||
|
->set('USER_NAME',$ao->name());
|
||||||
|
|
||||||
|
$email->to = array('email'=>array($ao->email=>$ao->name()));
|
||||||
|
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||||
|
$email->subject = 'Please activate your account for '.$co->name();
|
||||||
|
$email->deliver();
|
||||||
|
|
||||||
|
SystemMessage::factory()
|
||||||
|
->title(_('Account Registered'))
|
||||||
|
->type('info')
|
||||||
|
->body(_('Please check your email for more instructions!'));
|
||||||
|
|
||||||
|
Session::instance()->set('activate',$ao);
|
||||||
|
HTTP::redirect('login/activate/'.$ao->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Block::factory()
|
||||||
|
->type('form-horizontal')
|
||||||
|
->title('Register Account')
|
||||||
|
->title_icon('fa-edit')
|
||||||
|
->body(View::factory('account/user/edit')->set('o',$ao));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -31,9 +31,7 @@ abstract class lnAuth_Controller_TemplateDefault extends lnApp_Controller_Templa
|
|||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
|
return parent::_auth_required();
|
||||||
(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__)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function before() {
|
public function before() {
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides User Account Update functions
|
|
||||||
*
|
|
||||||
* @package lnAuth
|
|
||||||
* @category Controllers/User
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Deon George
|
|
||||||
* @license http://dev.leenooks.net/license.html
|
|
||||||
*/
|
|
||||||
abstract class lnAuth_Controller_User_Account extends Controller_Account {
|
|
||||||
protected $secure_actions = array(
|
|
||||||
'edit'=>TRUE,
|
|
||||||
'resetpassword'=>TRUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable User to Edit their Account Details
|
|
||||||
*/
|
|
||||||
public function action_edit() {
|
|
||||||
if ($_POST AND $this->ao->values($_POST)->changed() AND (! $this->save($this->ao)))
|
|
||||||
$this->ao->reload();
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('Account: %s',$this->ao->accnum()))
|
|
||||||
->title_icon('fa-wrench')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('account/user/edit')->set('o',$this->ao));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function action_resetpassword() {
|
|
||||||
if ($this->request->post()) {
|
|
||||||
$validation = Validation::factory($this->request->post())
|
|
||||||
->rule('password','not_empty')
|
|
||||||
->rule('password','min_length',array(':value',6))
|
|
||||||
->rule('password_confirm','matches',array(':validation',':field','password'));
|
|
||||||
|
|
||||||
// Store our new values
|
|
||||||
$this->ao->values($this->request->post());
|
|
||||||
|
|
||||||
if (! $validation->check())
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Record NOT updated'))
|
|
||||||
->type('error')
|
|
||||||
->body(_('Your password didnt pass validation.'));
|
|
||||||
|
|
||||||
// Run validation and save
|
|
||||||
elseif ($this->ao->changed())
|
|
||||||
if ($this->ao->save()) {
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title('Record updated')
|
|
||||||
->type('success')
|
|
||||||
->body(_('Your account record has been updated.'));
|
|
||||||
|
|
||||||
// Log the password reset
|
|
||||||
$this->ao->log('Password reset');
|
|
||||||
|
|
||||||
HTTP::redirect('login');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make this a default JS load
|
|
||||||
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure())
|
|
||||||
Script::factory()
|
|
||||||
->type('src')
|
|
||||||
->data('media/js/jquery/jquery.validate-1.11.1.min.js');
|
|
||||||
else
|
|
||||||
Script::factory()
|
|
||||||
->type('src')
|
|
||||||
->data('http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js');
|
|
||||||
|
|
||||||
Script::factory()
|
|
||||||
->type('stdin')
|
|
||||||
->data('
|
|
||||||
$("#reset").validate({
|
|
||||||
wrapper: "div",
|
|
||||||
errorElement: "span",
|
|
||||||
|
|
||||||
rules: {
|
|
||||||
password_confirm: {
|
|
||||||
equalTo: "input[name=password]",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
highlight: function(element) {
|
|
||||||
$(element).parents(".control-group").removeClass("success").addClass("error");
|
|
||||||
},
|
|
||||||
success: function(element) {
|
|
||||||
$(element).parents(".control-group").removeClass("error").addClass("success");
|
|
||||||
},
|
|
||||||
errorPlacement: function(error, element) {
|
|
||||||
error.appendTo(element.parents(".controls"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
');
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('Password Reset: %s',$this->ao->accnum()))
|
|
||||||
->title_icon('fa-cog')
|
|
||||||
->id('reset')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -36,7 +36,7 @@ abstract class lnAuth_Menu extends lnApp_Menu {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function items($type) {
|
public static function items($type,array $list=array()) {
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
if (empty(URL::$method_directory[$type]))
|
if (empty(URL::$method_directory[$type]))
|
||||||
@ -51,9 +51,6 @@ abstract class lnAuth_Menu extends lnApp_Menu {
|
|||||||
if (empty($result[$mmo->id]))
|
if (empty($result[$mmo->id]))
|
||||||
$result[$mmo->id] = $mmo;
|
$result[$mmo->id] = $mmo;
|
||||||
|
|
||||||
if ($type == 'user')
|
|
||||||
$result[0] = 'logout';
|
|
||||||
|
|
||||||
return self::collapse($result);
|
return self::collapse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* @copyright (c) 2014 Deon George
|
* @copyright (c) 2014 Deon George
|
||||||
* @license http://dev.leenooks.net/license.html
|
* @license http://dev.leenooks.net/license.html
|
||||||
*/
|
*/
|
||||||
abstract class lnAuth_Model_Account extends Model_Auth_UserDefault {
|
abstract class lnAuth_Model_Account extends lnApp_Model_Account {
|
||||||
// Relationships
|
// Relationships
|
||||||
protected $_has_many = array(
|
protected $_has_many = array(
|
||||||
'user_tokens'=>array('model'=>'user_token'),
|
'user_tokens'=>array('model'=>'user_token'),
|
||||||
@ -17,28 +17,6 @@ abstract class lnAuth_Model_Account extends Model_Auth_UserDefault {
|
|||||||
'group'=>array('through'=>'account_group'),
|
'group'=>array('through'=>'account_group'),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $_has_one = array(
|
|
||||||
'country'=>array('foreign_key'=>'id'),
|
|
||||||
'currency'=>array('foreign_key'=>'id'),
|
|
||||||
'language'=>array('foreign_key'=>'id'),
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $_display_filters = array(
|
|
||||||
'date_orig'=>array(
|
|
||||||
array('Site::Date',array(':value')),
|
|
||||||
),
|
|
||||||
'date_last'=>array(
|
|
||||||
array('Site::Date',array(':value')),
|
|
||||||
),
|
|
||||||
'active'=>array(
|
|
||||||
array('StaticList_YesNo::get',array(':value',TRUE)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $_form = array('id'=>'id','value'=>'name(TRUE)');
|
|
||||||
|
|
||||||
protected $_save_message = TRUE;
|
|
||||||
|
|
||||||
public function rules() {
|
public function rules() {
|
||||||
return Arr::merge(parent::rules(),array(
|
return Arr::merge(parent::rules(),array(
|
||||||
'id'=>array(
|
'id'=>array(
|
||||||
@ -50,50 +28,10 @@ abstract class lnAuth_Model_Account extends Model_Auth_UserDefault {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Our account number format
|
|
||||||
*/
|
|
||||||
public function accnum() {
|
|
||||||
return sprintf('%s-%04s',Company::instance()->site(TRUE),$this->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function activate_code() {
|
|
||||||
return md5(sprintf('%s-%s-%s-%s',$this->accnum(),$this->date_orig,$this->date_last,$this->email));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function activated() {
|
public function activated() {
|
||||||
return $this->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE));
|
return $this->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the groups that an account belongs to
|
|
||||||
*/
|
|
||||||
public function groups() {
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
foreach ($this->group->where_active()->find_all() as $go)
|
|
||||||
foreach ($go->list_parentgrps(TRUE) as $cgo)
|
|
||||||
if (empty($result[$cgo->id]))
|
|
||||||
$result[$cgo->id] = $cgo;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function log($message) {
|
|
||||||
// Log a message for this account
|
|
||||||
$alo = ORM::factory('Account_Log');
|
|
||||||
$alo->account_id = $this->id;
|
|
||||||
$alo->ip = Request::$client_ip;
|
|
||||||
$alo->details = $message;
|
|
||||||
$alo->save();
|
|
||||||
|
|
||||||
return $alo->saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isAdmin() {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will extract the available methods for this account
|
* This function will extract the available methods for this account
|
||||||
* This is used both for menu options and method security
|
* This is used both for menu options and method security
|
||||||
@ -116,49 +54,15 @@ abstract class lnAuth_Model_Account extends Model_Auth_UserDefault {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an account name
|
* Return a token valid for this user
|
||||||
*/
|
*/
|
||||||
public function name() {
|
public function token($token_expire,$module,$method,$uses) {
|
||||||
return trim(sprintf('%s %s',$this->first_name,$this->last_name));
|
return ORM::factory('Module_Method_Token')
|
||||||
}
|
->method(array($module,$method))
|
||||||
|
->account($this)
|
||||||
/**
|
->uses($uses)
|
||||||
* Search for accounts matching a term
|
->expire(time()+$token_expire)
|
||||||
*/
|
->generate();
|
||||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
|
||||||
$ao = Auth::instance()->get_user();
|
|
||||||
|
|
||||||
$this->clear();
|
|
||||||
$this->where_active();
|
|
||||||
|
|
||||||
// Build our where clause
|
|
||||||
// First Name, Last name
|
|
||||||
if (preg_match('/\ /',$term)) {
|
|
||||||
list($fn,$ln) = explode(' ',$term,2);
|
|
||||||
|
|
||||||
$this->where_open()
|
|
||||||
->where('first_name','like','%'.$fn.'%')
|
|
||||||
->and_where('last_name','like','%'.$ln.'%')
|
|
||||||
->where_close();
|
|
||||||
|
|
||||||
} elseif (is_numeric($term)) {
|
|
||||||
$this->where('id','like','%'.$term.'%');
|
|
||||||
|
|
||||||
} elseif (preg_match('/\@/',$term)) {
|
|
||||||
$this->where('email','like','%'.$term.'%');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$this->where_open()
|
|
||||||
->or_where('first_name','like','%'.$term.'%')
|
|
||||||
->or_where('last_name','like','%'.$term.'%')
|
|
||||||
->or_where('email','like','%'.$term.'%')
|
|
||||||
->where_close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restrict results to authorised accounts
|
|
||||||
// @todo
|
|
||||||
|
|
||||||
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default ORM profile for Authentication Accounts
|
|
||||||
*
|
|
||||||
* @package lnAuth
|
|
||||||
* @category Models
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2014 Deon George
|
|
||||||
* @license http://dev.leenooks.net/license.html
|
|
||||||
*/
|
|
||||||
abstract class lnAuth_Model_Auth_UserDefault extends Model_Auth_User {
|
|
||||||
// Validation rules
|
|
||||||
public function rules() {
|
|
||||||
return array(
|
|
||||||
'email' => array(
|
|
||||||
array('not_empty'),
|
|
||||||
array('min_length', array(':value', 4)),
|
|
||||||
array('max_length', array(':value', 127)),
|
|
||||||
array('email'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Complete our login
|
|
||||||
*
|
|
||||||
* For some database logins, we may not want to record the user last login
|
|
||||||
* details in the repository, so we just override that parent function
|
|
||||||
* here.
|
|
||||||
*
|
|
||||||
* We can also do some other post-login actions here.
|
|
||||||
*/
|
|
||||||
public function complete_login() {
|
|
||||||
return $this->log('Logged In');
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function isAdmin();
|
|
||||||
}
|
|
||||||
?>
|
|
@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* Application Module Method Model
|
* Application Module Method Model
|
||||||
*
|
*
|
||||||
* @package lnAauth
|
* @package lnAuth
|
||||||
* @category Models
|
* @category Models
|
||||||
* @author Deon George
|
* @author Deon George
|
||||||
* @copyright (c) 2014 Deon George
|
* @copyright (c) 2014 Deon George
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration - Authentication
|
|
||||||
*
|
|
||||||
* @package lnAuth
|
|
||||||
* @category Configuration
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2014 Deon George
|
|
||||||
* @license http://dev.leenooks.net/license.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'driver' => 'ORM',
|
|
||||||
'hash_method' => 'md5',
|
|
||||||
);
|
|
||||||
?>
|
|
@ -3,6 +3,4 @@
|
|||||||
return array
|
return array
|
||||||
(
|
(
|
||||||
'method_security' => TRUE, // Enable User Based method security
|
'method_security' => TRUE, // Enable User Based method security
|
||||||
'session_change_trigger'=>array( // Updates to tables to make when our session ID is changed
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
<fieldset>
|
|
||||||
<legend>Account Details</legend>
|
|
||||||
|
|
||||||
<?php echo Form::input('date_last',$o->date_last ? $o->display('date_last') : Site::date(time()),array('label'=>'Last Updated','class'=>'col-md-2','disabled')); ?>
|
|
||||||
|
|
||||||
<?php echo Form::input('email',$o->display('email'),array('label'=>'Email','class'=>'col-md-3','placeholder'=>'Email Address','type'=>'email','required','data-error'=>'Invalid EMAIL address')); ?>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-md-2 control-label" for="Title">Name</label>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-1">
|
|
||||||
<?php echo Form::select('title',StaticList_Title::table(),$o->display('title'),array('class'=>'form-control','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<?php echo Form::input('first_name',$o->display('first_name'),array('class'=>'form-control col-md-2','placeholder'=>'First Name','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<?php echo Form::input('last_name',$o->display('last_name'),array('class'=>'form-control col-md-2','placeholder'=>'Last Name','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-md-2 control-label" for="address1">Address</label>
|
|
||||||
<?php echo Form::input('address1',$o->display('address1'),array('class'=>'col-md-6','placeholder'=>'Address Line 1','required')); ?>
|
|
||||||
|
|
||||||
<label class="col-md-2 control-label" for="address2"></label>
|
|
||||||
<?php echo Form::input('address2',$o->display('address2'),array('class'=>'col-md-6','placeholder'=>'Address Line 2')); ?>
|
|
||||||
|
|
||||||
<label class="col-md-2 control-label" for="city"></label>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3">
|
|
||||||
<?php echo Form::input('city',$o->display('city'),array('label'=>'City','placeholder'=>'City','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-1">
|
|
||||||
<?php echo Form::input('state',$o->display('state'),array('label'=>'','class'=>'input-mini','placeholder'=>'State','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-1">
|
|
||||||
<?php echo Form::input('zip',$o->display('zip'),array('label'=>'','class'=>'input-mini','placeholder'=>'Post Code','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-md-2 control-label" for="address1">Country</label>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<?php echo Form::select('country_id',ORM::factory('Country')->list_select(),$o->country_id,array('class'=>'form-control','required','nocg'=>TRUE)); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php echo Form::hidden('language_id',Company::instance()->language()); ?>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-offset-1">
|
|
||||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
|
||||||
<button type="button" class="btn btn-default">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,14 +0,0 @@
|
|||||||
<div class="span11">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Reset Password</legend>
|
|
||||||
|
|
||||||
<?php echo Form::input('password','',array('label'=>'Password','type'=>'password','required','minlength'=>8)); ?>
|
|
||||||
<?php echo Form::input('password_confirm','',array('label'=>'Confirm','type'=>'password','required','minlength'=>8)); ?>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="offset2">
|
|
||||||
<button type="submit" class="btn btn-primary">Update</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> <!-- /span -->
|
|
@ -1,30 +0,0 @@
|
|||||||
<fieldset>
|
|
||||||
<legend>Activate Account</legend>
|
|
||||||
|
|
||||||
<div class="panel-body">
|
|
||||||
<p>You should have received an email with a pass code. Please enter that pass code here.</p>
|
|
||||||
|
|
||||||
<?php if (is_object($o) AND $o->loaded()) : ?>
|
|
||||||
<input type="hidden" name="email" value="<?php echo $o->email; ?>"/>
|
|
||||||
|
|
||||||
<?php else : ?>
|
|
||||||
<div class="input-group col-md-3">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-envelope fa-fw"></i></span>
|
|
||||||
<input type="email" id="email" name="email" value="" placeholder="Email" class="form-control" required />
|
|
||||||
</div>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<div class="input-group col-md-3">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-bomb fa-fw"></i></span>
|
|
||||||
<input type="text" id="code" name="code" value="" placeholder="Activation Code" class="form-control" required />
|
|
||||||
</div>
|
|
||||||
<span class="help-block">Need to <?php echo HTML::anchor(URL::link('','login/activate_resend'),'resend'); ?> it?</span>
|
|
||||||
</div> <!-- /panel-body -->
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-offset-1">
|
|
||||||
<button type="submit" class="btn btn-primary">Activate</button>
|
|
||||||
<button type="button" class="btn btn-default">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,19 +0,0 @@
|
|||||||
<fieldset>
|
|
||||||
<legend>Send Activation Code</legend>
|
|
||||||
|
|
||||||
<div class="panel-body">
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="input-group col-md-3">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-envelope fa-fw"></i></span>
|
|
||||||
<input type="email" id="email" name="email" value="" placeholder="Email" class="form-control" required />
|
|
||||||
</div>
|
|
||||||
</div> <!-- /form-group -->
|
|
||||||
</div> <!-- /panel-body -->
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-offset-1">
|
|
||||||
<button type="submit" class="btn btn-primary">Send</button>
|
|
||||||
<button type="button" class="btn btn-default">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,31 +0,0 @@
|
|||||||
<div class="center-block" style="width: 400px;">
|
|
||||||
<div class="content clearfix">
|
|
||||||
<form method="post" action="<?php echo URL::site('login/reset'); ?>">
|
|
||||||
<br/>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<div class="panel-title">Reset Password</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="panel-body">
|
|
||||||
<p>If you have forgotten your password, we can issue you a temporary access code via email that will allow you to change your password.</p>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<p>To start this process, please enter your Username. If you dont know your Username, please contact us.</p>
|
|
||||||
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-user fa-fw"></i></span>
|
|
||||||
<input type="text" id="username" name="username" value="" placeholder="Username" class="form-control" required />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="btn-group">
|
|
||||||
<button class="btn btn-default btn-large">Reset</button>
|
|
||||||
</div> <!-- /btn-group -->
|
|
||||||
</div>
|
|
||||||
</div> <!-- /panel-body -->
|
|
||||||
</div> <!-- /panel -->
|
|
||||||
</form>
|
|
||||||
</div> <!-- /content -->
|
|
||||||
</div> <!-- /center-block -->
|
|
@ -1,29 +0,0 @@
|
|||||||
<div class="center-block" style="width: 400px;">
|
|
||||||
<div class="content clearfix">
|
|
||||||
<form method="post" action="<?php echo URL::site('login/reset'); ?>">
|
|
||||||
<br/>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<div class="panel-title">Reset Password</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="panel-body">
|
|
||||||
<div class="form-group">
|
|
||||||
<p>You should have received an email with a pass code. Please enter that pass code here.</p>
|
|
||||||
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-bomb fa-fw"></i></span>
|
|
||||||
<input type="text" id="token" name="token" value="" placeholder="Token" class="form-control" required />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="btn-group">
|
|
||||||
<button class="btn btn-default btn-large">Reset</button>
|
|
||||||
</div> <!-- /btn-group -->
|
|
||||||
</div>
|
|
||||||
</div> <!-- /panel-body -->
|
|
||||||
</div> <!-- /panel -->
|
|
||||||
</form>
|
|
||||||
</div> <!-- /content -->
|
|
||||||
</div> <!-- /center-block -->
|
|
16
views/module/method/admin/add.php
Normal file
16
views/module/method/admin/add.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<div class="col-md-11">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Add Method</legend>
|
||||||
|
|
||||||
|
<?php echo Form::input('name',$name,array('label'=>'Method','disabled','divclass'=>'col-sm-5')); ?>
|
||||||
|
<?php echo Form::input('notes','',array('label'=>'Description','placeholder'=>'Method Description','divclass'=>'col-sm-7')); ?>
|
||||||
|
<?php echo Form::input('menu_display','',array('label'=>'Menu Title','placeholder'=>'Menu Title','divclass'=>'col-sm-7')); ?>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="offset2">
|
||||||
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||||
|
<button type="button" class="btn">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div> <!-- /span -->
|
41
views/module/method/admin/edit.php
Normal file
41
views/module/method/admin/edit.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<div class="col-md-5">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Method Details</legend>
|
||||||
|
|
||||||
|
<?php echo Form::input('notes',$o->notes,array('label'=>'Desc','placeholder'=>'Method Description','divclass'=>'col-md-9')); ?>
|
||||||
|
<?php echo Form::input('menu_display',$o->menu_display,array('label'=>'Title','placeholder'=>'Menu Title','divclass'=>'col-md-9')); ?>
|
||||||
|
</fieldset>
|
||||||
|
</div> <!-- /col-md-->
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Method Security</legend>
|
||||||
|
|
||||||
|
<table class="table table-striped table-condensed table-hover" id="list-table">
|
||||||
|
<thead><tr>
|
||||||
|
<th>Method</th>
|
||||||
|
<th>Notes</th>
|
||||||
|
<th>Group Active</th>
|
||||||
|
<th>Method Enable</th>
|
||||||
|
</tr></thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<?php foreach (ORM::factory('Group')->find_all() as $go) : ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo HTML::anchor(URL::link('admin','group/edit/'.$go->id,TRUE),$go->display('name')); ?></td>
|
||||||
|
<td><?php echo $go->display('notes'); ?></td>
|
||||||
|
<td><?php echo $go->display('active'); ?></td>
|
||||||
|
<td><?php echo Form::checkbox('groups[]',$go->id,$o->has('group',$go),array('nocg'=>TRUE)); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-offset-2">
|
||||||
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||||
|
<button type="button" class="btn">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div> <!-- /col-md -->
|
Reference in New Issue
Block a user