CodeIgniter Forums
Ion Auth - Lightweight Auth System based on Redux Auth 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Ion Auth - Lightweight Auth System based on Redux Auth 2 (/showthread.php?tid=27435)



Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-11-2011

[eluser]c-s-n[/eluser]
Hi there,

I just wanted to give a bit of feedback to the great Ion Auth library. My Version is exactly one week old and downloaded from github. Codeigniter is v1.7.3

In your example controller you heavily use flashdata. So did i but in conjunction with database sessions.
When I updated a user and got a duplicate error, the new session data could not be stored in the database, because the transaction was not completed and so the flashdata message stayed empty. So here is the fix:

ion_auth_model.php
Code:
// After line 838, before return FALSE:
$this->db->trans_rollback();

Also I changed the english language file a bit - just writing style, not wanted to keep back from you Wink
Code:
// Account Creation
$lang['account_creation_successful']            = 'Account successfully created';
$lang['account_creation_unsuccessful']           = 'Unable to create account';
$lang['account_creation_duplicate_email']      = 'Email already used or invalid';
$lang['account_creation_duplicate_username']      = 'Username already used or invalid';

// Password
$lang['password_change_successful']           = 'Password successfully changed';
$lang['password_change_unsuccessful']            = 'Password change unsuccessful';
$lang['forgot_password_successful']           = 'Password reset email sent';
$lang['forgot_password_unsuccessful']           = 'Password reset unsuccessful';

// Activation
$lang['activate_successful']                = 'Account activated';
$lang['activate_unsuccessful']               = 'Unable to activate account';
$lang['deactivate_successful']                = 'Account deactivated';
$lang['deactivate_unsuccessful']            = 'Unable to deactivate account';
$lang['activation_email_successful']            = 'Activation email sent';
$lang['activation_email_unsuccessful']        = 'Unable to send activation email';

// Login / Logout
$lang['login_successful']                = 'Logged in successfully';
$lang['login_unsuccessful']                = 'Incorrect login';
$lang['logout_successful']               = 'Logged out successfully';
  
// Account Changes
$lang['update_successful']               = 'Account information successfully updated';
$lang['update_unsuccessful']               = 'Unable to update account information';
$lang['delete_successful']               = 'User deleted';
$lang['delete_unsuccessful']               = 'Unable to delete user';

Regards


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-11-2011

[eluser]Ben Edmunds[/eluser]
Thanks c-s-n. I created a GitHub issue for this and I'll look into this when I get a chance: http://github.com/benedmunds/CodeIgniter-Ion-Auth/issues/issue/44


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-14-2011

[eluser]Basketcasesoftware[/eluser]
Been sidetracked with other stuff this weekend, Ben. I'll be getting back to that DataMapper version as soon as I can get back on track. Kind of embarrassing really. :red:


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-16-2011

[eluser]c-s-n[/eluser]
Ok, hi again.

A bit too often now I looked at some database errors produced by Ion Auth. I'm using PostgreSQL DBMS and you know, this is very restrictive related to data types.

I know one could/should check for correct types of variables passed to a function - but look at this example:
Code:
$this->ion_auth->get_user_by_identity( $this->session->userdata('my_user') )
The userdata function returns (bool)FALSE, if - whyever - the key is not existing in the session.
And then your model tries to compare varchar with boolean...

The same thing could happen in your model functions, where you also just rely on the correct session variable type.

To avoid this you should check against the type first in the library, because if done in model and returned NULL, you get things like "Call to a member function row() on a non-object" from library

So this is, what I did in the library to check the parameter (adapt for other functions):
Code:
public function get_user_by_identity($identity) {
  if(!is_string($identity))
    return null;
  ...


public function get_user_array($id=false) {
  if($id !== false && !is_int($id))
    return null;
  ...

Then one can check with
Code:
is_object(($user = $this->ion_auth->get_user_by_identity( $this->session->userdata('my_user') )))
if the request was succesful.

Best regards


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-18-2011

[eluser]c77m[/eluser]
I made the conversion from Tank_auth to Ion_auth last night (which was surprisingly easy). So far I really enjoy this library, but I ran into a problem today that I can't track down.

When loading any page now, I get the following PHP error: Message: Undefined property: Auth::$ion_auth, Filename: core/Model.php, Line Number: 50

It's related to the login session (I logged in last night and checked "Remember me"), but I don't know where to go to resolve it. I have the Ion_auth library in my autoload config, and if I delete the identity and remember_me cookies I can log in with everything being normal.

The CI log for the page load:

Code:
DEBUG - 2011-02-18 13:52:49 --> Config Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Hooks Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Utf8 Class Initialized
DEBUG - 2011-02-18 13:52:49 --> UTF-8 Support Enabled
DEBUG - 2011-02-18 13:52:49 --> URI Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Router Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Output Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Input Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Global POST and COOKIE data sanitized
DEBUG - 2011-02-18 13:52:49 --> Language Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Loader Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Helper loaded: url_helper
DEBUG - 2011-02-18 13:52:49 --> Helper loaded: text_helper
DEBUG - 2011-02-18 13:52:49 --> Database Driver Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Config file loaded: application/config/ion_auth.php
DEBUG - 2011-02-18 13:52:49 --> Email Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Session Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Helper loaded: string_helper
DEBUG - 2011-02-18 13:52:49 --> Session routines successfully run
DEBUG - 2011-02-18 13:52:49 --> Language file loaded: language/english/ion_auth_lang.php
DEBUG - 2011-02-18 13:52:49 --> Model Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Model Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Helper loaded: cookie_helper
DEBUG - 2011-02-18 13:52:49 --> Helper loaded: date_helper
DEBUG - 2011-02-18 13:52:49 --> Session class already loaded. Second attempt ignored.
ERROR - 2011-02-18 13:52:49 --> Severity: Notice  --> Undefined property: Auth::$ion_auth C:\CI\system\core\Model.php 50
ERROR - 2011-02-18 13:52:49 --> Severity: Notice  --> Undefined property: Auth::$ion_auth C:\CI\system\core\Model.php 50
ERROR - 2011-02-18 13:52:49 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at C:\CI\system\core\Exceptions.php:170) C:\CI\system\libraries\Session.php 670
DEBUG - 2011-02-18 13:52:49 --> Model Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Model Class Initialized
DEBUG - 2011-02-18 13:52:49 --> Controller Class Initialized
DEBUG - 2011-02-18 13:52:49 --> File loaded: application/views/admin/index.php
DEBUG - 2011-02-18 13:52:49 --> Final output sent to browser
DEBUG - 2011-02-18 13:52:49 --> Total execution time: 0.1941

EDIT:

This seems to be the same error that was referenced in a post last year (http://ellislab.com/forums/viewreply/736434/). It seems to only happen when I have logged in via multiple browsers and the ci_session cookie has expired. (I set the Ion_auth cookie to expire after a week, but ci_session expires after two hours by default.)

I haven't looked through the code in enough detail to verify the proposed fix is ideal, but I suspect I'll have to before rollout time.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-18-2011

[eluser]Glazz[/eluser]
@c77m - The fix: https://bitbucket.org/ellislab/codeigniter/issue/252/undefined-method-error-produced-when-using


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-19-2011

[eluser]fran-quero[/eluser]
Hello. Congratullations for this great library.

I´m new in CI and I´m testing Ion Auth in a test application.

I´d like to set access based on groups.

1. I haven´t see that in the code. Is there any pre-made function or way to do it?

2. If there isn´t, please, check my code to know if I have done a good practice, or if there´s a better way to do it:

I have added a function to ion_auth_model.php to control if the user´s group is allowed to acces and optionally if the user have made a payment (in my application there are free and payments users)

ion_auth_model.php
Code:
public function access($allowed_group,$check_payment=false)
    {
        if($user=$this->ion_auth->get_user())
        {
            if($user->group_id>=$allowed_group)
            {
                if($check_payment)
                {
                    if($user->payment)
                    {
                        return true;
                    } else {
                       redirect('welcome');
                    }
                } else {
                    return true;
                }
            } else {
                redirect('welcome');
            }
        } else {
            redirect('auth','refresh');
        }
    }

When I want to set the access level to a controller I add:
Code:
$this->ion_auth->access(2,true);//Grant access to users from group 2 or higher who have paid

I´m new in CI and in MVC, is that a good practice? Is there a better way to do this?

Thanks for your advice.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-19-2011

[eluser]c77m[/eluser]
[quote author="Glazz" date="1298104586"]@c77m - The fix: https://bitbucket.org/ellislab/codeigniter/issue/252/undefined-method-error-produced-when-using[/quote]

Glazz, thanks for the link. I'm very much opposed to hacking the CI core to hide a library bug, but this link will hopefully help me track down the offending code in the library when I have a few more minutes.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-19-2011

[eluser]c77m[/eluser]
[quote author="fran-quero" date="1298168229"]Hello. Congratullations for this great library.

I´m new in CI and I´m testing Ion Auth in a test application.

I´d like to set access based on groups.

1. I haven´t see that in the code. Is there any pre-made function or way to do it?
[/quote]

fran-quero,

There is already a function, is_group(), that will check group membership for you. (http://benedmunds.com/ion_auth/#is_group)

Quote:
Code:
if($user=$this->ion_auth->get_user())

As written, this will always return true. ;-)


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 02-19-2011

[eluser]fran-quero[/eluser]
[quote author="c77m" date="1298168683"]
There is already a function, is_group(), that will check group membership for you. (http://benedmunds.com/ion_auth/#is_group)
[/quote]

Thanks! I should have read more :red:

[quote author="c77m" date="1298168683"]
Code:
if($user=$this->ion_auth->get_user())
As written, this will always return true. ;-)[/quote]

No if the user is not logged in. I use it to check it. Now I will combine logged_in() + is_group().

Thanks again!