Changeset 64

Show
Ignore:
Timestamp:
04/13/07 06:32:15
Author:
grahack
Message:

FAL: enhancement or the denying process + link to example in the nav (example now in a view)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/public/css/style.css

    r2 r64  
    112112padding-bottom: 24px; 
    113113margin: 0; 
    114 margin-left: 250px;} 
     114margin-left: 190px;} 
    115115 
    116116ul#navlist li {float: left; 
  • FreakAuth/trunk/www/system/application/config/freakauth_light.php

    r36 r64  
    2323 
    2424$config['FAL'] = TRUE;                                    //TRUE/FALSE (boolean).  Whether the FreakAuth system is turned on. 
     25 
     26$config['FAL_flash'] = TRUE; //boolean: if TRUE uses FLASH messages and redirect if not allowed 
     27                                                         //                     if FALSE loads the page you defined in $config['FAL_denied_page'] 
     28$config['FAL_denied_page'] = 'FreakAuth_light/template/denied'; //if we don't want to use a flash message 
     29                                                        //the page/view we want to load to display the deny message 
    2530 
    2631$config['FAL_create_user_profile'] = TRUE;      //TRUE/FALSE (boolean).  Whether to use custom user profile 
  • FreakAuth/trunk/www/system/application/controllers/example.php

    r56 r64  
    1414                  function index() 
    1515                  { 
    16                   
    17                         echo '<h1>You can view this message because you logged in and are at least an user!</h1>'; 
    18                         echo 'You are <b>'.getUserName().'</b> (role:<b>'.getUserProperty('role').'</b>),'; 
    19                         echo ' your id is <b>'.getUserProperty('id').'</b>.<br />'; 
    20                         echo 'Your superadmin is <b>'.getUserPropertyFromId(1,'user_name').'</b>.'; 
     16              $this->load->view($this->config->item('FAL_template_dir').'template/example'); 
    2117                  } 
    2218} 
  • FreakAuth/trunk/www/system/application/libraries/Freakauth_light.php

    r56 r64  
    128128    function check($_lock_to_role=null, $_only=null) 
    129129    { 
    130                  
    131130 
    132131                //check who did the request and build role hierarchy 
     
    166165                    if ($_condition==false) 
    167166                    { 
    168                         //set a flash message 
    169                                 $msg = "You do not have the credentials to access this reserved area"; 
    170                                         $this->CI->db_session->set_flashdata('flashMessage', $msg, 1); 
    171                         redirect('', 'location'); 
    172                     }    
     167                        $this->deny($_who_is); 
     168                    } 
    173169                } 
    174170                //it means it is a guest because it has no role stored in DB_session  
    175                 else  
    176                 {  
    177                 redirect('auth/index', 'location'); 
     171                else 
     172                { 
     173                    $this->deny($_who_is); 
    178174                } 
    179175    } 
    180176 
     177    // -------------------------------------------------------------------- 
     178 
     179    /** 
     180     * Handles the case where the one who did the request 
     181     * doesn't have enough credentials 
     182     * 
     183     * if FAL_flash == true in config file, displays a flash message 
     184     *      and redirect to the referer page (or root if none) 
     185     * 
     186     * else displays the FAL_denied_page (see config file) 
     187     * 
     188     * @param $role : the role of the one we are denying the access 
     189     */ 
     190    function deny($role) 
     191    { 
     192        $this->CI->lang->load('freakauth'); 
     193        if ($this->CI->config->item('FAL_flash')) 
     194        { 
     195            if ($role == '') 
     196            { 
     197                $msg = $this->CI->lang->line('FAL_no_credentials_guest'); 
     198                $this->CI->db_session->set_flashdata('flashMessage', $msg, 1); 
     199                redirect('auth', 'location'); 
     200                exit(); 
     201            } 
     202            else 
     203            { 
     204                $msg = $this->CI->lang->line('FAL_no_credentials_user'); 
     205                $this->CI->db_session->set_flashdata('flashMessage', $msg, 1); 
     206                 
     207                // redirect where we were previously 
     208                if (isset($_SERVER['HTTP_REFERER'])) 
     209                { 
     210                    header("location:".$_SERVER['HTTP_REFERER']); 
     211                    exit(); 
     212                } 
     213                else 
     214                { 
     215                    redirect('', 'location'); 
     216                } 
     217                exit(); 
     218            } 
     219        } 
     220        else 
     221        { 
     222            $page = $this->CI->config->item('FAL_denied_page'); 
     223            $data['role'] = $role; 
     224            // this is how we stop the execution 
     225            echo $this->CI->load->view($page, $data, true); 
     226            exit(); 
     227        } 
     228    } 
     229     
     230     
     231     
    181232    // -------------------------------------------------------------------- 
    182233 
  • FreakAuth/trunk/www/system/application/views/FreakAuth_light/template/menu.php

    r2 r64  
    22                <ul id="navlist"> 
    33                        <li id="active"><?=anchor('', 'home')?></li> 
    4                         <li><?=anchor('auth/', 'login')?></li> 
     4                        <li><?=anchor('example', 'example')?></li> 
     5                        <li><?=anchor('auth', 'login')?></li> 
    56                        <li><?=anchor('auth/register', 'register')?></li> 
    67                        <li><?=anchor('auth/forgotten_password', 'forgotten password')?></li> 
    78                        <li><?=anchor('auth/changepassword', 'change password')?></li> 
    8                         <li><?=anchor('admin/', 'admin')?></li> 
     9                        <li><?=anchor('admin', 'admin')?></li> 
    910                </ul> 
    1011        </div> 
  • FreakAuth/trunk/www/system/language/english/freakauth_lang.php

    r61 r64  
    4040 
    4141$lang['FAL_unknown_user'] = 'unknown user'; 
     42 
     43$lang['FAL_no_credentials_guest'] = 'You do not have the credentials to access this reserved area, please login and retry.'; 
     44$lang['FAL_no_credentials_user'] = 'You do not have the credentials to access this reserved area.'; 
    4245 
    4346//------------------------------------------------------------------