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]
  • #931 / May 18, 2011 11:32pm

    Ben Edmunds

    812 posts

    Andy78,

    You can still use it through the Ion Auth library but you’d want to make a DataMapper model for the basics like querying users.

  • #932 / May 20, 2011 1:52am

    austintbiggs

    40 posts

    After checking some DB values I’ve found that once a user is deleted that their ID is not reused. In fact there are gaps in between ID numbers once new accounts are created, I’m aiming to fix this “bug” in my own system.

    For example, I create 5 new accounts and their ID in the DB is set to Auto_Increment. If I delete user 3 I would like for the ID 3 to be reused upon creating a new account, but instead a gap is created. Instead of using auto_increment how would I reuse the lowest available ID?

    Hopefully this post is understandable.

    The resulting ID numbers after the above are: 1, 2, 4, 5, [6]

  • #933 / May 20, 2011 2:01am

    Ben Edmunds

    812 posts

    austintbiggs,

    You DO NOT want to re-use IDs.

    IDs should be a completely unique identifier and will be referenced throughout your application, emails that are sent, bookmarks, etc.  Also, if you have relations setup, and forget to cleanup on user delete or something happens, you do not want that data related to a new user.

    There is no good reason to re-use IDs (size is not a valid reason) so take it from experience and just don’t.

  • #934 / May 20, 2011 5:13am

    austintbiggs

    40 posts

    That’s a valid point, I didn’t even really think of that. Thanks, I could’ve really messed up :]

  • #935 / May 22, 2011 10:00pm

    Ben Edmunds

    812 posts

    Hey everybody,

    I’ve made a good bit of progress with Ion Auth v2 so I’d like to invite people to beta test and give me feedback/suggestions.  Ion Auth v2 is not backwards compatible but you’re DB would be easy enough to upgrade. 

    This update adds multiple groups per user, more powerful querying, fixes the issue with emails, and adds hooks so the library can be extended properly.


    The code can be found here: http://github.com/benedmunds/CodeIgniter-Ion-Auth/tree/2


    Thanks!

  • #936 / May 22, 2011 10:28pm

    austintbiggs

    40 posts

    Exactly how difficult would it be to migrate or update the db? Do you have a list of the differences / changes so we can make them? or is there a doc somewhere?

  • #937 / May 22, 2011 10:45pm

    shenanigans01

    36 posts

    Ben : do you have a change lot / list of updates for the V2. I’d like to give it a test but also know what changes were made to the system

  • #938 / May 22, 2011 10:50pm

    Ben Edmunds

    812 posts

    austintbiggs mikem562,

    Not ATM, it’s still very alpha.  You can look at the SQL file to see the DB differences, the group_id is removed from the users table and a new users_groups table is added to support the user -> groups relations.

  • #939 / May 27, 2011 12:36pm

    joytopia

    76 posts

    Ben,

    perhaps I could test it in a current project.
    Database changes seem to be easy.
    But do all old methodes keep on working like before?

    Best regards

    Bernd

  • #940 / May 27, 2011 12:50pm

    Ben Edmunds

    812 posts

    Bernd,

    No the methods have changed as well.

    For example, to get the current user as an object you do:

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

    to get the current user as an array:

    $user_array = $this->ion_auth->user()->result_array();

    or to get all the active users order desc by id do:

    $users = $this->ion_auth->where('active', 1)
                            ->order_by('id', 'desc')
                            ->users()
                            ->result();
  • #941 / May 27, 2011 4:13pm

    malcomhfc

    27 posts

    Ben when i echo $user i just get Array.

    Im trying to insert the logged in user into the database table website(for comment system and learning purposes. I know it looks bad but im learning 😊)

    if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $this->ion_auth->user()->result_array())))

    Also tried to do it with out result_array

    if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $this->ion_auth->user()->result())))

    Any idea why the output is Array?

    Error Number: 1054
    
    Unknown column 'Array' in 'field list'
    
    INSERT INTO `comments` (`doWebsite`, `doUser`) VALUES ('http://test.com', Array)
  • #942 / May 27, 2011 4:19pm

    Ben Edmunds

    812 posts

    malcomhfc,

    You probably only want to insert the user id.  You can’t stick an array in a DB field without serializing it, and that is bad practice for most situations.

    Are you using Ion Auth v1 or v2?

    v1 code is:

    $user = $this->ion_auth->get_user();
    if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))

    v2 code is:

    $user = $this->ion_auth->user()->result();
    if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))
  • #943 / May 27, 2011 4:53pm

    malcomhfc

    27 posts

    I just get the error

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Trying to get property of non-object
    
    Filename: controllers/account.php
    
    Line Number: 32

    the line is the one above ^. Im using version 2 for ion_auth. I take it the problem could just be my code in the model?

    its just a simple function

    function addDomain($options = array()) 
         {
             //required values
            if(!$this->_required(
                array('doWebsite', 'doUser'),$options) 
            )return false;
            
            $this->db->insert('comments', $options);
            
            return $this->db->insert_id();
         }

    Thanks a lot for your assistance Ben 😊

  • #944 / May 27, 2011 5:03pm

    Ben Edmunds

    812 posts

    malcomhfc,


    It could be because I gave you the wrong v2 code 😉 it should be:

    $user = $this->ion_auth->user()->row();
    if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))

    If that doesn’t work, please answer these questions:

    1. What’s on line 32? 

    2. Are you sure your logged in? 

    3. What do you get if you var_dump($user)?

    4. What do you get if you do:

    var_dump($this->ion_auth->current()->user()->row());
  • #945 / May 27, 2011 5:19pm

    malcomhfc

    27 posts

    Ah that worked thank you. Using the correct code helps most times :D. Thanks so much!

    Was that in the docs and i have missed it or is there new docs to be released once ion_auth 2 is finished? dont know php well enough to look through your library and see the correct usage 😊 I have a habit of using everything bleeding edge.

    Thanks again Ben.

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

ExpressionEngine News!

#eecms, #events, #releases