Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]Timothy_[/eluser]
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

[eluser]techgnome[/eluser]
[quote author="Timothy_" date="1291386394"]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

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

No luck.

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

Any suggestions??

Thanks,

Tim[/quote]

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
Code:
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
Code:
$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

[eluser]Unknown[/eluser]
[quote author="Todlerone" date="1290812274"][quote author="techgnome" date="1290756490"]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[/quote]
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').[/quote]

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.

[eluser]2think[/eluser]
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.

[eluser]woeps[/eluser]
I have tracked down my error producing this message when using the username_check-method:
[quote author="woeps" date="1290599108"]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'
[/quote]

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

[eluser]Todlerone[/eluser]
[quote author="Ben Edmunds" date="1291363833"]Todlerone,

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

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?

Code:
$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:
Code:
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

[eluser]Ben Edmunds[/eluser]
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:

Code:
$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...

[eluser]Ben Edmunds[/eluser]
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:

Code:
$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?

[eluser]Timothy_[/eluser]
Hello Ben,

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

Code:
$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

[eluser]Ben Edmunds[/eluser]
Timothy_,

Code:
$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.




Theme © iAndrew 2016 - Forum software by © MyBB