CodeIgniter Forums
flexi auth - A user authentication library for CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: flexi auth - A user authentication library for CodeIgniter (/thread-54581.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34


flexi auth - A user authentication library for CodeIgniter - El Forum - 10-16-2012

[eluser]haseydesign[/eluser]
@PyroDev

Thanks for posting the code to help anyone else having problems with getting flexi auth to work on earlier versions of php - much appreciated!

Regarding setting the 'usess_series' to NULL, this should be absolutely fine.




flexi auth - A user authentication library for CodeIgniter - El Forum - 10-16-2012

[eluser]haseydesign[/eluser]
@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


flexi auth - A user authentication library for CodeIgniter - El Forum - 10-16-2012

[eluser]code_has_been_ignited[/eluser]
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:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$session_name

Filename: models/flexi_auth_model.php

Line Number: 785
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$session_data

Filename: models/flexi_auth_model.php

Line Number: 785
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$db_settings

Filename: models/flexi_auth_model.php

Line Number: 797
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$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 `numrows` WHERE () 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


flexi auth - A user authentication library for CodeIgniter - El Forum - 10-17-2012

[eluser]haseydesign[/eluser]
@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:
Code:
$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.



flexi auth - A user authentication library for CodeIgniter - El Forum - 10-17-2012

[eluser]code_has_been_ignited[/eluser]
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


flexi auth - A user authentication library for CodeIgniter - El Forum - 10-17-2012

[eluser]haseydesign[/eluser]
@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:
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:
Code:
// Attempt to login user.
$this->flexi_auth->login('login_identity', 'login_password');

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



flexi auth - A user authentication library for CodeIgniter - El Forum - 10-17-2012

[eluser]code_has_been_ignited[/eluser]
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:

Code:
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
Code:
&lt;?php if (! empty($message)) { ?&gt;
<div id="message">
  &lt;?php echo $message; ?&gt;
  </div>
&lt;?php } ?&gt;

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

Thanks for any tips and solutions

Will


flexi auth - A user authentication library for CodeIgniter - El Forum - 10-18-2012

[eluser]haseydesign[/eluser]
@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.

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



flexi auth - A user authentication library for CodeIgniter - El Forum - 10-18-2012

[eluser]code_has_been_ignited[/eluser]
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.



flexi auth - A user authentication library for CodeIgniter - El Forum - 10-19-2012

[eluser]davidinchi[/eluser]
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.