Part of the EllisLab Network
   
2 of 6
2
EzAuth 0.4 (beta) Released! - An ACL/user management CodeIgniter Project
Posted: 24 October 2007 05:31 PM   [ Ignore ]   [ # 11 ]  
Summer Student
Total Posts:  12
Joined  08-06-2007

i seem to be getting this error:

A PHP Error was encountered

Severity
Notice

Message
Undefined propertyUserbackend::$validation

Filename
controllers/userbackend.php

Line Number
31 

it’s referring to this:

function login($data = array()) {
                
// set required fields for validation
                
$rules['username'"required";
                
$this->validation->set_rules($rules);
                
$fields['username'"Username";
                
$this->validation->set_fields($fields);

                
// if post variables are set, run validation
                
if ($this->validation->run()) {
                    $login_ok 
$this->ezauth->login();    // $login_ok returns authorize = true or false depending on user login information
                    
if ($login_ok['authorize'== true{
                        $this
->ezauth->remember_user();        // store username in cookie
                        
redirect('userbackend');            // if user logs in successfully, redirect to main page
                    
else {
                        $data[
'error_string'$login_ok['error'];
                    
}

                }
                $this
->load->view('login/index',$data);
        


any suggestions? I’m using CI 1.5.4

Many thanks

Profile
 
 
Posted: 24 October 2007 05:42 PM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

Hi ceej. I am going to guess that your controller is named BackEnd.

Since you downloaded the demo application, you will need to load the validation, database and session libaries, as well as the cookie, url, and form helpers. The error you received may be referring to the validation library that has not been loaded yet.

If you have the validation library loaded, you may be having a problem with the redirect function, which will require you to load the url helper.

Let me know if loading the helpers and libraries works!

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile
 
 
Posted: 24 October 2007 05:53 PM   [ Ignore ]   [ # 13 ]  
Summer Student
Total Posts:  18
Joined  04-14-2007

Hi!

So I’m using your model for my project and I’ve been trying to program a pre-controller hook to autolog using the “remember me” cookie.

I must be very bad at OOP, since I can’t seem to make my hook class even begin to work.

I thought I’d go something like:

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

class 
Autologin
{
  
  
function autolog()
  
{

    $CI 
=& get_instance();
        
$CI->load->helper('cookie');

    if (
$cookie $CI->get_cookie('ezauth_username'TRUE))
    
{
     
        [more code here]

    }
  }

}
?> 

But this gives an error:

Fatal errorCall to a member function on a non-object in /home.10.3/instanta/mc2b/system/application/hooks/autologin.php on line 10 

Line 10 is where I’m trying to load the cookie helper.

I’m sure there’s something very simple I’m doing wrong but what is it?

Any help much appreciated! smile
Thanks
Laurent

Profile
 
 
Posted: 24 October 2007 06:14 PM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

I haven’t done much work with hooks, but it looks like you are calling the get_cookie function before the helper is actually loaded.

Because of my inexperience with hooks, I don’t have a solution to correct the hook, but logging the user in when you load your controller would solve your problem.

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile
 
 
Posted: 25 October 2007 12:16 AM   [ Ignore ]   [ # 15 ]  
Summer Student
Total Posts:  12
Joined  08-06-2007

Thank you danoph, that seemed to do the job! smile

Profile
 
 
Posted: 25 October 2007 04:20 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  18
Joined  04-14-2007
danoph - 24 October 2007 10:14 PM

I haven’t done much work with hooks, but it looks like you are calling the get_cookie function before the helper is actually loaded.

Because of my inexperience with hooks, I don’t have a solution to correct the hook, but logging the user in when you load your controller would solve your problem.

Yes, that would surely do, but wouldn’t it be a LOT cleaner to use a hook? I kinda hate to burden all my controllers with the same piece of code (though I’ll probably end up doing so).

Profile
 
 
Posted: 25 October 2007 04:32 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

It would be a lot cleaner if you used a hook, but it seems like the libraries and helpers aren’t loaded at the point where you make that call.

I hate redundant code! In fact, the last release of EzAuth (0.5) allowed you to declare a lot less when you are using multiple controllers. I like reducing code!

An auto-login looks like a good feature that will be added to the next release smile

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile
 
 
Posted: 25 October 2007 05:41 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Total Posts:  18
Joined  04-14-2007

Well I’ve just worked out an autologin code.

I’ll post the code here later, but here’s how I made it.

1. I tweaked your remember me cookie, cause I don’t think autologin from the username is something safe, I think it’s best done from some random unique ID.
For that, I added a field to the ez_users table named “code” and that’s what I’m storing in the cookie instead of the username. This code would have to be generated upon registration (something like uniqid() would probably do).

2. I used a post_controller_constructor hook (not a pre_controller hook which only sounded like the best choice). That lets you load helpers and libraries and that’s early enough in the flow for what we want to do.

3. I added an extra function autologin() to the model. This works the same as login() except it logs the user from its “code” instead of his username+pwd.

4. I also changed the logout function to have it erase the cookie.

I’ll post my code as soon as I get a chance to clean it.

Profile
 
 
Posted: 25 October 2007 06:08 PM   [ Ignore ]   [ # 19 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

Sounds good!

Post the code here or send it via e-mail to daniel{at}bizwidgets.biz

Your code should be useful when I incorporate an auto-login to the next release!

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile
 
 
Posted: 25 October 2007 06:11 PM   [ Ignore ]   [ # 20 ]  
Summer Student
Total Posts:  18
Joined  04-14-2007
danoph - 25 October 2007 10:08 PM

Sounds good!

Post the code here or send it via e-mail to daniel{at}bizwidgets.biz

Your code should be useful when I incorporate an auto-login to the next release!

I’ll post it some time tomorrow. For now, I’m off to bed grin

Profile
 
 
   
2 of 6
2