I’m using the latest version of Zend Server CE on a Windows machine (as you can tell by the path on “Filename” line).
Since I’m still trying to understand a bit more the library, I’m not sure if I can just set a default value directly at the db structure or if I can do that somewhere within the library files.
In reply to an email I received from ‘Wills’, this may also help others with the same problem.
I use the routes function in codeigniter to make prettier URLS but when I set the logout one to:
$route[‘logout’] = ‘auth/logout’;
All it does is goes to the user dashboard, but accessing the URL auth/logout, it logs out nicely. Any ideas?
This is simply a conflict with the way the demo example has been setup, and is not a problem with the library.
In the __construct() of the current ‘auth’ controller, there is an IF condition that performs a redirect if true.
if ($this->flexi_auth->is_logged_in_via_password() && uri_string() != 'auth/logout')
Because of the new url routing the uri_string() function would now return ‘logout’, rather than ‘auth/logout’, and therefore causing a the __construct() to redirect before the logout method got to be called.
Changing the code to the following would allow for both url paths.
if ($this->flexi_auth->is_logged_in_via_password() && ! in_array(uri_string(), array('auth/logout', 'logout')))
This error seems to be related to the CodeIgniter database config (application/config/database.php):
$db['default']['stricton'] = TRUE;
If this is defined as TRUE, then I also get the same errors as yourself.
If you were to update the database table ‘user_login_sessions’ with the following sql statement it would fix this particular error message.
ALTER TABLE `user_login_sessions` MODIFY COLUMN `usess_series` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '' AFTER `usess_uacc_fk`;
However, you will then receive other errors for other table columns that also do not have a default value defined.
So your options are, either update your CI database config as follows:
$db['default']['stricton'] = FALSE;
Or alternatively, you will need to go through all of the libraries database tables and define default values for each column.
I’ve fixed it setting the column to allow NULL and it’s default value to NULL also. It seems to be fixed, since I have not noticed any errors after.
One thing it’s weird though, I’ve checked my db config and striction it’s set to false already.
Later on, I caught myself thinking setting “usess_series” to NULL as default value, makes sense as Barry Jaspan states in the first 2 items of his “Improved Persistent Login Cookie Best Practice” solution that:
1. When the user successfully logs in with Remember Me checked, a login cookie is issued in addition to the standard session management cookie.
2. The login cookie contains the user’s username, a series identifier, and a token. The series and token are unguessable random numbers from a suitably large space. All three are stored together in a database table.
If the user doesn’t check Remember Me, that cookie wouldn’t need to be set, right? If so, the “usess_series” column wouldn’t have to set a default value other than NULL or another value that represents emptiness.
Well… that makes sense to me. If you have another point of view of this particular subject, I’ll be more than glad to hear.
Hey there, sorry if I’m spamming, but I’m struggling to get Flexi Auth working on a dedicated server I have.
I’ve uploaded everything, imported sql dumps and changed configs, but oddly I can’t login.
I thought some change I’ve made caused this, so I’ve uploaded a fresh copy of CI and Flexi Auth, did everything again (installation instructions), but no success.
Please tell me if there’s any other information that might be helpful.
UPDATE 11 Oct 2012
I’ve found the reason for this issue on my server is PHP, which is running 5.2.17. After a very quick research on that, I’ve also found a PHP version lower than 5.3 doesn’t have CRYPT_BLOWFISH implementation and relies on OS to provide support.
After checking the flexi auth installation on your link and the subsequent update message you left, i’m assuming you got things working properly; is that right?
Once you worked out that the php version was causing the issue, how did you go about solving it?
I’ve asked for the upgrade to PHP 5.3 with mbstring enabled to my hosting company, but until they do that, I’ve made a helper to fullfil the lack of two functions Flexi uses. I’m pretty sure it’s not the best code ever, but at least it’s a start to make backward compatibility where mbstring isn’t enabled.
mbstring_helper.php source code:
<?php
if (!function_exists('mb_strlen')) { function mb_strlen($string) { return preg_match_all( '(.)su', $string, $matches ); } }
if (!function_exists('mb_substr')){ function mb_substr($string, $start = 0, $length = NULL) { $pattern = '^'; if ($start > 0) $pattern .= '(?:.{'.$start.'})'; else $pattern .= '(?:.*)';
I’m using Flexi auth and everything goes well until I use AJAX. With the user logged in, an AJAX request to a controller is done. This controller then uses a model to store some info to the database. When the user then goes to another page, he has been logged out.
At first I was trying to obtain the user id in the controller, but the is_logged_in function returned false. I thought the problem was using the Flexi auth library in the AJAX request, so I took out all Flexi auth code from the controller, but the user session continues to be closed.
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();