ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ion Auth - Lightweight Auth System based on Redux Auth 2

February 10, 2010 7:00pm

Subscribe [287]
  • #631 / Nov 23, 2010 2:31am

    joytopia

    76 posts

    Bernd, I’m getting the exact same error when using Ion Auth and the latest tip version of CI2.

    Maybe they’ve changed the load order? The version from ~October 12 was working fine.

    Iversia, Devon,
    thanks for reporting the same error.
    I downloaded the newest CI2 from tip, but unfortunately the error remains (sometimes you have to reload the page up to 7 times to reproduce the error).

    Could someone please send me an old Version of CI2 , perhaps from around ~October 12, than I can try, if it works with that version?

    Thanks and best regards
    Bernd

  • #632 / Nov 23, 2010 9:12am

    Devon Lambert

    139 posts

    Bernd, I’m getting the exact same error when using Ion Auth and the latest tip version of CI2.

    Maybe they’ve changed the load order? The version from ~October 12 was working fine.

    Iversia, Devon,
    thanks for reporting the same error.
    I downloaded the newest CI2 from tip, but unfortunately the error remains (sometimes you have to reload the page up to 7 times to reproduce the error).

    Could someone please send me an old Version of CI2 , perhaps from around ~October 12, than I can try, if it works with that version?

    Thanks and best regards
    Bernd

    Hey Bernd,

    See below:

    UPDATE ON THE UNDEFINED/MODEL Error

    After beating my head against a wall trying to figure out a fix for the error that Bernd, Inversia, and myself have been experiencing, I made the following change to the Model.php file under the CI Core (I know, this seems a bit hackish, but if I’m correct, I believe this minor fix should be pushed to the core anyways).

    CI > System > Core > Model.php

    Change this function:

    function __get($key)
        {
            $CI =& get_instance();
            return $CI->$key;
        }

    To this:

    function __get($key)
        {
            $CI =& get_instance();
            
            if (isset($CI->$key)) {
                return $CI->$key;
            }
        }

    I believe the error is returned because CI is trying to make recursive use of __get with the Ion_auth class. i.e. Controller calls Library, Library calls Model. etc…

    Hope this helps someone else out there. 😊

  • #633 / Nov 23, 2010 8:36pm

    kakap

    24 posts

    hello, I need help here in using ci+hmvc+ion auth. my simple codes :

    MY_Controller: (location:application/libraries/MY_Controller.php)

    <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
    
    class MY_Controller extends Controller{
        
        function __construct() {
            
            parent::Controller();
            
        }
    }

    Admin_Controller: (location:application/libraries/Admin_Controller.php)

    <?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');
            }
        } 
    }

    admin.php: (location:application/controller/admin.php)

    <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
    
    class Admin extends Admin_Controller{
        
        function __construct() {
            
            parent::__construct();
            $this->load->library('form_validation');
        }
        
        function index() {
            
            //here
            $this->data['title'] = 'Dashboard';
            
            $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
            $this->data['users'] = $this->ion_auth->get_users_array();
            
            $this->load->view('admin/index', $this->data);
        }
        
        function login() {
            
            //here
            $this->data['title'] = 'Login';
            
            //validasi input
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('password', 'Password', 'required');
            
            if ($this->form_validation->run() == TRUE) {
                    
                //cek remember me
                if ($this->input->post('remember') == 1) {
                    
                    $remember = TRUE;
                }
                else {
                    
                    $remember = FALSE;
                }
                
                if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember)) {
                    
                    $this->session->set_flashdata('message', $this->ion_auth->messages());
                    redirect('admin/index', 'refresh');
                }
                else {
                    
                    $this->session->set_flashdata('message', $this->ion_auth->errors());
                    redirect('admin/login', 'refresh');
                }
            }
            else {
                
                //disini adalah antarmuka login
                //$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
                
                $this->data['email']    = array(
                                                'name'  => 'email',
                                                'id'    => 'email',
                                                'type'  => 'text',
                                                'value' => $this->form_validation->set_value('email')
                                                );
                                                
                $this->data['password'] = array(
                                                'name'  => 'password',
                                                'id'    => 'password',
                                                'type'  => 'password'
                                                );
                
                $this->load->view('admin/login', $this->data);
            }
        }
        
        function logout() {
            
            //here
            $this->data['title'] = 'Logout';
            
            $logout = $this->ion_auth->logout();
            redirect('admin/login', 'refresh');
        }
    }
    
    ?>

    when I try to access http://localhost/web/admin/login, the page refresh on and on (I mean always refreshed) I think this is because the condition from Admin_Controller :

    //check apakah user login
            if (!$this->ion_auth->logged_in()) {
                
                //jika belum login kirim ke halaman login admin
                redirect('admin/login', 'refresh'); 
            }

    I want to ask, how to pass it from the condition ?. I try to see from PyroCMS Admin_Controller, there is stuff like :

    // These pages get past permission checks
            $ignored_pages = array('admin/login', 'admin/logout');
                
            // Check if the current page is to be ignored
            $current_page = $this->uri->segment(1, '') . '/' . $this->uri->segment(2, 'index');
            $is_ignored_page = in_array($current_page, $ignored_pages);

    but I don’t know how to make my own code like that.

    help me please, thank yo so much.

  • #634 / Nov 24, 2010 1:45am

    woeps

    4 posts

    Hey Kakap!
    I’m not an expert on CI but I think your problem could be the constructor of your Admin_Controller…

    <?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');
            }
        } 
    }

    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:

    <?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! 😉

    __________________________________________________________________


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

    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):

    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!

  • #635 / Nov 24, 2010 3:43am

    joytopia

    76 posts

    Hey Devon,

    thank you so much! It seems that the error has gone.

    Now I wonder if one of us should report that issue at bitbucket or if one of the core team, Ben?, Phil? can fix it directly?

    Best regards
    Bernd

  • #636 / Nov 24, 2010 11:21am

    Devon Lambert

    139 posts

    Hey Devon,

    thank you so much! It seems that the error has gone.

    Now I wonder if one of us should report that issue at bitbucket or if one of the core team, Ben?, Phil? can fix it directly?

    Best regards
    Bernd

    Done

  • #637 / Nov 24, 2010 11:48am

    Todlerone

    63 posts

    Hello everyone.  I’m trying to use this but when I enter the MySql information I get the error:

    #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 ‘IDENTITY(1,1),
      group_id int NOT NULL,
      ip_address char(16) NOT NULL,
    ’ at line 2

    Any suggestions?

    TY in advance.  SOLVED…turns out I used the mssql by mistake.

  • #638 / Nov 24, 2010 3:26pm

    kakap

    24 posts

    <?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! 😉

    yes, thats worked. thank you.
    but, I need page ‘admin/logout’ should be passed too. so I modified it lilte. 😊

  • #639 / Nov 25, 2010 4:36pm

    Todlerone

    63 posts

    Hello all. Sorry if this is a very basic question but I made a mess trying to make it work.  All I want to do is have the login form from my main page.  I don’t want a link to send me to another login page.

    TY in advance

  • #640 / Nov 25, 2010 9:28pm

    techgnome

    182 posts

    So then include the login form as part of your view. There’s nothing that says the login form has to be it’s own view. Just make sure the form posts to the right controller, and if it fails that it redirects to an appropriate page.

    -tg

  • #641 / Nov 25, 2010 9:46pm

    JoeDRL

    6 posts

    Is it me or I can’t find a way to retrieve a user by it’s username…?
    I tried to use extra_where(array(‘username’=>$username)) followed by a get_user()but it sent me an error.

    Am I doing things right?

    Thanks a lot and very very good Auth system 😊


    EDIT: Sorry, it worked after putting get_users() instead of get_user().

  • #642 / Nov 26, 2010 12:57pm

    Todlerone

    63 posts

    So then include the login form as part of your view. There’s nothing that says the login form has to be it’s own view. Just make sure the form posts to the right controller, and if it fails that it redirects to an appropriate page.

    -tg

    TY techgnome for your reply.  I tried this and I get Undefined variable: message, username and password.

    I have placed the auth controller index code into my home index controller and I copied the login function also.  I also loaded the library(‘ion_auth’).

  • #643 / Nov 26, 2010 7:56pm

    Timothy_

    100 posts

    Timothy_,

    I ran into this problem the other day as well.  I just pushed a change to the library so the register() method will return the newly created users id if the registration was successful, otherwise it will return false.

    So an example of how you get the users id now is:

    $user_id = $this->ion_auth->register(......

    Hey Ben,

    Sorry about not getting back to you sooner, busy week!

    Thanks so much for doing this. This is perfect!!!

    Tim

  • #644 / Nov 29, 2010 10:07am

    Todlerone

    63 posts

    I tried putting the form in my main page view but I still get Undefined variable: message, username and password.

    I have placed the auth controller index code into my home index controller and I copied the login function also.  I also loaded the library(‘ion_auth’).

    Ayone have suggestions.TY TY

  • #645 / Nov 29, 2010 10:21am

    techgnome

    182 posts

    What does your controller and form code look like? I don’t know about others here, but I’m not clairvoyant.

    -tg

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases