Skip to content

Commit

Permalink
Fixed issue with error and modified control() to include redirect ind…
Browse files Browse the repository at this point in the history
…icated in config file
  • Loading branch information
tswagger committed Feb 14, 2015
1 parent d3617a0 commit 1707579
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions application/libraries/Aauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author Emre Akay <emreakayfb@hotmail.com>
* @contributor Jacob Tomlinson
* @contributor Tim Swagger (Renowne, LLC) <tim@renowne.com>
*
* @copyright 2014 Emre Akay
*
Expand All @@ -19,7 +20,7 @@
* The latest version of Aauth can be obtained from:
* https://github.com/emreakay/CodeIgniter-Aauth
*
*
* @todo implement same fix for "info" as was implemented for "errors"
*
*/
class Aauth {
Expand Down Expand Up @@ -78,6 +79,9 @@ public function __construct() {
// config/aauth.php
$this->CI->config->load('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');
}


Expand Down Expand Up @@ -297,20 +301,29 @@ public function is_loggedin() {

/**
* 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
*/
public function control( $perm_par ){
public function control( $perm_par = false ){

$perm_id = $this->get_perm_id($perm_par);
$this->update_activity();
$perm_id = $this->get_perm_id($perm_par);
$this->update_activity();

// if user or user's group not allowed
if ( ! $this->is_allowed($perm_id) or ! $this->is_group_allowed($perm_id) ){
echo $this->CI->lang->line('no_access');
die();
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');
die();
}
}

}

//tested
Expand Down Expand Up @@ -1632,19 +1645,21 @@ public function set_as_read_pm($pm_id){
# Error / Info Functions
########################

//tested
/**
* Error
* Add message to error array and set flash data
* @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->CI->session->set_flashdata('errors', $this->errors);
if($flashdata) {
$this->CI->session->set_flashdata('errors', $this->errors);
}
}

//not working
// NOTE: this should now be working.
/**
* Keep Errors
* keeps the flash data flash data
Expand Down Expand Up @@ -1692,6 +1707,16 @@ public function print_errors($divider = '<br />'){
}
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
/**
Expand Down

0 comments on commit 1707579

Please sign in to comment.