Welcome Guest, Not a member yet? Register   Sign In
Community Auth
#1

Hey Guys, 

I'm using  Community Auth and for each action in my app i'm redirected to the login page. 

Here is the MY_Controller code ;
PHP Code:
require_once APPPATH 'third_party/community_auth/core/Auth_Controller.php';
require_once 
APPPATH 'third_party/community_auth/helpers/auth_helper.php';

class 
MY_Controller extends Auth_Controller
{
    
/**
     * Class constructor
     */
    
public function __construct()
    {
        
parent::__construct();
    }
}

class 
Front_Controller extends MY_Controller
{
    
/**
     * Class constructor
     */
    
public function __construct()
    {
        
parent::__construct();

        
/*Load */
        
$this->load->library(array('template''session'));
        
$this->load->helper(array('url''form''auth_helper'));
    }
}

class 
Back_Controller extends MY_Controller
{
    
/**
     * Class constructor
     */
    
public function __construct()
    {
        
parent::__construct();

        if (
$this->require_min_level(1))
        {

        }
        
/*Load */
        
$this->load->library(array('template''form_validation''table''pagination'));
        
$this->load->helper(array('url''form''array''date'));
        
$this->load->model(array('organization_model''visit_model''level_model''dashboard_model''user_model'));

    }



Here is my dashboard controller : 
PHP Code:
class Dashboard extends Back_Controller
{
    public function 
__construct()
    {
        
parent::__construct();
        
//Do your magic here
    
}

    public function 
index()
    {

            
/*Set page title*/
            
$this->data['title'] = "Tableau de Bord";

            
/*Get all data*/
            
if ($this->verify_role('agent,manager'))
            {
                
$this->data['all_visits'] = $this->dashboard_model->count_all_visits($this->auth_user_id);
                
$this->data['attempting_visits'] = $this->dashboard_model->count_all_attempting_visits($this->auth_user_id);
                
$this->data['opened_visits'] = $this->dashboard_model->count_all_opened_visits($this->auth_user_id);
                
$this->data['closed_visits'] = $this->dashboard_model->count_all_closed_visits($this->auth_user_id);
            }
            else
            {
                
$this->data['all_visits'] = $this->dashboard_model->count_all_visits();
                
$this->data['attempting_visits'] = $this->dashboard_model->count_all_attempting_visits();
                
$this->data['opened_visits'] = $this->dashboard_model->count_all_opened_visits();
                
$this->data['closed_visits'] = $this->dashboard_model->count_all_closed_visits();
            }

            
/*Load Template*/
            
$this->template->back_render('backend/dashboard'$this->data);

    }



and here the dahboard view
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<!-- Right side column. Contains the navbar and content of the page -->
       <aside class="right-side">
           <!-- Main content -->
           <section class="content-header">
               <h1><?php echo $title; ?></h1>
               <ol class="breadcrumb">
                   <li class="active">
                       <a href="#">
                           <i class="livicon" data-name="home" data-size="14" data-color="#333" data-hovercolor="#333"></i> Tableau de bord
                       </a>
                   </li>
               </ol>
           </section>
           <section class="content">
               <div class="row">
                   <div class="col-lg-3 col-md-6 col-sm-6 margin_10 animated fadeInLeftBig">
                       <div class="lightbluebg no-radius">
                           <div class="panel-body squarebox square_boxs">
                               <div class="col-xs-12 pull-left nopadmar">
                                   <div class="row">
                                       <div class="square_box col-xs-7 text-right">
                                           <span>Toutes les visites</span>
                                           <div class="number" id="myTargetElement1"><a href="<?php echo site_url('backend/visit'); ?>"><?php echo $all_visits; ?></a></div>
                                       </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   </div>
                   <div class="col-lg-3 col-md-6 col-sm-6 margin_10 animated fadeInUpBig">
                       <!-- Trans label pie charts strats here-->
                       <div class="redbg no-radius">
                           <div class="panel-body squarebox square_boxs">
                               <div class="col-xs-12 pull-left nopadmar">
                                   <div class="row">
                                       <div class="square_box col-xs-7 pull-left">
                                           <span>Visites en attente</span>
                                           <div class="number" id="myTargetElement2"><a href="<?php echo site_url('backend/visit#attempt'); ?>"><?php echo $attempting_visits; ?></a></div>
                                       </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   </div>
                   <div class="col-lg-3 col-sm-6 col-md-6 margin_10 animated fadeInDownBig">
                       <!-- Trans label pie charts strats here-->
                       <div class="goldbg no-radius">
                           <div class="panel-body squarebox square_boxs">
                               <div class="col-xs-12 pull-left nopadmar">
                                   <div class="row">
                                       <div class="square_box col-xs-7 pull-left">
                                           <span>Visites en cours</span>
                                           <div class="number" id="myTargetElement3"><a href="<?php echo site_url('backend/visit#opened'); ?>"><?php echo $opened_visits; ?></a></div>
                                       </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   </div>
                   <div class="col-lg-3 col-md-6 col-sm-6 margin_10 animated fadeInRightBig">
                       <!-- Trans label pie charts strats here-->
                       <div class="palebluecolorbg no-radius">
                           <div class="panel-body squarebox square_boxs">
                               <div class="col-xs-12 pull-left nopadmar">
                                   <div class="row">
                                       <div class="square_box col-xs-7 pull-left">
                                           <span>Visites Terminées</span>
                                           <div class="number" id="myTargetElement4"><a href="<?php echo site_url('backend/visit#closed'); ?>"><?php echo $closed_visits; ?></a></div>
                                       </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   </div>
               </div>
           </section>
       </aside>
       <!-- right-side -->

Each time a connected user clicks on a link he gets redirection to the login page before. 
Also when i remove the require_min_level condition, the authentication are not loaded and i get the undefined variable errors.
I get thess issues with all of my pages.
Please can anyone help me on these issues ?
Thanks in advance !!!
Reply
#2

First thing I notice is that you are trying to load the session library in your Front_Controller, but this is taken care of in Auth_Controller, and Front_Controller is extending Auth_Controller, so you can remove that.

Next, for testing I changed my Auth_Controller.php to this:

PHP Code:
require_once APPPATH 'third_party/community_auth/core/Auth_Controller.php';

class 
MY_Controller extends Auth_Controller
{
    
/**
     * Class constructor
     */
    
public function __construct()
    {
        
parent::__construct();
    }
}

class 
Back_Controller extends MY_Controller
{
 
   /**
     * Class constructor
     */
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       $this->require_min_level(1);
 
   }




I also made a basic controller for testing:


PHP Code:
class Back extends Back_Controller {
    
    public function 
__construct()
    {
        
parent::__construct();
    }

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

    /**
     * Test by going to /back/dash in your browser
     */
    
public function dash()
    {
        echo 
'authenticated content ...';
    }
    
    
// -----------------------------------------------------------------------


And this all worked as expected.

One thing you should know is that this is the wrong way to load helpers:


PHP Code:
require_once APPPATH 'third_party/community_auth/helpers/auth_helper.php'


See the documentation for helpers to see the right way.

If this doesn't help the problem is most likely in your code, as you seem to not fully grasp the documentation for CodeIgniter. Really, it could be something as simple as a botched installation of Community Auth, but could be anything based on your code that you've provided.
Reply
#3

Hi Skunkbad,

Please both enforcing and simple verification load auth_data?

If yes, why when i use only simple verification method i get undefined variables errors?
Reply
#4

(12-26-2017, 02:22 AM)filipirie Wrote: Hi Skunkbad,

Please both enforcing and simple verification load auth_data?

If yes, why when i use only simple verification method i get undefined variables errors?

Auth variables won't be available if the request is done without current or previous authentication.
Reply
#5

Okay SB. Thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB