EllisLab text mark
Advanced Search
1 of 89
1
   
Ion Auth - Lightweight Auth System based on Redux Auth 2
Posted: 10 February 2010 07:00 PM
Avatar
Joined: 2009-07-26
823 posts

Hey everybody,

Just wanted to “officially” announce the release of Ion_Auth.  It’s based on Redux Auth 2 but with a whole lot more awesomeness added in.

You can get it here:
http://github.com/benedmunds/CodeIgniter-Ion-Auth


Redux Auth 2 had a lot of potential.  It’s lightweight, simple, and clean,
but had a ton of bugs and was missing some key features.

So I’ve refactored the code and added new methods and functions with the much
appreciated help of Phil Sturgeon.

INSTALLATION:
Just copy the files from this package to the corresponding folder in your
application folder.  For example, copy Ion_auth/config/ion_auth.php to
system/application/config/ion_auth.php.

USING THE LIBRARY: 
In the package you will find example usage code in the controllers and views
folders.  The example code isn’t the most beautiful code you’ll ever see but
it’ll show you how to use the library and it’s nice and generic so it doesn’t
require a MY_controller or anything but it will be easy to add render() methods
if needed since there is only one load->view() per controller method. 


IMPORTANT: 
It is highly recommended that you use encrypted database sessions for security!

Feel free to send me an email if you have any problems.


Thanks,

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 10 February 2010 10:45 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-10-12
7 posts

Hi Ben,

I was just looking for a nice authentication library. I really like redux but it seems to be dead now, unfortunately. So I like what you’re doing.

I saw in your sample controller that you called functions like $this->ion_auth->logged_in() or $this->ion_auth->is_admin(). Is it possible with Ion Auth to define custom roles like for example $this->ion_auth->is_moderator() without having to modify the library?

I just released a new version of TagMVC that could use a feature like that.

Cheers,

Julien

 
Posted: 10 February 2010 11:33 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
823 posts

Thanks Julien,

You can use ->is_group(‘moderator’)


Enjoy,

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 11 February 2010 08:58 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-02-11
3 posts

Hi Ben,

Giving your library a shot. Perfect timing for my project. Thanks for sharing!

I’m still learning codeigniter but I found a couple little bugs and also have a suggestion to pass by you. I can keep posting to this thread if this is helpful.

Thanks again.


auth.php, line 167, remove line:
echo $reset; //debug

auth/index.php, line 21, change line:
<td><?php echo $user[‘group_description’];?></td>
to
<td><?php echo $user[‘group’];?></td>

Also would you ever consider adding a session variable ‘identity’, so the code maps more cleanly to which identity you choose in config?

ion_auth_model, line 537:
$this->session->set_userdata(‘identity’,  $result->{$this->identity_column});

And delete in logout
Ion_auth.php, line 255:
$this->ci->session->unset_userdata(‘identity’);

(Or maybe do the unsetting in the model)

Thanks once more.

 
Posted: 11 February 2010 11:14 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
823 posts

Hey betabeta,

Thanks for the feedback!


The first two errors are fixed now and for the question about identity you can use

$identity $this->session->userdata($this->config->item('identity')); 

will this do what you need?

 

Thanks!

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 12 February 2010 01:00 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-02-11
3 posts

Thanks! That’s a much better way to do it.

 
Posted: 12 February 2010 03:43 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-02-11
3 posts

Hi Ben,

A couple more for you to fix activation emails:

controller/auth.php

Line 211 to 213:
// delete lines because new users are the ones that need to create accounts

if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin()) {
    redirect
('auth''refresh');


libraries/Ion_auth.php

Line 203:
// deactivate takes $id instead of $username

$deactivate $this->ci->ion_auth_model->deactivate($register); 

Line 212:
// need to add ->row() or else can’t get properties for email

$user            $this->ci->ion_auth_model->get_user($register)->row(); 


Also it’s weird to me that session vars are set in the model but deleted in the library.


I hope this is helpful.


EDIT: The activation email bugs mention here were resolved in the source as of 2010 Feb 13. Thanks.

 
Posted: 12 February 2010 04:15 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2010-02-10
4 posts

Hey!

How do I fetch eg. user id (or any data) from database who’s currently logged in?

 
Posted: 12 February 2010 04:16 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
823 posts

Markko,

$user = $this->ion_auth->get_user();

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 13 February 2010 04:16 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2010-02-10
4 posts

Okey thanks Ben!

// Edit
Are you planning to make some documentation for your awesome Auth? I know this should be simple but what can I do when i’m still CI noob!? wink

 
Posted: 13 February 2010 10:40 AM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-29
77 posts

Hi Ben,

Your auth seems promising, are you able to keep it up to date for the next couple of years?

Thanks a lot for your time mate.
atno

 Signature 

Junior PHP dev looking for a project to get started with.

 
Posted: 13 February 2010 05:19 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2008-01-18
128 posts

@atno,
It would be great if Ben could predict those next couple years - not just for himself but can you imagine what that would do for Codeigniter itself?  wink

@Markko,
Check out his controllers in the download sample and the library code itself. Documentation would be great but the code really is extremely well written with comments.

 
Posted: 13 February 2010 10:20 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
823 posts

Markko,

I’m really bad about documentation so I tried to make the code easy to understand and build a comprehensive demo.


If you have questions or need additional support feel free to email me.


atno,

I definitely plan to continue supporting it.  If something ever comes up where I can’t I’ll pass it off to someone else so don’t worry about losing support.

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 18 February 2010 09:36 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2008-01-18
128 posts

Ben,

Great library/solution. After updating to your most recent code on Github (commit_id: 18e39bd1), I noticed after login that I was redirected to http://my.domain.com// (<—-notice the extra slash).

The base_url in my config is a sub-domain, don’t know if that mattered any but doubt it.

Anyway, I switched my code in the app/controllers/auth.php to the following:

...controllers/auth.php

//log the user in
    
function login()
    
{
        $this
->data['title'"Login";
        
$redirect_uri_successful_login $this->config->item('base_url',TRUE);

        
//validate form input
        
$this->form_validation->set_rules('email''Email Address''required|valid_email');
        
$this->form_validation->set_rules('password''Password''required');

        if (
$this->form_validation->run() == true//check to see if the user is logging in
            
if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'))) //if the login is successful
                //redirect them back to the home page
                
$this->session->set_flashdata('message'"Logged In Successfully");
                
redirect($redirect_uri_successful_login'refresh');

... 

I’m thinking you could set this in your ion_auth.php in the config folder?

 
Posted: 18 February 2010 10:16 PM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-26
823 posts

Thanks for pointing that out 2think.

The controller is just example code so feel free to modify it as much as needed.  I went ahead and pushed a change to use base_url instead of ‘/’ in the home page redirects.


Thanks!

 Signature 

BenEdmunds.com

Contact Me:                                    My Code: 

  ben.edmunds@gmail.com            Github
  @benedmunds

 
Posted: 20 February 2010 07:24 AM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-14
95 posts

Hi,
I have user redux_auth with extensive customisation that I did myself. Particularly:
1) Added the ability to login with email OR username
2) Introduced error messages, such as “Incorrect username/password”

Will this library support the above mentioned features?

 
1 of 89
1