Welcome Guest, Not a member yet? Register   Sign In
Community auth forced login
#5

(This post was last modified: 05-30-2017, 10:16 PM by skunkbad.)

PHP Code:
$bool is_role('admin'); 

That is documented here:
https://community-auth.com/documentation...-functions

Also, I made this Test controller up real quick, and I'm not saying you should do it, because it's not secure to switch users via URL param, but it's proof of switching user working. You would go to /test/simple_verification to start:

PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Test extends MY_Controller{
    
    public function 
__construct()
    {
        
parent::__construct();

        
// Form and URL helpers always loaded (just for convenience)
        
$this->load->helper('url');
        
$this->load->helper('form');
    }

    
// -----------------------------------------------------------------------

    
public function switch_user$username_or_email_address )
    {
        
$this->is_logged_in();

        if( ! empty( 
$username_or_email_address ) )
        {
            
$auth_model $this->authentication->auth_model;

            
// Get normal authentication data using username or email address
            
if( $auth_data $this->{$auth_model}->get_auth_data$username_or_email_address ) )
            {
                
// Set auth related session / cookies
                
$this->authentication->maintain_state$auth_data );
            }

            
$_GET['redirect'] = urlencode('test/simple_verification');
            
$this->authentication->redirect_after_login();
        }
        else
        {
            echo 
'Example requires that you set a username or email address.';
        }
    }
    
    
// -----------------------------------------------------------------------

    
public function simple_verification()
    {
        
$this->is_logged_in();

        echo 
$this->load->view('examples/page_header'''TRUE);

        echo 
'<p>';
        if( ! empty( 
$this->auth_role ) )
        {
            echo 
$this->auth_role ' logged in!<br />
                User ID is ' 
$this->auth_user_id '<br />
                Auth level is ' 
$this->auth_level '<br />
                Username is ' 
$this->auth_username;

            if( 
$http_user_cookie_contents $this->input->cookieconfig_item('http_user_cookie_name') ) )
            {
                
$http_user_cookie_contents unserialize$http_user_cookie_contents );
                
                echo 
'<br />
                    <pre>'
;

                
print_r$http_user_cookie_contents );

                echo 
'</pre>';
            }

            if( 
config_item('add_acl_query_to_auth_functions') && $this->acl )
            {
                echo 
'<br />
                    <pre>'
;

                
print_r$this->acl );

                echo 
'</pre>';
            }
        }
        else
        {
            echo 
'Nobody logged in.';
        }

        echo 
'</p>';

        echo 
'<h2>Switch User</h2>
            <p>If you do not have these users, you need to create them first</p>
            <ul>
                <li><a href="/test/switch_user/skunk">skunk</a></li>
                <li><a href="/test/switch_user/chicken">chicken</a></li>
                <li><a href="/test/switch_user/lizard">lizard</a></li>
            </ul>
        '
;

        echo 
$this->load->view('examples/page_footer'''TRUE);
    }
    
    
// -----------------------------------------------------------------------
}

/* End of file Test.php */
/* Location: /application/controllers/Test.php */ 

Dig through the code a bit, and you'll find that you should easily be able to achieve what you want.

Edit:
This assumes a clean install of CI and Community Auth, because I can't know if you've made mods.
Reply


Messages In This Thread
Community auth forced login - by mxfragz - 05-28-2017, 09:16 PM
RE: Community auth forced login - by skunkbad - 05-29-2017, 08:36 AM
RE: Community auth forced login - by mxfragz - 05-30-2017, 06:19 PM
RE: Community auth forced login - by mxfragz - 05-30-2017, 07:18 PM
RE: Community auth forced login - by skunkbad - 05-30-2017, 10:15 PM
RE: Community auth forced login - by mxfragz - 05-31-2017, 12:11 AM
RE: Community auth forced login - by skunkbad - 05-31-2017, 12:16 PM
RE: Community auth forced login - by mxfragz - 05-31-2017, 06:40 PM
RE: Community auth forced login - by skunkbad - 05-31-2017, 07:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB