EllisLab text mark
Advanced Search
2 of 17
2
   
flexi auth - A user authentication library for CodeIgniter
Posted: 21 September 2012 09:20 PM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

@Klausch

Cheers for your input.
I’ve noted down your valid points, and I’ll include the updates to the next Github repo push.

 Signature 

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

 
Posted: 24 September 2012 07:33 AM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

I try the live demo (http://haseydesign.com/flexi-auth/auth_lite/demo) but I am not able to log in as public user (logging in as the two others, admin and moderator, does work however.
Can this be confirmed?

 
Posted: 24 September 2012 08:21 AM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

Hey Klausch,
You are indeed correct. Something obviously must have gone awry around launch.
I’ve updated both, the live demo and the Github repo to fix this glitch. The login details remain the same.

 Signature 

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

 
Posted: 26 September 2012 08:12 AM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

Hi,

Thanks again for the quick reaction!
I have downloaded the new zipfile from the Github repo (haseydesign-flexi-auth-806f08e.zip), but when recursively comparing the content with the previous version (b639cc8), no differecnes are reported, except for the file dates…
MAybe I am missing something, but can you tell what has been modified between those two releases?


And one more issue, I have developed a first user registration system for our website, I do not use a separate custom user table but have extended the existing user_account table, which should be perfectly legal accoding to the documentation.

When trying to register a new user, trhe following errors are issued:

A PHP Error was encountered
Severity
Notice
Message
Undefined propertystdClass::$tbl_custom_data
Filename
models/flexi_auth_model.php
Line Number
389

A PHP Error was encountered
Severity
Warning
Message
Invalid argument supplied for foreach()
Filenamemodels/flexi_auth_model.php
Line Number
389

A PHP Error was encountered
Severity
Notice
Message
Undefined variablerow_id
Filename
models/flexi_auth_model.php
Line Number
420 

The errors originate from the fact that in flexi_auth_model.php, the method insert_custom_user_data(...) is called but no variable [‘database’][‘custom’] is defined in the config file.


Already before commiting, the following error was shown. I remember I had seen this error before when running the demo and had commented out line 86, but this was not the solution because the $this->auth->tbl_custom_data is used in the insert_user method.
A PHP Error was encountered
Severity: Notice
Message: Undefined index: custom
Filename: models/flexi_auth_lite_model.php
Line Number: 86
($this->auth->tbl_custom_data = $this->auth->auth_database[‘custom’];)

I think a solution might be defining the [‘database’][‘custom’] variable as an empty array, but this is not mentiond in the confi file so I would like to hear your opinion.

 
Posted: 26 September 2012 09:11 AM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

Hey again Klausch,
It’s good to see you’re making some progress with the library.

Regarding the last Git commit, the only difference was a quick update to the demo sql dump, that would fix the incorrect login details for the ‘public’ user.
You can see the change highlighted @ https://github.com/haseydesign/flexi-auth/commit/806f08e8854598af2d231bc0c4d37903ea9515c2

You would only need to update this if you’re using the demo sql data.
In which case if you could also just use the following sql to update your existing database data.

UPDATE `user_accounts
SET `uacc_password` = '$2a$08$GlxQ00VKlev2t.CpvbTOlepTJljxF2RocJghON37r40mbDl4vJLv2'
    `
uacc_salt` = 'CDNFV6dHmn'
WHERE `uacc_id` = 3

——————————————————————————

Regarding the error with the custom user data, I think you’re using the wrong function for the table you are targeting.

The ‘insert_custom_user_data()’ and ‘update_custom_user_data()’ functions are only for updating data within custom user tables that you have added.

If you have just added additional columns to the main user account table, then you need to define the column name and value via the ‘user_data’ argument in both the ‘insert_user()’ and ‘update_user()’ functions.

Function references:
http://haseydesign.com/flexi-auth/user_guide/user_account_set_data#insert_user
http://haseydesign.com/flexi-auth/user_guide/user_account_set_data#update_user

So if for example you had a custom column within the main user account table named ‘column_1’ and ‘column_2, you would update that column with the following code.

$user_id 101;
$user_data = array('column_1' => 'Column Data #1''column_2' => 'Column Data #2');

update_user($user_id$user_data); 

Note: Ensure you have defined these custom columns in the flexi auth config file via the following setting:

$config['database']['user_acc']['custom_columns'= array('column_1''column_2'); 

 

 Signature 

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

 
Posted: 26 September 2012 12:46 PM   [ Ignore ]   [ # 26 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

Hi,

Thanks again for the info, you are totally right about the difference in the sql script, my diff tool did not consider files with exactly the same size as different… :(

THe second issue is more complicated I am afraid.
I never call insert_custom_user_data() directory directly. What I do is calling the library function insert_user(...):

$response $this->flexi_auth->insert_user($email$username$password$profile_data1$instant_activate); 

which in turn delegates the call to the corresponding function in the flexi_auth_model:

The insert_custom_user_data() is called from this model function, in line 217:

$this->insert_custom_user_data($user_id$custom_data); 


And indeed I have configured the custom columns in the configuration file:

// Custom columns can be added to the main user account table to enable library functions to handle additional custom data stored within the table.
$config['database']['user_acc']['custom_columns'= array(
  
### Example : 'date_modified', 'modified_user_id' etc.
  
'first_name''last_name''company''phone''usertype_id''avatar'
); 

So still struggling with this, I need some more time to figure it out but if you still have some more hints, they are welcome smile

 
Posted: 27 September 2012 07:00 AM   [ Ignore ]   [ # 27 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

I may ‘possibly’ have found the issue that you are having.

Since you say you are not using any custom user data tables, have you by any chance deleted all references to custom users tables in the config file (As you should).
For example, do you have any config setting defined similar to the following:

$config['database']['custom']['YOUR_CUSTOM_TABLE']['table''custom_table'

Without any reference to a custom table, there was a bug in the library that would throw an error warning.

I have since tweaked the lite model to fix this warning appearing.
You can get this update from the Github repo, or just change line 86 in flexi_auth_lite_model.php
to the following:

$this->auth->tbl_custom_data = (! empty($this->auth->auth_database['custom'])) ? $this->auth->auth_database['custom': array(); 

If this doesn’t fix your problem, then can you confirm you have structured your ‘$profile_data’ argument that is being passed to the ‘insert_user()’ function is similar to as follows:

$profile_data = array(
    
'first_name' => 'first name value',
    
'last_name' => 'last name value',
    
'company' => 'company value',
    
'phone' => 'phone value',
    
'usertype_id' => 101,
    
'avatar' => 'avatar value'
); 
 Signature 

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

 
Posted: 27 September 2012 10:19 AM   [ Ignore ]   [ # 28 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

Hi,

I was exactly thinking in that direction. Indeed I have no references to custom tables in the config file. And I had already commented out line 86 of the flexi_auth_lite_model.php so was close to the solution smile

I just did run a first test and it appears the problem is solved! Also the extra custom fields are added correctly to the user_account table.
There remains one warning/error message:

A PHP Error was encountered
Severity
Notice
Message
Undefined variablerow_id
Filename
models/flexi_auth_model.php
Line Number
420 

And this confirms my idea that the return value $row_id of the function insert_custom_user_data(...)  is meaningless, this function loops over zero or ore custom tables, so each of these tables will have a separate insert id. So return the insert id is not possible and in this case, raises a warning because no custom tables exist.

return $row_id;  (line 420

But I have set some more steps towards a working system, thanks for you help again and I will keep you posted!

 
Posted: 27 September 2012 05:11 PM   [ Ignore ]   [ # 29 ]   [ Rating: 0 ]
Avatar
Joined: 2012-09-24
13 posts

Hi I’m a new codeigniter developer and I’m very interested at flexi auth.

I have a problem, in my local webserver, with the demo.

it’s no work

I read the installation guide and make step by step.

When I open the local url (http://test.loc) the demo’s homepage shows but when I want to go on Demo link I see a 404 error and the relative url is http://test.loc:82/auth_lite/demo

why ? where I wrong.

Please help me

Thanks

 Signature 

Curreri Damiano
Software and Web Developer
 
  Phone: +44 (020) 365 942 71
  Fax:    +44 (020) 365 942 71
 
      http://www.damianocurreri.co.uk
      .(JavaScript must be enabled to view this email address)

 
Posted: 28 September 2012 05:38 AM   [ Ignore ]   [ # 30 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

And I have a bunch of more issues… hope you appreciate my input smile

First:
It is about the email actication. When clicking the link in the activation email, the function

auth->activate_account(...)  (line 179

is called, which is delegated to

flexi_auth_model->activate_user($user_id$tokenTRUE); (line 888

Although the documentation of this function tells the return type is “void”, it is actually the boolean result of this function which tells us whether activation was succesful or not.

However, the return value is ignored in the controller method and the caller is redirected to the index page (and from there to the login page).
I think it would be better to use the Boolean return value in a view which tells whether activation was succesful or not. And in the case of a succesful actication, offer a link to the login page.

I am about to implement this, the library class needs not to be modified for this, but the controller does. And of course I am interested in your opinion about this!

Second:
I noticed that the logout function was not working, the call to auth/logout raised an error and the session row was never deleted.
After som research I found the culprit was in the contructor of the auth controller, which I copied from the demo:

if ($this->flexi_auth->is_logged_in_via_password() && uri_string() != ‘auth/logout’) {

The parentheses after the call to uri_string are missing! Adding them solved the problem.


Third
I have noticed that when signin up as a new user, if the email notification does not work, the Flexi_auth->insert_user(...)  function returns with FALSE at line 589, but the inserted record remains in the database. I think that in this case, it should be deleted. BEcause we have some problems with the mail server, we always have to delete the record by hand when the confirnation amil is not send.

In my opinion, the insert of the user and the sending of the email should i fact be considered as one transaction. I think on this level we cannot make use of a real DB transaction because sending the email is not a DB operation, but at least the insert should be undone when email sending fails.
For now, I will make the following modification for this in the library:

(from line 587)    $this->CI->flexi_auth_model->set_error_message('activation_email_unsuccessful''config');
$this->delete_user($user_id); //ADDED KVG
return FALSE


But if you agree we should stay in sync with this because I am reluctant to edit the library itself with regards to future updates… smile

Regards, Klaas

 
Posted: 02 October 2012 07:13 AM   [ Ignore ]   [ # 31 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

One more important issue about inserting NULL values in the database.
I have a custom field in the Useraccount table ‘user_type’ which is an FK to a lookup table, but it is not required and therefore can be NULL.

Problem is that inserting NULL in the database raises an error, this seems to be related to the ActiveRecord library which escapes all values with backtics which is not accepted for NULL values.

I think this should be handled somewhere in the flexi_auth_model.update_user() function, but I want to share this with you first.

EDIT: An alternative would be, adding a value “not specofied” to the lookup table, thereby elimination the need for a NULL value. But I do not favour this solution, it should be possible to update a nullable field to the value of NULL>

The issue appears to be more general in nature and is described in this thread:
http://stackoverflow.com/questions/3509791/codeigniter-activerecord-update-method-refuses-to-insert-null-value?rq=1

Though I still have no solution, escaping the values can be prevented by using the extra parameter on the $this->db->set method, but when using the field-value array approach, this does not work.
Even Phil Sturgeon commented the issue and consiferes it as a bug, but apparently it has not been solved yet.


I have found a solution by modifying the flexi-auth_model->update_user() method
It holds the assumption that a null value is passed in the post array as the string ‘null’, and does not add the quotes when a ‘null’ value is found. The update query code had to be rewritten for this:
In facyt the same goes for the insert, but in this case the lookup field can just be omitted in which case the database default value us used, which is also null.

(from line 315)

if (count($sql_update) > 0)  {
  
//KVG:  handling null values correctly
  
foreach ($sql_update as $field => $value{
    
if (strtolower($value) == 'null'{
      $this
->db->set($field$valueFALSE);
    
else {
      $this
->db->set($field$value); 
    
}
  }
  $this
->db->where($this->auth->tbl_col_user_account['id']$user_id);
  
$this->db->update($this->auth->tbl_user_account);

Regards, Klaas

 

 
Posted: 02 October 2012 07:21 AM   [ Ignore ]   [ # 32 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

@Damiano Curreri

Since you say you can access the demo homepage, you have probably correctly setup the majority of the library and just have a minor error within one of your controllers.

I would double check that the ‘base_url’ and ‘includes_dir’ vars set in parent::__construct of each of your controller files is defined correctly.

$this->load->vars('base_url''http://localhost/your_codeigniter_directory/');
$this->load->vars('includes_dir''http://localhost/your_codeigniter_directory/includes/'); 

From the fact you say you can access the demo homepage which is loaded via the auth_lite controller, I’m presuming its the ‘base_url’ var set in this controller that is the problem.

 Signature 

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

 
Posted: 02 October 2012 07:49 AM   [ Ignore ]   [ # 33 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

@Klausch

You’ve been busy…

insert_custom_user_data()
Regarding the insert_custom_user_data() function and the undefined $row_id var being returned, that’s an obvious error that I’ve somehow missed…
Since potentially multiple row_id’s could be set, I will likely have to overhaul the function a little to ensure it works well.

Regarding your message on 28 September 2012
First
You’re right that the activate_user() function only returns a boolean value, this is what’s in the user guide documentation, but the actual ‘@return’ value within the model incorrectly states it’s void - I’ll update it.

As for the behaviour of how the demo handles the value returned by this function, I’m not too bothered about the current implementation as it’s simply there as an example of using the function, it’s really up to the developer to decide the function interactions within the site.

Second
I think you may have deleted the parentheses from the uri_string() function sometime during your development as its in the current Github repo. Do a search for ‘uri_string()’ on https://github.com/haseydesign/flexi-auth/blob/master/demo_files/application/controllers/auth.php and you should see it there.

Third
It’s an interesting thought to include a database rollback transaction if the sending of the verification email fails.
I could probably implement the feature using CI’s database transactions.

If you were to implement the transactions yourself to a stable level and were willing to share the code, I’d be more than happy to include it in the library with full credits where due.

As for your most recent message regarding NULL values in the database, I’ll read into this later.

You’ve been sticking with the library for a while now, so are you liking it?

 Signature 

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

 
Posted: 02 October 2012 12:29 PM   [ Ignore ]   [ # 34 ]   [ Rating: 0 ]
Joined: 2012-09-13
19 posts

Thanks for your replies on these 3 issues!
Indeed issue 2 is a non-issue, probably I hit the delete key on a wrong moment…
Regarding issue one, thanks for updating.
And about issue three, I will think about that and will definately send you all code which I consider as an improvment or bugfix.

Furthermore, I have posted some extra info under the post about the NULL value issue, and also some code which, for now, addressed the issue.

So far I am impressed by the library, only the demo code is IMHO needlesly complicated and the extra “model” layer between controllers and library is not what I would prefer, but indeed this is in fact separate from the library.

I have to gain more experience with it, but I think it is very workable and the only alternative for IonAuth which lacks some functionality. Keep you informed!

 
Posted: 03 October 2012 07:29 AM   [ Ignore ]   [ # 35 ]   [ Rating: 0 ]
Joined: 2012-03-08
156 posts

@Klausch

I’ve just read your post and the Stack Overflow link regarding NULL values and CI’s ActiveRecord library.

The fact that it’s a CI bug causes problems, as CI could fix it with any update.
Whilst if I was to patch a work around like the code you have provided yourself into the library, I would have to go through every other function within the library to ensure it also patches CI’s bug.

Patching the library would then mean I would have to go through and test that every function within the library still works as intended.

Since I’m short of spare time at the moment, I will add this to my watch list, and if other users are encountering the same problem, I’ll have a look into implementing it.

Thanks for the code snippet.

 Signature 

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

 
2 of 17
2