OSB enhancements to date
This commit is contained in:
@@ -92,8 +92,30 @@ class account extends OSB_module {
|
||||
/** SMARTY METHODS **/
|
||||
|
||||
/**
|
||||
* Get authorized groups
|
||||
* Get a list of groups to which an account is a member of
|
||||
*
|
||||
* Accounts are always a member of group 0/2 (All Un & Registered Users)
|
||||
*/
|
||||
public function sAccountGroups($account_id) {
|
||||
static $CACHE = array();
|
||||
|
||||
if (! isset($CACHE[$account_id])) {
|
||||
$db = &DB();
|
||||
|
||||
$rs = $db->Execute(sqlSelect($db,'account_group','group_id',sprintf('group_id>2 AND active=1 AND account_id=%s',$account_id)));
|
||||
$CACHE[$account_id] = array(0,2);
|
||||
if ($rs && $rs->RecordCount()) {
|
||||
while (! $rs->EOF) {
|
||||
array_push($CACHE[$account_id],$rs->fields['group_id']);
|
||||
$rs->MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $CACHE[$account_id];
|
||||
}
|
||||
|
||||
// @todo Use sAccountGroups() in this method
|
||||
public function user_get_auth_groups($VAR) {
|
||||
global $smarty,$C_auth;
|
||||
|
||||
@@ -103,16 +125,17 @@ class account extends OSB_module {
|
||||
# Get groups for this account
|
||||
$authgrp = array();
|
||||
if (! empty($VAR['id'])) {
|
||||
$grs = $db->Execute(sqlSelect($db,'account_group','group_id',sprintf('group_id>2 AND active=1 AND account_id=%s',$VAR['id'])));
|
||||
if ($grs && $grs->RecordCount()) {
|
||||
while (! $grs->EOF) {
|
||||
$authgrp[$grs->fields['group_id']] = true;
|
||||
$grs->MoveNext();
|
||||
$rs = $db->Execute(sqlSelect($db,'account_group','group_id',sprintf('group_id>2 AND active=1 AND account_id=%s',$VAR['id'])));
|
||||
|
||||
if ($rs && $rs->RecordCount()) {
|
||||
while (! $rs->EOF) {
|
||||
$authgrp[$rs->fields['group_id']] = true;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rs = $db->Execute(sqlSelect($db,'group','id,name',sprintf('id IN (%s) AND id > 2',implode(',',$C_auth->group))));
|
||||
|
||||
if ($rs && $rs->RecordCount()) {
|
||||
while (! $rs->EOF) {
|
||||
$gid = $rs->fields['id'];
|
||||
@@ -609,9 +632,7 @@ class account extends OSB_module {
|
||||
$limit = $result->fields['date_orig']+$LIMIT_SECONDS;
|
||||
|
||||
if ($limit>time()) {
|
||||
$error1 = $C_translate->translate('password_reset_spam_limit',$this->module,'');
|
||||
$error = str_replace('%limit%',$LIMIT_SECONDS,$error1);
|
||||
$C_debug->alert($error);
|
||||
$C_debug->alert(sprintf(_('You have already submitted the password reset request for this account within the past %s seconds, please wait to try again'),$LIMIT_SECONDS));
|
||||
|
||||
return;
|
||||
|
||||
@@ -640,7 +661,7 @@ class account extends OSB_module {
|
||||
$my->send('account_reset_password',$account,'','',$now,false);
|
||||
|
||||
# ALERT: we have sent an email to you....
|
||||
$C_debug->alert($C_translate->translate('password_reset_sent',$this->module,''));
|
||||
$C_debug->alert(_('Thank you, we have sent an email to your email address on file with a link for changing your password. The link is valid for 15 minutes only, so be sure to check your email right away.'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -914,9 +935,9 @@ class account extends OSB_module {
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
public function __construct($id=null) {
|
||||
if (! defined('AJAX'))
|
||||
parent::__construct();
|
||||
parent::__construct($id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1084,6 +1105,8 @@ class account extends OSB_module {
|
||||
$where = sprintf('(username LIKE "%s%%" OR first_name LIKE "%s%%" OR last_name LIKE "%s%%" OR company LIKE "%s%%")',
|
||||
$VAR[$field],$VAR[$field],$VAR[$field],$VAR[$field]);
|
||||
|
||||
$where .= 'AND status=1';
|
||||
|
||||
if (! preg_match("/{$return}/",$fieldlist))
|
||||
$fieldlist .= ','.$return;
|
||||
|
||||
@@ -1095,8 +1118,8 @@ class account extends OSB_module {
|
||||
|
||||
if ($result->RecordCount() > 0) {
|
||||
while (! $result->EOF) {
|
||||
printf('<li><div class="name"><b>%s %s</b></div><div class="email"><span class="informal">%s</span></div><div class="index" style="display:none">%s</div></li>',
|
||||
$result->fields['first_name'],$result->fields['last_name'],$result->fields['email'],$result->fields[$return]);
|
||||
printf('<li><div class="name"><b>%s %s (%s)</b></div><div class="email"><span class="informal">%s</span></div><div class="index" style="display:none">%s</div></li>',
|
||||
$result->fields['first_name'],$result->fields['last_name'],$result->fields['username'],$result->fields['email'],$result->fields[$return]);
|
||||
|
||||
$result->MoveNext();
|
||||
}
|
||||
@@ -1774,13 +1797,13 @@ class account extends OSB_module {
|
||||
}
|
||||
|
||||
# Get invoice details for this account
|
||||
$view = $db->SelectLimit(sqlSelect($db,'invoice','id,date_orig,total_amt,billed_amt,process_status',array('account_id'=>$VAR['id']),'id DESC'),10);
|
||||
$view = $db->SelectLimit(sqlSelect($db,'invoice','id,date_orig,total_amt,IFNULL(credit_amt,0) as credit_amt,status,billed_amt,process_status',array('account_id'=>$VAR['id']),'id DESC'),10);
|
||||
if ($view && $view->RecordCount() > 0) {
|
||||
$smart['invoice'] = array();
|
||||
|
||||
while (! $view->EOF) {
|
||||
if ($view->fields['total_amt'] > $view->fields['billed_amt'] && $view->fields['suspend_billing'] != 1)
|
||||
$view->fields['due'] = $view->fields['total_amt']-$view->fields['billed_amt'];
|
||||
$view->fields['due'] = round($view->fields['total_amt']-$view->fields['billed_amt']-$view->fields['credit_amt'],2);
|
||||
|
||||
array_push($smart['invoice'],$view->fields);
|
||||
$view->MoveNext();
|
||||
@@ -1798,6 +1821,18 @@ class account extends OSB_module {
|
||||
}
|
||||
}
|
||||
|
||||
# Get payment details for this account
|
||||
$rs = $db->SelectLimit(sqlSelect($db,array('payment','payment_item'),'A.id,A.date_payment,A.total_amt,SUM(B.alloc_amt) AS alloc_amt',
|
||||
sprintf('A.account_id=%s AND B.payment_id=A.id',$VAR['id']),'A.date_payment DESC','','','B.payment_id'),10);
|
||||
if ($rs && $rs->RecordCount() > 0) {
|
||||
$smart['payment'] = array();
|
||||
|
||||
while (! $rs->EOF) {
|
||||
array_push($smart['payment'],$rs->fields);
|
||||
$rs->MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
# Get invoices to be generated for this account
|
||||
include_once(PATH_MODULES.'invoice/invoice.inc.php');
|
||||
$invoice = new invoice;
|
||||
|
@@ -108,9 +108,6 @@
|
||||
<convert>md5</convert>
|
||||
<display>Password</display>
|
||||
</password>
|
||||
<inherit_group>
|
||||
<type>L</type>
|
||||
</inherit_group>
|
||||
<!-- @unknown? -->
|
||||
<misc>
|
||||
<type>C2(128)</type>
|
||||
@@ -233,10 +230,10 @@
|
||||
<user_view>id,parent_id,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id,max_child</user_view>
|
||||
<delete>id</delete>
|
||||
<add>search,date_expire,language_id,country_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip</add>
|
||||
<update>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child</update>
|
||||
<view>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child</view>
|
||||
<update>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child</update>
|
||||
<view>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child</view>
|
||||
<search>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child</search>
|
||||
<search_export>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,tax_id,max_child</search_export>
|
||||
<search_export>id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,tax_id,max_child</search_export>
|
||||
<export_excel>language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id</export_excel>
|
||||
<export_xml>language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id</export_xml>
|
||||
<export_csv>language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id</export_csv>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<date_last>1112335769</date_last>
|
||||
<date_expire>0</date_expire>
|
||||
<parent_id>0</parent_id>
|
||||
<language_id>english</language_id>
|
||||
<language_id>en</language_id>
|
||||
<country_id>840</country_id>
|
||||
<reseller_id>0</reseller_id>
|
||||
<currency_id>1</currency_id>
|
||||
|
289
modules/account/classes/auth/osb.php
Normal file
289
modules/account/classes/auth/osb.php
Normal file
@@ -0,0 +1,289 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* OSB Auth driver.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Account
|
||||
* @category Auth
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.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
|
||||
$user = $this->get_user(FALSE);
|
||||
|
||||
// If we are not a valid user object, then we are not logged in
|
||||
if (is_object($user) AND $user instanceof Model_Account AND $user->loaded()) {
|
||||
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT && Kohana::config('config.site_debug'))
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Kohana::debug(array('user'=>$user->username,'r'=>$role))));
|
||||
|
||||
if (! empty($role)) {
|
||||
// Get the module details
|
||||
$module = ORM::factory('module',array('name'=>Request::instance()->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),
|
||||
));
|
||||
|
||||
} else {
|
||||
if (Request::instance()->directory)
|
||||
$method_name = sprintf('%s_%s',Request::instance()->directory,Request::instance()->action);
|
||||
else
|
||||
$method_name = Request::instance()->action;
|
||||
|
||||
// Get the method number
|
||||
$method = ORM::factory('module_method',array('module_id'=>$module->id,'name'=>$method_name));
|
||||
if (! $method->loaded()) {
|
||||
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),
|
||||
));
|
||||
|
||||
} else {
|
||||
// If the role has the authorisation to run the method
|
||||
$group_method = ORM::factory('group_method')
|
||||
->where('method_id','=',$method->id);
|
||||
|
||||
$roles = '';
|
||||
foreach ($group_method->find_all() as $gm) {
|
||||
$roles .= ($roles ? '|' : '').$gm->group->name;
|
||||
|
||||
$ro = ORM::factory('group', array('name' => $gm->group->name));
|
||||
|
||||
// $ro->id == 0 means all users.
|
||||
if ($ro->id == 0 OR $user->has('group', $ro)) {
|
||||
$status = TRUE;
|
||||
$roles = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $status) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>'User is not authorised in Database',
|
||||
'type'=>'debug',
|
||||
'body'=>sprintf('Role(s) checked: %s<br/>User: %s</br>Module: %s<br/>Method: %s',$roles,$user->username,$module->name,$method->name),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'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)));
|
||||
|
||||
// There is no role, so the method should be allowed to run as anonymous
|
||||
} else {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'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)));
|
||||
|
||||
$status = TRUE;
|
||||
}
|
||||
|
||||
// Check and see if we have a token to login and run the method
|
||||
} elseif ((! empty($_REQUEST['token']) AND $token = $_REQUEST['token']) OR $token=Session::instance()->get('token')) {
|
||||
|
||||
if ($user=$this->_get_token_user($token) AND $user !== FALSE)
|
||||
$status = TRUE;
|
||||
|
||||
} else {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>'No user logged in'));
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently logged in user from the session.
|
||||
* Returns FALSE if no user is currently logged in.
|
||||
*
|
||||
* @param boolean Check token users too
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_user($tokenuser=TRUE) {
|
||||
$user = parent::get_user();
|
||||
|
||||
// If we are not logged in, see if there is token for the usre
|
||||
if ($tokenuser AND $user === FALSE AND $token=Session::instance()->get('token')) {
|
||||
$user = $this->_get_token_user($token);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that a token applies to
|
||||
*
|
||||
* This will check that the token is valid (not expired and for the request)
|
||||
*
|
||||
* @param $token The token
|
||||
* @return mixed The user
|
||||
*/
|
||||
private function _get_token_user($token) {
|
||||
$mmto = ORM::factory('module_method_token',array('token'=>$token));
|
||||
$request = Request::instance();
|
||||
$user = FALSE;
|
||||
|
||||
if ($mmto->loaded()) {
|
||||
if ($mmto->date_expire < time()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Token Not Valid'),
|
||||
'type'=>'warning',
|
||||
'body'=>_('Token expired')));
|
||||
|
||||
Session::instance()->delete('token');
|
||||
$mmto->delete();
|
||||
|
||||
} else {
|
||||
// Check that the token is for this URI
|
||||
$mo = ORM::factory('module',array('name'=>$request->controller));
|
||||
$mmo = ORM::factory('module_method',
|
||||
array('name'=>$request->directory ? sprintf('%s_%s',$request->directory,$request->action) : $request->action));
|
||||
|
||||
// Ignore the token if this is not the right method.
|
||||
if ($mmo->id == $mmto->method_id) {
|
||||
// @todo Implement single use tokens
|
||||
Session::instance()->set('token',$token);
|
||||
|
||||
$user = ORM::factory('account',$mmto->account_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a user in.
|
||||
*
|
||||
* @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('user');
|
||||
$user->where($user->unique_key($username), '=', $username)->find();
|
||||
}
|
||||
|
||||
// If the passwords match, perform a login
|
||||
if ($user->has('group', ORM::factory('group', array('name' => 'Registered Users'))) AND $user->password === $password)
|
||||
{
|
||||
if ($remember === TRUE)
|
||||
{
|
||||
// Create a new autologin token
|
||||
$token = ORM::factory('user_token');
|
||||
|
||||
// Set token data
|
||||
$token->user_id = $user->id;
|
||||
$token->expires = time() + $this->_config['lifetime'];
|
||||
$token->save();
|
||||
|
||||
// Set the autologin cookie
|
||||
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
|
||||
}
|
||||
|
||||
// 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
|
||||
// @todo figure out where this is best to go
|
||||
$session_change_trigger = array('cart'=>'session_id');
|
||||
|
||||
if (count($session_change_trigger) AND (session_id() != $oldsess)) {
|
||||
foreach ($session_change_trigger as $t => $c) {
|
||||
$orm = ORM::factory($t)
|
||||
->where($c,'=',$oldsess);
|
||||
|
||||
$orm->session_id = session_id();
|
||||
$orm->save_all();
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Login failed
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the supplied find_salt() to enable disabling salt keys
|
||||
*/
|
||||
public function find_salt($password) {
|
||||
$salt = '';
|
||||
|
||||
foreach ($this->_config['salt_pattern'] as $i => $offset) {
|
||||
// Find salt characters, take a good long look...
|
||||
if (is_numeric($offset))
|
||||
$salt .= substr($password, $offset + $i, 1);
|
||||
}
|
||||
|
||||
return $salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a user is authorised to view an account
|
||||
*
|
||||
* @param integer Account ID
|
||||
*
|
||||
* @return boolean TRUE if authorised, FALSE if not.
|
||||
*/
|
||||
public function authorised($aid) {
|
||||
if (! $this->get_user())
|
||||
return FALSE;
|
||||
|
||||
// @todo Consider caching this.
|
||||
$ao = ORM::factory('account',$this->get_user()->id);
|
||||
|
||||
if (! $ao->loaded() OR ($aid != $ao->id AND ! $ao->admin()))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable KO3 hash_password function
|
||||
*/
|
||||
public function hash_password($password,$salt = FALSE) {
|
||||
return md5($password);
|
||||
}
|
||||
}
|
||||
?>
|
16
modules/account/classes/controller/account.php
Normal file
16
modules/account/classes/controller/account.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides account management
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Account
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @also [logout]
|
||||
*/
|
||||
class Controller_Account extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
115
modules/account/classes/controller/user/account.php
Normal file
115
modules/account/classes/controller/user/account.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides User Account Update functions
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Account
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_User_Account extends Controller_TemplateDefault {
|
||||
public $secure_actions = array(
|
||||
'edit'=>TRUE,
|
||||
'resetpassword'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_resetpassword() {
|
||||
$ao = Auth::instance()->get_user();
|
||||
|
||||
if (! $ao->loaded())
|
||||
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
|
||||
|
||||
// @todo Fix this next logic, since matches_ifset is not being called when the value is on the form, but empty
|
||||
if (empty($_POST['password_confirm']))
|
||||
$_POST['password_confirm'] = ' ';
|
||||
|
||||
// Store our new values
|
||||
$ao->values($_POST);
|
||||
|
||||
// Run validation and save
|
||||
if ($ao->changed())
|
||||
if ($ao->check()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record updated'),
|
||||
'type'=>'info',
|
||||
'body'=>_('Your account record has been updated.')
|
||||
));
|
||||
|
||||
$ao->save();
|
||||
Request::instance()->redirect('login');
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record NOT updated'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Your updates didnt pass validation.')
|
||||
));
|
||||
|
||||
foreach ($ao->validate()->errors('form_errors') as $field => $error)
|
||||
SystemMessage::add(array(
|
||||
'title'=>$field,
|
||||
'type'=>'error',
|
||||
'body'=>$error,
|
||||
));
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Password Reset'),
|
||||
'body'=>View::factory('account/password_reset')
|
||||
->set('record',$ao),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a product
|
||||
*/
|
||||
public function action_edit() {
|
||||
$ao = Auth::instance()->get_user();
|
||||
|
||||
if (! $ao->loaded())
|
||||
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
|
||||
|
||||
// Store our new values
|
||||
$ao->values($_POST);
|
||||
|
||||
// Run validation and save
|
||||
if ($ao->changed())
|
||||
if ($ao->check()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record updated'),
|
||||
'type'=>'info',
|
||||
'body'=>_('Your account record has been updated.')
|
||||
));
|
||||
|
||||
$ao->save();
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record NOT updated'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Your updates didnt pass validation.')
|
||||
));
|
||||
|
||||
foreach ($ao->validate()->errors('form_errors') as $field => $error)
|
||||
SystemMessage::add(array(
|
||||
'title'=>$field,
|
||||
'type'=>'error',
|
||||
'body'=>$error,
|
||||
));
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$ao->accnum(),$ao->name(TRUE)),
|
||||
'body'=>View::factory('account/edit')
|
||||
->set('record',$ao),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
}
|
||||
?>
|
76
modules/account/classes/model/account.php
Normal file
76
modules/account/classes/model/account.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Account extends Model_Auth_UserDefault {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'user_tokens' => array('model' => 'user_token'),
|
||||
'group' => array('through' => 'account_group'),
|
||||
'invoice' => array(),
|
||||
'payment'=>array(),
|
||||
'service' => array(),
|
||||
);
|
||||
|
||||
// Complete our login
|
||||
public function complete_login() {}
|
||||
|
||||
/**
|
||||
* Return an account name
|
||||
*/
|
||||
public function name($withcompany=FALSE) {
|
||||
if ($withcompany)
|
||||
return sprintf('%s %s (%s)',$this->first_name,$this->last_name,$this->company);
|
||||
else
|
||||
return sprintf('%s %s',$this->first_name,$this->last_name);
|
||||
}
|
||||
|
||||
public function accnum() {
|
||||
return sprintf('%02s-%06s',Config::siteid(),$this->id);
|
||||
}
|
||||
|
||||
public function date_last() {
|
||||
return Config::date($this->date_last);
|
||||
}
|
||||
|
||||
public function title($name) {
|
||||
return StaticList_Title::form($name,$this->title);
|
||||
}
|
||||
|
||||
public function currency($name) {
|
||||
return StaticListModule::form($name,'currency',$this->currency_id,'id','name',array());
|
||||
}
|
||||
|
||||
public function country($name) {
|
||||
return StaticListModule::form($name,'country',$this->country_id,'id','name',array());
|
||||
}
|
||||
|
||||
public function language($name) {
|
||||
// @todo To setup
|
||||
return 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the groups that an account belongs to
|
||||
*/
|
||||
public function groups() {
|
||||
return $this->group->find_all()->as_array();
|
||||
}
|
||||
|
||||
public function admin() {
|
||||
// @todo Define admins in the config file or DB
|
||||
$admins = array('Root');
|
||||
|
||||
foreach ($this->groups() as $go)
|
||||
if (in_array($go->name,$admins))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
54
modules/account/classes/model/auth/roledefault.php
Normal file
54
modules/account/classes/model/auth/roledefault.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
?>
|
77
modules/account/classes/model/auth/userdefault.php
Normal file
77
modules/account/classes/model/auth/userdefault.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @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,
|
||||
),
|
||||
);
|
||||
|
||||
// Validation callbacks
|
||||
protected $_callbacks = array(
|
||||
'username' => array('username_available'),
|
||||
'email' => array('email_available'),
|
||||
);
|
||||
|
||||
// Columns to ignore
|
||||
protected $_ignored_columns = array('password_confirm');
|
||||
|
||||
/*
|
||||
* 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() {}
|
||||
|
||||
/**
|
||||
* Test to see if a record has been changed
|
||||
*/
|
||||
public function changed() {
|
||||
return ! (empty($this->_changed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug function to see that has() finds
|
||||
* @todo This function could be removed
|
||||
*/
|
||||
public function has_list($alias, $model) {
|
||||
// Return list of matches
|
||||
return DB::select()
|
||||
->from($this->_has_many[$alias]['through'])
|
||||
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
|
||||
->where($this->_has_many[$alias]['far_key'], '=', $model->pk())
|
||||
->execute($this->_db)
|
||||
->as_array();
|
||||
}
|
||||
}
|
84
modules/account/views/account/edit.php
Normal file
84
modules/account/views/account/edit.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<?php echo Form::open(); ?>
|
||||
<table class="box-center">
|
||||
<tr>
|
||||
<td class="head">Last Updated</td>
|
||||
<td><?php echo $record->date_last(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">User Name</td>
|
||||
<td><b><?php echo $record->username; ?></b></td>
|
||||
</tr>
|
||||
<!-- //@todo This needs to be done somewhere else
|
||||
<tr>
|
||||
<td class="head">Password</td>
|
||||
<td><input type="password" name="password" value=""/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Confirm Password</td>
|
||||
<td><input type="password" name="confirm_password" value=""/></td>
|
||||
</tr>
|
||||
-->
|
||||
<tr>
|
||||
<td class="head">Email</td>
|
||||
<td><input type="text" name="email" value="<?php echo $record->email; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Company</td>
|
||||
<td><input type="text" name="company" value="<?php echo $record->company; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">First Name</td>
|
||||
<td><input type="text" name="first_name" value="<?php echo $record->first_name; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Last Name</td>
|
||||
<td><input type="text" name="last_name" value="<?php echo $record->last_name; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Title</td>
|
||||
<td><?php echo $record->title('title'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Address</td>
|
||||
<td><input type="text" name="address1" value="<?php echo $record->address1; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head"> </td>
|
||||
<td><input type="text" name="address2" value="<?php echo $record->address2; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">City</td>
|
||||
<td><input type="text" name="city" value="<?php echo $record->city; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">State</td>
|
||||
<td><input type="text" name="state" value="<?php echo $record->state; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Postal Code</td>
|
||||
<td><input type="text" name="zip" value="<?php echo $record->zip; ?>"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Country</td>
|
||||
<td><?php echo $record->country('country'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Language</td>
|
||||
<td><?php echo $record->language('language_id'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Currency</td>
|
||||
<td><?php echo $record->currency('currency_id'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- @todo NEEDS TO BE CONFIGURABLE -->
|
||||
<td class="head">HTML Email</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
<!-- @todo OTHER STATIC VARS -->
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;"><?php echo Form::submit('update','Update'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php echo Form::close(); ?>
|
16
modules/account/views/account/password_reset.php
Normal file
16
modules/account/views/account/password_reset.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<?php echo Form::open(); ?>
|
||||
<table class="box-center">
|
||||
<tr>
|
||||
<td class="head">Password</td>
|
||||
<td><input type="password" name="password" value=""/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="head">Confirm Password</td>
|
||||
<td><input type="password" name="password_confirm" value=""/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;"><?php echo Form::submit('update','Update'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php echo Form::close(); ?>
|
135
modules/account/views/bregister.php
Normal file
135
modules/account/views/bregister.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<br/>
|
||||
<?php echo Form::open(); ?>
|
||||
<table class="login">
|
||||
<tr>
|
||||
<td>User Name</td>
|
||||
<td><?php echo Form::input('username',$account->username,
|
||||
array('id'=>'login-uid','size'=>40,'class'=>(array_key_exists('username',$errors) ? 'error' : 'ok'))); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password</td>
|
||||
<td><?php echo Form::password('password',null,array('id'=>'login-pwd','size'=>16));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Confirm Password</td>
|
||||
<td><?php echo Form::password('password_confirm',null,array('id'=>'login-pwd-confirm','size'=>16));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Email Address</td>
|
||||
<td><?php echo Form::input('email',$account->email,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Company</td>
|
||||
<td><?php echo Form::input('company',$account->company,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>First Name</td>
|
||||
<td><?php echo Form::input('first_name',$account->first_name,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Last Name</td>
|
||||
<td><?php echo Form::input('last_name',$account->last_name,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td><?php echo StaticList_Title::form('title',$account->title);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Address Line 1</td>
|
||||
<td><?php echo Form::input('address1',$account->address1,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Address Line 2</td>
|
||||
<td><?php echo Form::input('address2',$account->address2,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>City</td>
|
||||
<td><?php echo Form::input('city',$account->city,array('size'=>40));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>State</td>
|
||||
<td><?php echo Form::input('state',$account->state,array('size'=>20));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Post Code</td>
|
||||
<td><?php echo Form::input('zip',$account->zip,array('size'=>20));?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Country</td>
|
||||
<!-- @todo - our default currency should be defined in a config -->
|
||||
<td><?php echo StaticList_Module::form('country_id','country',61,'id','name',array());?></td>
|
||||
<!--
|
||||
{if $VAR.account_country_id != ''}
|
||||
{$list->menu('no','account_country_id','country','name',$VAR.account_country_id,'form_field" onchange="taxIdsDisplay(this.value)',true)}
|
||||
{else}
|
||||
{$list->menu('no','account_country_id','country','name',$smarty.const.DEFAULT_COUNTRY,'form_field" onchange="taxIdsDisplay(this.value)',true)}
|
||||
{/if}
|
||||
|
||||
{$method->exe_noauth('tax','get_tax_ids')}
|
||||
{if $tax_ids}
|
||||
<script type="text/javascript" language="javascript">
|
||||
{if $VAR.account_country_id != ""}
|
||||
var countryId='{$VAR.account_country_id}';
|
||||
{else}
|
||||
var countryId='{$smarty.const.DEFAULT_COUNTRY}';
|
||||
{/if}
|
||||
{literal}
|
||||
function taxIdsDisplay(id) {
|
||||
try{ document.getElementById('tax_country_id_'+id).style.display='block'; } catch(e) {}
|
||||
try{ document.getElementById('tax_country_id_'+countryId).style.display='none'; } catch(e) {}
|
||||
countryId=id;
|
||||
}
|
||||
{/literal}
|
||||
</script>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{foreach from=$tax_ids item=tax}
|
||||
<tr valign="top" id="tax_country_id_{$tax.country_id}" {if $VAR.account_country_id !=''}{if $VAR.account_country_id!=$tax.country_id}{osb f=style_hide}{/if}{else}{if $smarty.const.DEFAULT_COUNTRY!=$tax.country_id}{osb f=style_hide}{/if}{/if}>
|
||||
<td width="29%">{$tax.tax_id_name}</td>
|
||||
<td width="71%">
|
||||
<input type="text" name="account_tax_id[{$tax.country_id}]" value="{$VAR.account_tax_id[$tax.country_id]}" {if $account_tax_id == true}class="form_field_error"{/if}/>
|
||||
<!-* {if $tax.tax_id_exempt}
|
||||
(or) exempt
|
||||
<input type="checkbox" name="account_tax_id_exempt[{$tax.country_id}]" value="1"/>
|
||||
{/if} -*>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</td>
|
||||
-->
|
||||
</tr>
|
||||
|
||||
<!--
|
||||
{$method->exe('account','static_var')}
|
||||
{foreach from=$static_var item=record}
|
||||
<tr valign="top">
|
||||
<td>{$record.name}</td>
|
||||
<td>{$record.html}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
-->
|
||||
<!--
|
||||
{if $smarty.const.NEWSLETTER_REGISTRATION == "1"}
|
||||
<tr valign="top">
|
||||
<td>{t module=account}subscribe_newsletters{/t}</td>
|
||||
<td>{$method->exe('newsletter','check_list_registration')}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
-->
|
||||
|
||||
<tr>
|
||||
<td>Use HTML for Email</td>
|
||||
<!-- // @todo default should be specified in a global confi -->
|
||||
<td><?php echo StaticList_YesNo::form('email_type',true); ?></td>
|
||||
</tr>
|
||||
<tr><td colspan="2"> </td></tr>
|
||||
<tr><td colspan="2" style="text-align: center;"><?php echo Form::submit('submit',_('Register'));?></td></tr>
|
||||
</table>
|
||||
<?php echo Form::close(); ?>
|
||||
<!-- @todo The following focus() is not ajax/jscript friendly -->
|
||||
<!-- @todo Provide field validation highlighting -->
|
||||
<!-- @todo Add javascript to stop submission when password fields dont match -->
|
||||
<script type="text/javascript">document.getElementById('login-uid').focus();</script>
|
||||
|
Reference in New Issue
Block a user