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]
  • #661 / Dec 03, 2010 4:51am

    Timothy_

    100 posts

    2think,

    Could you please elaborate a little.

    As I said I have already changed the database call in the ion auth model thinking that most if not all database actions happen in there.

    I tried connecting to the other DB just before my register action in my controller but no luck.

    Thanks

    Tim

  • #662 / Dec 03, 2010 12:17pm

    techgnome

    182 posts

    Just continuing from above. I am curious to see if I can get ION_AUTH to connect to another database that is not the default in CI.

    I tried changing line 66 in ion_auth_model.php

    $this->load->database('myaccount', TRUE);

    No luck.

    The user was still registered to the SITE database not the MYACCOUNT database

    Any suggestions??

    Thanks,

    Tim

    I think that was the right idea… but not executed all the way correctly.

    When you use the TRUE parameter, it returns the database connection. So you need to capture it.

    Add

    public $ion_db; // Or what ever you want to call it

    to the list of variables at the top of the ion_auth model… change line 66 to

    $this->ion_db = $this->load->config('ion_auth', TRUE);

    Now, here comes the part that sucks… all occurrences of $this->db would need to be changed to $this->ion_db (or what ever you want to call it).

    -tg

  • #663 / Dec 03, 2010 1:40pm

    chipperclocker

    1 posts

    So then include the login form as part of your view. There’s nothing that says the login form has to be it’s own view. Just make sure the form posts to the right controller, and if it fails that it redirects to an appropriate page.

    -tg

    TY techgnome for your reply.  I tried this and I get Undefined variable: message, username and password.

    I have placed the auth controller index code into my home index controller and I copied the login function also.  I also loaded the library(‘ion_auth’).

    Todlerone,

    Would you mind posting what your solution to this issue was? I am experiencing the exact problem as I try to load the auth/login view from within another page.

  • #664 / Dec 03, 2010 2:11pm

    2think

    125 posts

    In very draft pseudo-code because I’m on lunch and need to eat(LOL!):

    In your controller’s constructor or your method, wherever you call your DB connect, you connect to the alternative DB then call Ion_Auth.

    The problem with this is if you have any base controllers and within them you do Ion_Auth checking.

    *****Security point/discuss

    You said that you were separating your DBs for security? Perhaps there are other ways you can secure your app because if you think about it, should one DB become compromised, an attacker might quickly realize that the compromised DB doesn’t have all the data they may want.

  • #665 / Dec 03, 2010 2:24pm

    woeps

    4 posts

    I have tracked down my error producing this message when using the username_check-method:

    A Database Error Occurred

    Error Number: 1064

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE `username` = ‘administrator’’ at line 2

    SELECT COUNT(*) AS `numrows` WHERE `username` = ‘administrator’

    Just in case another one will make the same dumb mistake (it took me days to track it down) I want to share my experience:

    I put the ion_auth-config file into the autoload-array (don’t do this! xD)

    Becaus of this fact the config-file couldn’t get loaded into a seperate config-array (via $this->ci->load->config(‘ion_auth’, TRUE) ) which is expected by the ion_auth-controller & model.

    Now everything works perfect again!
    (This is a great library! Thanks!)

  • #666 / Dec 03, 2010 7:01pm

    Todlerone

    63 posts

    Todlerone,

    Are you passing a proper group name in your register method call?  Is your default group setup properly in the config file?

    TY again Ben.  Since I couldn’t pinpoint what I changed that caused the problem I just recopied the original model and controller and started over.  I’m still getting the error.  But that’s ok because I want to add a form field to select a user group anyway this should take away the NULL value.  I was able to add the form field and pass the value.  Is there a way to pass the get_groups() array to the form data array?

    $groups=$this->ion_auth_model->get_groups();
    
    $this->data['group_id'] = array('name' => 'group_id',
    'id' => 'group_id',
    'type' => 'text',
    'value' => $this->form_validation->set_value('group_id'),
    );

    How could I use:

    echo form_dropdown('group_id', $groups);

    Or should I pass a $data[‘groups’] over to the view and echo it out there.

    TY for your time

  • #667 / Dec 03, 2010 7:48pm

    Ben Edmunds

    812 posts

    Todlerone,

    You’d want to build an array of the dropdown options and pass that to the view, or just pass the groups to the view and build the array there.

    So do something like this:

    $groups = $this->ion_auth_model->get_groups();
    
    foreach ($groups as $group)
        $this->data['groups_dropdown'][$group->name] = ucfirst($group->name); 
    
    print_r($this->data['groups_dropdown']);

    Or you could build the ID into the key if you want, depends on how you want to process it…

  • #668 / Dec 03, 2010 7:56pm

    Ben Edmunds

    812 posts

    Timothy_,

    It depends on how your logic is laid out but if you want to only use the alternate DB is a specific place you could do something like this:

    $this->load->database('normal'); //you're probably autoloading this
    
    $this->normal_db = $this->db;
    $this->alt_db    = $this->load->database('alt', TRUE); 
    
    //do normal stuff
    $my_poop = $this->poop_model->get_poop(array('green', 'brown', 'red', 'WTFisThis'));
    
    
    //do alt db stuff
    $this->db =& $this->alt_db;
    $user = $this->ion_auth->get_user();
    
    
    //do normal stuff again
    $this->db =& $this->normal_db;
    $this->poop_model->add_to_user($user->id);


    You’ll have to make sure you initialize the library correctly as well.


    Make sense?

  • #669 / Dec 05, 2010 12:38am

    Timothy_

    100 posts

    Hello Ben,

    Thanks for that. I don’t quite understand this line

    $this->db =& $this->alt_db;

    Is it like a switch?

    I tried to implement it but unfortunately no luck. The user is still registering in the SITE db.

    I’ll try techgnomes solution and see if that works for me.

    Thanks,

    Tim

  • #670 / Dec 05, 2010 12:41am

    Ben Edmunds

    812 posts

    Timothy_,

    $this->db =& $this->alt_db;

    Assigns $this->db as a reference to $this->alt_db.  Since Ion Auth model uses $this->db it should then reference your alt_db.

  • #671 / Dec 06, 2010 6:15am

    Yoosuf Muhammad

    25 posts

    I see a problem with ion_Auth, which is mainly about session;
    When I logged in, if I wanted to go for another controller, via URL, by entering in the address bar, the controller redirects to the login function

    For i.e.

    http://localhost/account
    http://localhost/auth /login

    Actually how to come out form this issue?

  • #672 / Dec 06, 2010 10:24am

    techgnome

    182 posts

    Hard to say. I don’t know about any one else around here, but I’m not clairvoyant. I’m guessing that since I haven’t had this problem (and I use Ion Auth too), that there’s something not right in your controller. In other words, can you show us the code?

    -tg

  • #673 / Dec 06, 2010 10:35am

    Ben Edmunds

    812 posts

    Muhammad,

    I don’t understand the question….

  • #674 / Dec 06, 2010 7:27pm

    Todlerone

    63 posts

    Hello everyone.  Sorry for the simple questions.  I’ve successfully implemented Ion Auth as a log in.  Works great.  Now I’m trying to add some functionality to my website.  I have a model that stores personal information (limited).  All I’m trying to do is add their username to the table (not through a form) for creating/editing the data.  The form doesn’t error but the $user[‘username’] comes up empty.  Sorry I don’t have the code (it’s at work).  What is the difference between passing variables with $data[‘username’] and $this->data[‘username’]?

    TY

  • #675 / Dec 06, 2010 7:38pm

    Ben Edmunds

    812 posts

    Todlerone,

    Just the scope of the variable.  $this->data can be accessed from any class method while $data can only be accessed in the current method.

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

ExpressionEngine News!

#eecms, #events, #releases