EllisLab text mark
Advanced Search
5 of 17
5
   
flexi auth - A user authentication library for CodeIgniter
Posted: 16 October 2012 07:23 AM   [ Ignore ]   [ # 61 ]   [ Rating: 0 ]
Joined: 2012-03-08
158 posts

@Xosen

It looks like you uncovered a bug that was preventing logging in via ajax.

I have just updated the Github repo with a fix for this problem, you just need to update the flexi_auth_lite_model.php file to get the new changes.

As a bonus, I’ve also updated the demo to include an example of logging in via ajax.
This is also available via the same Github repo.

You can also view this new demo via the live demo site @ http://haseydesign.com/flexi-auth/auth/login_via_ajax

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 16 October 2012 09:39 PM   [ Ignore ]   [ # 62 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

I have jut installed the library and have coded a registration form. Nothing special but its allowing me to become familiar. The reg form currently does not vary by much from the demo included with the download.

When I submit my form to register a user I get this error message:

A PHP Error was encountered

Severity
Notice

Message
Undefined propertystdClass::$session_name

Filename
models/flexi_auth_model.php

Line Number
785
A PHP Error was encountered

Severity
Notice

Message
Undefined propertystdClass::$session_data

Filename
models/flexi_auth_model.php

Line Number
785
A PHP Error was encountered

Severity
Notice

Message
Undefined propertystdClass::$db_settings

Filename
models/flexi_auth_model.php

Line Number
797
A PHP Error was encountered

Severity
Notice

Message
Undefined propertystdClass::$tbl_user_account

Filename
models/flexi_auth_model.php

Line Number
809
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 () IS NULL' at line 2

SELECT COUNT
(*) AS `numrowsWHERE () IS NULL

Filename
Z:\wamp\www\site\system\database\DB_driver.php

Line Number
330 

Any ideas on this? I installed everything par the instructions and the demo installed in a separate folder seems to work fine.

Thanks for any help

 
Posted: 17 October 2012 06:08 AM   [ Ignore ]   [ # 63 ]   [ Rating: 0 ]
Joined: 2012-03-08
158 posts

@code_has_been_ignited

The error suggests there is a misconfiguration problem somewhere with how you have installed the library.

From looking at the error message, I would first check that you have properly defined the session config settings via the flexi auth config file.
In the demo config file, this can be found on line 285 and should look like:

$config['sessions']['user_id''user_id'

If that fails, you’ve probably already gone through it, but try to re-go through each point of the installation guide @ http://haseydesign.com/flexi-auth/user_guide/installation

Other than that, it’s hard to pinpoint the problem.
In such a situation I find it is best to make a fresh clean install of CI and the flexi auth demo, and then reverse engineer the registration page to what you want, when it works, compare what is different through the config, controller and view files to the code that is causing the problem now.

 

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 17 October 2012 06:35 AM   [ Ignore ]   [ # 64 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

Hey,

Thanks for the reply, everything was fine, except I double loaded the library. Once i corrected this everything seemed fine.

I do have another issue or bug. When I am logging in, if i leave a field blank, error messages show, which is good,

But

if I enter wrong information not message displays. Ive tried to enter, right username, wrong password, wrong username, right password etc, but it wont throw the “Login unsuccessful” message.

Any idea on this, maybe lead me in the right direction?

Thanks

 
Posted: 17 October 2012 07:04 AM   [ Ignore ]   [ # 65 ]   [ Rating: 0 ]
Joined: 2012-03-08
158 posts

@code_has_been_ignited

Hey man,

Regarding how to return error messages with actions like failed logins, you can use the ‘get_messages()’ function.

How you implement the passing of data returned from this function to your view is up to you.
You could simply call the function directly within you view if you wanted.

What I will note though is that if like in the demo you add the returned messages to a CI flash session, then the page must be reloaded before the message will be available from the flash session data - this is just how CI’s session class works.

So as an example for returning error messages using CI flash sessions after a login attempt, you could use the following code:

// Attempt to login user.
$this->flexi_auth->login('login_identity''login_password');

// Add message to CI flash data.
$this->session->set_flashdata('message'$this->flexi_auth->get_messages());

// Ensure the page is reloaded to make the flashdata available on the next page.
redirect('auth'); 

To return the message instantly:

// Attempt to login user.
$this->flexi_auth->login('login_identity''login_password');

// Echo the message.
echo $this->flexi_auth->get_messages(); 
 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 17 October 2012 04:25 PM   [ Ignore ]   [ # 66 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

Hey,

What I guess what I do not understand is why it WILL show the error if im missing the username or password, because it will not pass the form_validation.

This is my function:

public function login()
 
{
 
// Set validation rules.
  
$this->form_validation->set_rules('login_identity''Identity (Email / Login)''required');
  
$this->form_validation->set_rules('login_password''Password''required');

  
// If failed login attempts from users IP exceeds limit defined by config file, validate captcha.
  
if ($this->flexi_auth->ip_login_attempts_exceeded())
  
{
   $this
->form_validation->set_rules('recaptcha_response_field''Captcha Answer''required|validate_recaptcha');      
  
}
  
  
// Run the validation.
  
if ($this->form_validation->run())
  
{
   
// Check if user wants the 'Remember me' feature enabled.
   
$remember_user = ($this->input->post('remember_me') == 1);
 
   
// Verify login data.
   
$this->flexi_auth->login($this->input->post('login_identity'), $this->input->post('login_password'), $remember_user);

   
// Save any public status or error messages (Whilst suppressing any admin messages) to CI's flash session data.
   
$this->session->set_flashdata('message'$this->flexi_auth->get_messages());

   
// Reload page, if login was successful, sessions will have been created that will then further redirect verified users.
   
redirect('account');
  
}
   
   
// Set validation errors.
   
$this->data['message'validation_errors('<p class="error_msg">''</p>');

  
  
$this->data['message'= (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message']
  
$this->load->view('template/global_header');
  
$this->load->view('public/login_form',$this->data);
  
$this->load->view('template/global_footer');
 

In my view I have

<?php if (! empty($message)) { ?>
 
<div id="message">
  
<?php echo $message?>
  
</div>
<?php } ?> 

The code is almost identical to the demo, with exception I process the login inside my controller.

Thanks for any tips and solutions

Will

 
Posted: 18 October 2012 05:42 AM   [ Ignore ]   [ # 67 ]   [ Rating: 0 ]
Joined: 2012-03-08
158 posts

@code_has_been_ignited

I think the problem is because you are redirecting the user to your ‘account’ page regardless of whether or not the login has been successful.

Even if you then only redirected on success, then with your current code you are trying to get the login error message from a CI flash session that has only been set just above.

Data set to CI flash session is not accessible until the page is reloaded.

Try changing your code to the following.

public function login()
{
  
// Set validation rules.
  
$this->form_validation->set_rules('login_identity''Identity (Email / Login)''required');
  
$this->form_validation->set_rules('login_password''Password''required');

  
// If failed login attempts from users IP exceeds limit defined by config file, validate captcha.
  
if ($this->flexi_auth->ip_login_attempts_exceeded())
  
{
    $this
->form_validation->set_rules('recaptcha_response_field''Captcha Answer''required|validate_recaptcha');      
  
}

  
// Run the validation.
  
if ($this->form_validation->run())
  
{
    
// Check if user wants the 'Remember me' feature enabled.
    
$remember_user = ($this->input->post('remember_me') == 1);

    
// Verify login data.
    
if ($this->flexi_auth->login($this->input->post('login_identity'), $this->input->post('login_password'), $remember_user))
    
{
      
// Save any public status or error messages (Whilst suppressing any admin messages) to CI's flash session data.
      
$this->session->set_flashdata('message'$this->flexi_auth->get_messages());

      
// Reload page, if login was successful, sessions will have been created that will then further redirect verified users.
      
redirect('account');
    
}
  }

  
// Set validation errors.
  
$this->data['message'validation_errors('<p class="error_msg">''</p>');
  
$this->data['message'= (empty($this->data['message'])) ? $this->flexi_auth->get_messages() : $this->data['message']

  
$this->load->view('template/global_header');
  
$this->load->view('public/login_form',$this->data);
  
$this->load->view('template/global_footer');
 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 18 October 2012 05:24 PM   [ Ignore ]   [ # 68 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

Thank you for this input. I have a better picture of what needs to be done. I will adjust my code and will come back to post my results.

Thank you for your time.

 
Posted: 19 October 2012 01:28 PM   [ Ignore ]   [ # 69 ]   [ Rating: 0 ]
Joined: 2012-10-19
11 posts

Is there a relation between Flexi-auth and a bug with the C.I. Cookies?

I’m working with CodeIgniter 2.1.3 and Flexi-auth but when a I login with Chrome or IE 9 if a user refresh or change the page I’m logout.

The problem seems with the ci_cookie. In Chrome or IE 9 that cookie is created but expire immediatly.

I try to fix this bug installing the upgrade that has been offered to @xosen in this forum, but without results.


  Best.

 
Posted: 19 October 2012 03:12 PM   [ Ignore ]   [ # 70 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1415 posts
davidinchi - 19 October 2012 01:28 PM

Is there a relation between Flexi-auth and a bug with the C.I. Cookies?

I’m working with CodeIgniter 2.1.3 and Flexi-auth but when a I login with Chrome or IE 9 if a user refresh or change the page I’m logout.

The problem seems with the ci_cookie. In Chrome or IE 9 that cookie is created but expire immediatly.

I try to fix this bug installing the upgrade that has been offered to @xosen in this forum, but without results.


  Best.

Wouldn’t this be an Ion Auth issue?

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 19 October 2012 07:56 PM   [ Ignore ]   [ # 71 ]   [ Rating: 0 ]
Joined: 2012-03-08
158 posts

@davidinchi

Yes you were right, there was a bug with the library and IE setting login cookies on the ‘Login via Ajax’ example.
Although I could only regenerate the bug in IE and not Chrome as you suggested.
However, I’m pretty sure the fix should address any browsers that were having the same issue.

You can get the fix from the usual Github repo.
The only file that needs to be updated is ‘flexi_auth_lite_model.php’.

@skunkbad

As said above, this particular issue would have been specific to the flexi-auth library rather than inherited from ion-auth.
Although the flexi-auth library was originally built on many of the foundations of ion-auth, by the time I released the library, the code base had virtually been completely rewritten.
So any bugs affecting ion-auth are unlikely to also affect flexi-auth.

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 19 October 2012 09:11 PM   [ Ignore ]   [ # 72 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

I was wondering is it possible for your auth library to use SMTP to send emails?

 
Posted: 20 October 2012 05:26 AM   [ Ignore ]   [ # 73 ]   [ Rating: 0 ]
Joined: 2012-10-19
11 posts

@skunkbad @haseydesign thanks for your responses.

@haseydesign the problem is still there with your suggested update. Check it for yourself: http://flyinglow.hl31.dinaserver.com/development/


Best.

 
Posted: 20 October 2012 11:57 AM   [ Ignore ]   [ # 74 ]   [ Rating: 0 ]
Joined: 2012-01-17
11 posts

In regards to reply: http://ellislab.com/forums/viewthread/224351/P60/#1035977

I implemented the changes and works very very nicely. Thank you so much this also resolved a few issues in my thought process.

Great library!

 
Posted: 20 October 2012 08:00 PM   [ Ignore ]   [ # 75 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
818 posts

Hey dude,

Just saw this so I wanted to say good job.  Code looks great.  It definitely has a different philosophy than Ion Auth and that’s great for the community to have choice.

Take care dude!

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
5 of 17
5