Changeset 283

Show
Ignore:
Timestamp:
06/03/07 03:41:08
Author:
grahack
Message:

redirect to the requested page after login functionality, uses the flashdata key requested_page (see #24)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/system/application/libraries/FAL_front.php

    r276 r283  
    158158    function login() 
    159159    {    
    160         //if an user, admin or superadmin is already logged in 
     160        //if a valid user is already logged in 
    161161        if($this->CI->freakauth_light->belongsToGroup('user')) 
    162162        { 
    163              // Display user name and an 'already logged in' flash message... 
    164             $msg = $this->CI->freakauth_light->getUserName().', '.$this->CI->lang->line('FAL_already_logged_in_msg'); 
     163            // we can arrive here after two different things 
     164            $requested_page = $this->CI->db_session->flashdata('requested_page'); 
     165            if ( $requested_page == '') 
     166            { 
     167                // a simple click on the login link 
     168                // Display user name and an 'already logged in' flash message... 
     169                $msg = $this->CI->freakauth_light->getUserName().', '.$this->CI->lang->line('FAL_already_logged_in_msg'); 
     170            } 
     171            else 
     172            { 
     173                // a lack of credentials after being redirected by the 
     174                // 'redirect to requested page' process 
     175                // (after a successful login that followed a denied access) 
     176                $msg = $this->CI->lang->line('FAL_no_credentials_user'); 
     177            } 
    165178            flashMsg($msg); 
    166179    
    167             //redirects to homepage 
     180            // redirects to homepage 
    168181            redirect('', 'location'); 
    169182        } 
     
    209222            { 
    210223                $role= $this->CI->db_session->userdata('role'); 
    211                 
     224                 
     225                // Here is the 'redirect to requested page after login' thing. 
     226                // We test if the visitor was denied and sent to the login form. 
     227                $requested_page = $this->CI->db_session->flashdata('requested_page'); 
     228                if ( $requested_page != '' ) 
     229                { 
     230                    // We have to keep the page info once again in case of 
     231                    // the user is still denied on the requested page. 
     232                    // (otherwise the 'already logged in' message is displayed) 
     233                    $this->CI->db_session->set_flashdata('requested_page', $requested_page); 
     234                    redirect( $requested_page, 'location'); 
     235                } 
     236                 
     237                // if no page was requested before, let's redirect the user 
     238                // according to his role 
    212239                switch ($role) 
    213240                { 
     
    225252            } 
    226253            
    227             //else display the login form (for the first time or once again) 
     254            // else display the login form (for the first time or once again) 
    228255            else 
    229             {    
    230                 
     256            { 
     257                // keep the page that was requested for the next login attempt 
     258                $this->CI->db_session->keep_flashdata('requested_page'); 
     259                 
    231260                if ($this->CI->config->item('FAL_use_captcha_login')) 
    232261                {        
  • FreakAuth/trunk/www/system/application/libraries/Freakauth_light.php

    r282 r283  
    218218            if ($role == '') 
    219219            { 
     220                // First, we have to store the requested page in order 
     221                // to serve it back to the visitor after a successful login. 
     222                $this->CI->db_session->set_flashdata('requested_page', 
     223                    $this->CI->uri->uri_string()); 
     224                 
     225                // Then we redirect to the login form with a 'access denied' 
     226                // message. Maybe if the visitor can log in, 
     227                // he'll get some more permissions... 
    220228                $msg = $this->CI->lang->line('FAL_no_credentials_guest'); 
    221229                flashMsg($msg); 
    222                 // redirects to login form 
    223                 // maybe if we can log in, we'll have some more permissions 
    224230                redirect($this->CI->config->item('FAL_login_uri'), 'location'); 
    225231            } 
     
    242248                    else 
    243249                    { 
    244                         // if we come from this website, just go to this page back 
     250                        // if we came from our website, just go to this page back 
     251                        // but maybe we arrived here because of the 
     252                        // 'redirect to requested page', so in order not to 
     253                        $this->CI->db_session->keep_flashdata('requested_page'); 
    245254                        header("location:".$_SERVER['HTTP_REFERER']); 
    246255                        exit();