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:
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
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:
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.
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?
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();
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);
// 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>');
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'); } }
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.
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.