Browse Source

Fixed issue with error and modified control() to include redirect indicated in config file

develop
tswagger 10 years ago
parent
commit
1707579824
  1. 39
      application/libraries/Aauth.php

39
application/libraries/Aauth.php

@ -8,6 +8,7 @@
* *
* @author Emre Akay <emreakayfb@hotmail.com> * @author Emre Akay <emreakayfb@hotmail.com>
* @contributor Jacob Tomlinson * @contributor Jacob Tomlinson
* @contributor Tim Swagger (Renowne, LLC) <tim@renowne.com>
* *
* @copyright 2014 Emre Akay * @copyright 2014 Emre Akay
* *
@ -19,7 +20,7 @@
* The latest version of Aauth can be obtained from: * The latest version of Aauth can be obtained from:
* https://github.com/emreakay/CodeIgniter-Aauth * https://github.com/emreakay/CodeIgniter-Aauth
* *
* * @todo implement same fix for "info" as was implemented for "errors"
* *
*/ */
class Aauth { class Aauth {
@ -78,6 +79,9 @@ class Aauth {
// config/aauth.php // config/aauth.php
$this->CI->config->load('aauth'); $this->CI->config->load('aauth');
$this->config_vars = $this->CI->config->item('aauth'); $this->config_vars = $this->CI->config->item('aauth');
// load error messages from flashdata (but don't store back in flashdata)
$this->errors = $this->CI->session->flashdata('errors');
} }
@ -297,20 +301,29 @@ class Aauth {
/** /**
* Controls if a logged or public user has permission * Controls if a logged or public user has permission
* If no permission, it stops script, it also updates last activity every time function called *
* If user does not have permission to access page, it stops script and gives
* error message, unless 'no_permission' value is set in config. If 'no_permission' is
* set in config it redirects user to the set url and passes the 'no_access' error message.
* It also updates last activity every time function called.
* @param bool $perm_par If not given just control user logged in or not * @param bool $perm_par If not given just control user logged in or not
*/ */
public function control( $perm_par ){ public function control( $perm_par = false ){
$perm_id = $this->get_perm_id($perm_par); $perm_id = $this->get_perm_id($perm_par);
$this->update_activity(); $this->update_activity();
// if user or user's group not allowed // if user or user's group not allowed
if ( ! $this->is_allowed($perm_id) or ! $this->is_group_allowed($perm_id) ){ if ( ! $this->is_allowed($perm_id) or ! $this->is_group_allowed($perm_id) ){
if( $this->config_vars['no_permission'] ) {
$this->error($this->CI->lang->line('no_access'));
redirect($this->config_vars['no_permission']);
}
else {
echo $this->CI->lang->line('no_access'); echo $this->CI->lang->line('no_access');
die(); die();
} }
}
} }
//tested //tested
@ -1632,19 +1645,21 @@ class Aauth {
# Error / Info Functions # Error / Info Functions
######################## ########################
//tested
/** /**
* Error * Error
* Add message to error array and set flash data * Add message to error array and set flash data
* @param string $message Message to add to array * @param string $message Message to add to array
* @param boolean $flashdata if true add $message to CI flashdata (deflault: true)
*/ */
public function error($message){ public function error($message = '', $flashdata = true){
$this->errors[] = $message; $this->errors[] = $message;
if($flashdata) {
$this->CI->session->set_flashdata('errors', $this->errors); $this->CI->session->set_flashdata('errors', $this->errors);
} }
}
//not working //not working
// NOTE: this should now be working.
/** /**
* Keep Errors * Keep Errors
* keeps the flash data flash data * keeps the flash data flash data
@ -1693,6 +1708,16 @@ class Aauth {
echo $msg; echo $msg;
} }
/**
* Clear Errors
*
* Removes errors from error list and clears all flashdata
*/
public function clear_errors() {
$this->errors = [];
$this->CI->session->set_flashdata('errors', $this->errors);
}
//tested //tested
/** /**
* Info * Info

Loading…
Cancel
Save