Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]woeps[/eluser]
Hey Kakap!
I'm not an expert on CI but I think your problem could be the constructor of your Admin_Controller...
[quote author="kakap" date="1290580595"]
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class Admin_Controller extends MY_Controller{
    
    function __construct() {
        
        parent::__construct();
        
        //check apakah user login
        if (!$this->ion_auth->logged_in()) {
            
            //jika belum login kirim ke halaman login admin
            redirect('admin/login', 'refresh');
        }
        //cek apakah yang login adalah admin
        elseif (!$this->ion_auth->is_admin()) {
            
            //jika yg login bukan admin (user biasa) maka
            //dikembalikan ke halaman profil siswa.
            redirect('siswa/index', 'refresh');
        }
    }
}
[/quote]
On every call of the admin controller you check first if the user is logged in. (At this time the user hadn't even a chance to login.) And if he is not logged in you redirect him again to admin/login. So I think this is where your controller "loops".. at least you have to expand the if-statement to check if the actual location is not "admin/login" yet.
For example:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class Admin_Controller extends MY_Controller{
    
    function __construct() {
        
        parent::__construct();
        
        //check apakah user login
        $current_page = $this->uri->segment(1).'/'.$this->uri->segment(2);
        if (!$this->ion_auth->logged_in() && $current_page != 'admin/login') {
            
            //jika belum login kirim ke halaman login admin
            redirect('admin/login', 'refresh');
        }
        //cek apakah yang login adalah admin
        elseif (!$this->ion_auth->is_admin()) {
            
            //jika yg login bukan admin (user biasa) maka
            //dikembalikan ke halaman profil siswa.
            redirect('siswa/index', 'refresh');
        }
    }
}
I hope this works! Wink

__________________________________________________________________


My (own) Problem:
Every time when I try to use the username_check()-method I get this sql-error:
Quote:A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `username` = 'administrator'' at line 2

SELECT COUNT(*) AS `numrows` WHERE `username` = 'administrator'


my code is pretty simple (stripped down):
Code:
function register()
        {
        $this->load_form_validation(); //Validation-Rules are set in the config-file
        if($this->form_validation->run() && !$this->ion_auth->username_check($this->input->post('username'))
            {
            //do register
            $this->messages->add('REGISTER-ACTION!', 'debug');
            }
        else
            {
            $this->errOp(); //output the errors
            $this->data['cont'] = $this->get_view('auth/register'); //load registration-form
            }
        $this->output(); //Output everything
        }

any idea where should I look for my error?

I have a MY_Controller but it contains only a few methods I use more often and in the header I set a few default-values for vars.
without the username_check()-call everything works fine..

I updated the ion-auth-library today but this didn't help either.
(I use CI version 1.7.2)

Thanks for your help!


Messages In This Thread
Ion Auth - Lightweight Auth System based on Redux Auth 2 - by El Forum - 11-23-2010, 11:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB