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.

Ion Auth - Lightweight Auth System based on Redux Auth 2

February 10, 2010 7:00pm

Subscribe [287]
  • #1 / Feb 10, 2010 7:00pm

    Ben Edmunds's avatar

    Ben Edmunds

    812 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,

  • #2 / Feb 10, 2010 10:45pm

    Julien Dreux

    3 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

  • #3 / Feb 10, 2010 11:33pm

    Ben Edmunds's avatar

    Ben Edmunds

    812 posts

    Thanks Julien,

    You can use ->is_group(‘moderator’)


    Enjoy,

  • #4 / Feb 11, 2010 8:58pm

    betabeta

    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.

  • #5 / Feb 11, 2010 11:14pm

    Ben Edmunds's avatar

    Ben Edmunds

    812 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!

  • #6 / Feb 12, 2010 1:00am

    betabeta

    3 posts

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

  • #7 / Feb 12, 2010 3:43am

    betabeta

    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.

  • #8 / Feb 12, 2010 4:15pm

    Markko's avatar

    Markko

    4 posts

    Hey!

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

  • #9 / Feb 12, 2010 4:16pm

    Ben Edmunds's avatar

    Ben Edmunds

    812 posts

    Markko,

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

  • #10 / Feb 13, 2010 4:16am

    Markko's avatar

    Markko

    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!? 😉

  • #11 / Feb 13, 2010 10:40am

    atno's avatar

    atno

    65 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

  • #12 / Feb 13, 2010 5:19pm

    2think

    125 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?  😉

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

  • #13 / Feb 13, 2010 10:20pm

    Ben Edmunds's avatar

    Ben Edmunds

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

  • #14 / Feb 18, 2010 9:36pm

    2think

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

  • #15 / Feb 18, 2010 10:16pm

    Ben Edmunds's avatar

    Ben Edmunds

    812 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!

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

ExpressionEngine News!

#eecms, #events, #releases