ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

flexi auth - A user authentication library for CodeIgniter

September 15, 2012 1:51am

Subscribe [104]
  • #16 / Sep 19, 2012 8:19pm

    haseydesign

    171 posts

    @Klausch

    Let me try to clear up some of your confusion.

    The split between the ‘lite’ library and the ‘main’ library should be considered a feature, it is not a requirement.
    Whenever you include the main library, it extends the lite library meaning functions in both versions are available to you.
    If you want to include the main library on every page, that is fine, it will just consume a little more memory on every page load.

    The easiest way to look at the purpose of each library version is this:

    + The lite library is used to getting user data, and for checking user credentials - things that you are likely to need to do on every page load - e.g. checking whether a user is logged in and then displaying their name.

    + The main library is the work horse, performing actions like login, registration and forgotten password functionality. You are likely to only need to use these functions when a specific action happens, like a login form being submitted.

    An example of the how/why you would use the lite library can be seen at http://haseydesign.com/flexi-auth/auth_lite/lite_library (Login as different demo users to see how different data is returned).

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

    Regarding you not being able to find the login() method in either model, its in the ‘flexi_auth_model’, but there is no reason for you to change any data within any of the flexi auths model or library files.
    The demo models are purely for the examples within the demo site and have no part in how flexi auth works - they are examples of how to use flexi auth functions within a website.

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

    Regarding the ‘base_url’ being defined in each controller, this is purely for the purposes of the demo so that it is easier for users to quickly get setup and running.
    The 3 vars that are set within each controller are defined there so that they are available for creating href link paths within Views.
    It is not used in the same was as the ‘base_url’ defined within CI’s config.php file that is used for routing.

  • #17 / Sep 19, 2012 8:20pm

    haseydesign

    171 posts

    @karanits

    I would presume there is an incorrect setting somewhere in the flexi_auth config file, but without looking at your setup it hard to know what the specific problem is that’s causing the error.

    What I would suggest is that you start a brand new bare installation of CI and flexi auth, then run through the installation guide @ http://haseydesign.com/flexi-auth/user_guide/installation
    It is very important that this guide is closely followed, as the slightest omission can cause errors.

    Then just follow examples within the demo files on how to setup your controller and a basic view file.
    Do not get complicated from the start, just have a simple form within the view file that gets a user to login and see how it goes.

    To give you some example data, you may want to use the sql dump and the flexi auth config files from the demo to give you a head start.
    Once you get the basics working, then customise the database tables and config file settings to your requirements.

  • #18 / Sep 20, 2012 3:16am

    karanits

    2 posts

    @haseydesign
    I found the issue. the errors come when ‘form_validation’ library is auto-loaded in beginning. Is there a specific reason for this error or is it still my installation issue.

    PS: this time i did a complete new install.

  • #19 / Sep 20, 2012 3:25am

    haseydesign

    171 posts

    @karanits

    That actually sounds like that’s a bug with the library, something that I will try and test out ASAP.
    I’ll keep you posted with my testing.

    Thanks for reporting this.

  • #20 / Sep 20, 2012 8:39am

    Klausch

    16 posts

    @Klausch

    Let me try to clear up some of your confusion.

    The split between the ‘lite’ library and the ‘main’ library should be considered a feature, it is not a requirement.
    Whenever you include the main library, it extends the lite library meaning functions in both versions are available to you.
    If you want to include the main library on every page, that is fine, it will just consume a little more memory on every page load.

    The easiest way to look at the purpose of each library version is this:

    + The lite library is used to getting user data, and for checking user credentials - things that you are likely to need to do on every page load - e.g. checking whether a user is logged in and then displaying their name.

    + The main library is the work horse, performing actions like login, registration and forgotten password functionality. You are likely to only need to use these functions when a specific action happens, like a login form being submitted.

    An example of the how/why you would use the lite library can be seen at http://haseydesign.com/flexi-auth/auth_lite/lite_library (Login as different demo users to see how different data is returned).

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

    Regarding you not being able to find the login() method in either model, its in the ‘flexi_auth_model’, but there is no reason for you to change any data within any of the flexi auths model or library files.
    The demo models are purely for the examples within the demo site and have no part in how flexi auth works - they are examples of how to use flexi auth functions within a website.

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

    Regarding the ‘base_url’ being defined in each controller, this is purely for the purposes of the demo so that it is easier for users to quickly get setup and running.
    The 3 vars that are set within each controller are defined there so that they are available for creating href link paths within Views.
    It is not used in the same was as the ‘base_url’ defined within CI’s config.php file that is used for routing.

    Hi, thanks again for your reply. I think I am getting things a bit better now.
    I made a sketch for myself to clear up some issues, I understand now that the flexi_auth_model class just extends the flexi_auth_model lite class and for the first tests I can just use the subclass version.

    Other issue was the demo model classes which I first considered to be a replacement for the core model classes, but now I understand that they are just another layer:
    Summarized the layers can be shown as follows:

    |---------- DEMO  FILES --------------------|  |---------- CORE FLEXIAUTH LIBRARY FILES ----|
     views <--- demo controllers --> demo model -> library -->l ibrary model ---> database tables

    Remains the issue of the 3 vars in each controller, I think is is still messy that they should be modified in 5 places or so, and a constant could be better defined for it, but maybe I am missing something yet…
    After talking to my project leader we continue evaluating FlexiAuth and will tryo to set up a basic register/login system next weeks. So I will keep you informed…

  • #21 / Sep 21, 2012 5:47am

    Klausch

    16 posts

    Some issues about the data model:

    CREATE TABLE `user_accounts` (
      PRIMARY KEY (`uacc_id`),
      UNIQUE KEY `uacc_id` (`uacc_id`),

    This is what I meant by a redundant unique index, a field which is defined as primary key is unique by definition, so the UNIQUE KEY constraint is superfluous.
    This is also found in some other tables.

    A potential more severe problem is:

    CREATE TABLE `user_privilege_users` (
      `upriv_users_id` smallint(5) NOT NULL AUTO_INCREMENT,
      `upriv_users_uacc_fk` int(11) NOT NULL,
      `upriv_users_upriv_fk` smallint(5) NOT NULL,
      PRIMARY KEY (`upriv_users_id`),

    First, I do not see the added value of an auto increment key in a link table. The combination of both FK field is already unique and perfectly suitable as primary key.
    Worse, the upriv_users_id PK field, if used,  should not be a smallint. One of the foreign key fields refers to the User Account table and because each user can have more privileges, the potential number of entries of this link table is higher than the number of users.
    So IF a separate auto-increment PK field is used, it should at least be as big as the biggest of the FK fields, so it ahould be an INT and surely not a SMALLINT.

  • #22 / Sep 21, 2012 9:20pm

    haseydesign

    171 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.

  • #23 / Sep 24, 2012 7:33am

    Klausch

    16 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?

  • #24 / Sep 24, 2012 8:21am

    haseydesign

    171 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.

  • #25 / Sep 26, 2012 8:12am

    Klausch

    16 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 property: stdClass::$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()
    Filename: models/flexi_auth_model.php
    Line Number: 389
    
    A PHP Error was encountered
    Severity: Notice
    Message: Undefined variable: row_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.

  • #26 / Sep 26, 2012 9:11am

    haseydesign

    171 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');

     

  • #27 / Sep 26, 2012 12:46pm

    Klausch

    16 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_data, 1, $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 😊

  • #28 / Sep 27, 2012 7:00am

    haseydesign

    171 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'
    );
  • #29 / Sep 27, 2012 10:19am

    Klausch

    16 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 😊

    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 variable: row_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!

  • #30 / Sep 27, 2012 5:11pm

    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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases