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]
  • #646 / Nov 30, 2010 12:22pm

    33cent

    26 posts

    Ben Edmunds,

    did you think about adding triggers into Ion Auth, something similar to Events in dx_auth?

    reference: http://dexcell.shinsengumiteam.com/dx_auth/general/events.html

  • #647 / Nov 30, 2010 11:02pm

    Ben Edmunds

    812 posts

    33cent,

    For the most part everything you do with Ion Auth is called by you in a controller so you should be able to add any hooks or triggers you want to in your controller code.

    Is there anywhere in particular that you need a trigger?

  • #648 / Dec 01, 2010 10:32am

    Todlerone

    63 posts

    What does your controller and form code look like? I don’t know about others here, but I’m not clairvoyant.

    -tg

    TY for your responce.  I eventually worked it out.  What I’m having a problem with now is the meta and user MySql tables.  I have created a username column in the meta table but phpmyadmin won’t let me set a foreign key index to the users table so that the username is passed.

    CREATE TABLE IF NOT EXISTS `meta` (
      `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
      `user_id` mediumint(8) unsigned DEFAULT NULL,
      `username` varchar(15) NOT NULL,
      `first_name` varchar(50) DEFAULT NULL,
      `last_name` varchar(50) DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `user_id` (`user_id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
    
    
    CREATE TABLE IF NOT EXISTS `users` (
      `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
      `group_id` mediumint(8) unsigned NOT NULL,
      `ip_address` char(16) NOT NULL,
      `username` varchar(15) NOT NULL,
      `password` varchar(40) NOT NULL,
      `salt` varchar(40) DEFAULT NULL,
      `email` varchar(100) NOT NULL,
      `activation_code` varchar(40) DEFAULT NULL,
      `forgotten_password_code` varchar(40) DEFAULT NULL,
      `remember_code` varchar(40) DEFAULT NULL,
      `created_on` int(11) unsigned NOT NULL,
      `last_login` int(11) unsigned DEFAULT NULL,
      `active` tinyint(1) unsigned DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
    
    
    ALTER TABLE `meta`
      ADD CONSTRAINT `meta_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
  • #649 / Dec 01, 2010 11:27am

    techgnome

    182 posts

    Don’t use the username as the fkey… use the ID… which is already being set in your script there.

    -tg

  • #650 / Dec 01, 2010 11:39am

    Todlerone

    63 posts

    Don’t use the username as the fkey… use the ID… which is already being set in your script there.

    -tg

    Thanks again techgnome.  I set the user_id to a foreign key.  However when I create a new user the field still is left blank.

    Could I just add it to the additional data array?

    $username  = substr(strtolower($this->input->post('first_name')), 0, 1).strtolower($this->input->post('last_name'));
    
    $additional_data = array('first_name' => $this->input->post('first_name'),
                                         'last_name'  => $this->input->post('last_name'),
                            'username'  => $username);
  • #651 / Dec 01, 2010 8:47pm

    techgnome

    182 posts

    Yes… you should… otherwise how will it know what to fill it in with? I see that you have username in both tables… that’s duplication of data and isn’t necessary. It should just be in the users table…

    For the fkey to work, you need to first insert into the user table, get the resulting ID, then insert into your meta table, passing the new user ID as the user_id field value.

    -tg

  • #652 / Dec 01, 2010 11:35pm

    Ben Edmunds

    812 posts

    Todlerone,

    To expand on/clarify what techgnome said. 

    You should remove the username column from the meta table as it already exists in the users table, then when creating the user with ion_auth->register() you will pass in the username and meta data and it will propagate the correct tables.  Also make sure you update your ion_auth config file with your meta columns.

  • #653 / Dec 02, 2010 11:22am

    Todlerone

    63 posts

    Todlerone,

    To expand on/clarify what techgnome said. 

    You should remove the username column from the meta table as it already exists in the users table, then when creating the user with ion_auth->register() you will pass in the username and meta data and it will propagate the correct tables.  Also make sure you update your ion_auth config file with your meta columns.

    TY very much Ben.  Your an asset to codeigniter and open source.  I have taken the username out of the meta table.  I’m slowly understanding the inner workings of Ion Auth and it is doing exactly what I want.  Can I ask you two more questions?

    1)  For my purposes I’m not allowing people to register themselfs, I’m doing it as admin only.  This is for a very select group of people.  I do want to be able to set there group names in the create form.  What all do I need to do to make this happen?  I suspect I can load the groups into an array and pass this to a select form input easily enough.  Just not completely sure what else is needed other then following errors until I get it.  I tried this and have come up against something I did that I can’t fix…which leads me to question 2.
    2) I’m now getting this error when I try to create a user.

    Column 'group_id' cannot be null
    
    INSERT INTO `users` (`username`, `password`, `email`, `group_id`, `ip_address`, `created_on`, `last_login`, `active`, `salt`) VALUES ('ticles', 'c7c5ddd126837ab3e71672a28603703f13fa34c8', '[email protected]', NULL, '142.21.240.74', 1291302985, 1291302985, 1, '2d16847247')

    Not sure where I screwed up.

    TY for your time.
    CHEERS

  • #654 / Dec 02, 2010 5:32pm

    2think

    125 posts

    Todlerone, totally agree with you on Ben being one of the immense assets to the Codeigniter community. There are quite a few people - for example, Phil Sturgeon, Jamie Rumbelow, Elliot Haughin, Collin Williams, and more - who make (made? LOL!) Codeigniter a much more pleasurable experience than it already is.

    I’ll try to offer my two cents worth and see if that helps any.

    Have you checked if you set the group_id to NOT NULL in your DB schema? You’re also passing in the group_id as NULL so why do that in the first place?

  • #655 / Dec 02, 2010 8:35pm

    Timothy_

    100 posts

    Hello,

    Has anyone else managed to connect ion_auth to a different database? As far as I can see there is no config option for it. The reason for this slightly unusual request is that I want to register a user in one application, but from then on the user will be logging in on another application.

    Thanks,

    Tim

  • #656 / Dec 02, 2010 10:10pm

    Ben Edmunds

    812 posts

    Todlerone,

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

  • #657 / Dec 02, 2010 10:11pm

    Ben Edmunds

    812 posts

    Timothy_,

    I’ve used it with MySQL and Postgres.  Never both at the same time though… you would have to replicate your data to both databases…  maybe you can expand on your use case a bit?

  • #658 / Dec 02, 2010 11:34pm

    Timothy_

    100 posts

    Timothy_,

    I’ve used it with MySQL and Postgres.  Never both at the same time though… you would have to replicate your data to both databases…  maybe you can expand on your use case a bit?

    Sorry, Reading back on my original question I wasn’t being clear.

    I have a main CI website that accesses a ‘default’ database set in the CI config/database file. It pulls things like menus, pages, posts etc from the default db.

    I also have a completely separate database that just deals with user data. Its for a ‘user account’ CI app that I am about to start developing. This separation of databases is primarily done for security. If my main website gets hacked that’s not good. If my users confidential details get exposed because of it that’s a nightmare.

    As you probably already know it is possible to connect to multiple DB’s in CI.

    What i was trying to do was have my main front end website basically setup a user in another CI installs DB. However reading back over this I think it would be easier just to pass the paramaters from my main website to the user account website and let the user account website do the registering, rather than have two instances of ION auth running in tandem on the same ‘user accounts’ DB.

    Sorry for confusing everyone, including myself.

    Thanks,

    Tim

  • #659 / Dec 03, 2010 4:26am

    Timothy_

    100 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

  • #660 / Dec 03, 2010 4:42am

    2think

    125 posts

    Timothy_,

    Have you tried switching to the other DB before calling any Ion_Auth functions? I can’t see why that wouldn’t work since Ion_Auth will use that particular DB.

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

ExpressionEngine News!

#eecms, #events, #releases