CodeIgniter Forums
Ion Auth - Lightweight Auth System based on Redux Auth 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Ion Auth - Lightweight Auth System based on Redux Auth 2 (/showthread.php?tid=27435)



Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]Ben Edmunds[/eluser]
internut,

I'm not exactly sure what your asking...

If you are asking how to insert a user without any meta data then just pass an empty array as the additional data to the register method.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]GlennJ[/eluser]
[quote author="Ben Edmunds" date="1273688559"]Glennj,

Why not just use groups?[/quote]

I could do I suppose, just felt I would like a distinct seperation in the database and I'd want to use different email templates, meta data etc for the different groups.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]Ben Edmunds[/eluser]
GlennJ,

I really don't recommend separating the users. It might sound like a good idea now but it makes things horrible to work with later on.

I would recommend having different groups and then if you need additional customer data that won't work in the meta table you can create another table with a relationship to the user; you shouldn't need to do that though.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]GlennJ[/eluser]
Yeah, I do understand where you're coming from and I understand the pros and cons.

I think for a blog or CMS that would be fine, but security is paramount on this site and the users have absolutely nothing in common.

I'll have a think... ;-)

Cheers.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]Phil Sturgeon[/eluser]
[quote author="GlennJ" date="1273690653"]Yeah, I do understand where you're coming from and I understand the pros and cons.

I think for a blog or CMS that would be fine, but security is paramount on this site and the users have absolutely nothing in common.

I'll have a think... ;-)

Cheers.[/quote]

As far as authentication goes, everybody is a user right? Everybody needs a login, everybody has an email.

I have done all sorts of crazy things with Ion Auth that a user auth system wouldn't handle, the best example being a multi-site, reseller account with public users, reseller customers (running the sites that the public users look at), resellers (managing the reseller custom accounts) and super-admins who manage the resellers.

These are all run off one "user" database and have groups.

Security here is clearly paramount, but as long as you code right there is no problems at all.

You could do this purely with groups, or you could have users, customers and admins as separate tables.

"users" would handle the basic data, then customers and admins would both have a user_id field and contain extra info.

Then just add a "type" enum('customer', 'admin') field to your database, and use the built-in hidden awesomeness that is:

Code:
$this->ion_auth->extra_where('type', 'customer');
$this->ion_auth->extra_set('type', 'customer');

This means any new users will be customers, and it will only look for customers on login.

Put that in global code like named base controllers and you are all set.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]GlennJ[/eluser]
Ahha!

The "built-in hidden awesomeness" does indeed sound awesome!

Still quite new to this library so thanks for taking the time to point these functions out to me.

The "awesomeness" sounds like a good enough solution to counter my security worries! :-)

Cheers.


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]Phil Sturgeon[/eluser]
Awesome! ;-)


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]joytopia[/eluser]
Phil and Ben,

now I have written it for register.

config:
Code:
/**
     * Send email
     * Ion_auth either sends an email directly (and returns bool)
     * or it returns a data-array, so that you can write your own email methods
     * or both
     * set to 'email', 'data' or 'both'
     * Default : 'email'
     */
    $config[']     = 'email';

  
    /**
     * Mail type, "text" or "html"
     */
    $config['mailtype']     = "text";

library:
Code:
/**
     * register
     *
     * @return array or bool
     * @author Mathew
     **/
    public function register($username, $password, $email, $additional_data, $group_name = false) //need to test email activation
    {


        ...


            $message = $this->ci->load->view($this->ci->config->item('email_templates', 'ion_auth').$this->ci->config->item('email_activate', 'ion_auth'), $data, true);
            
            $subject = substr($message, 0, strpos($message, '###message###'));
            $message = trim(str_replace($subject.'###message###', '', $message));
            $subject = trim(str_replace('###subject###','',$subject));
            if(!$subject) $subject = $this->ci->config->item('site_title', 'ion_auth') . ' - Account Activation';
            
            $data['subject'] = $subject;
            $data['message'] = $message;
                        
            if('data' == $this->ci->config->item(', 'ion_auth'))
                return $data;
            elseif('both' == $this->ci->config->item(', 'ion_auth'))            
                return ($this->send_email($email, $subject, $message)) ? $data : FALSE;
            else
                return ($this->send_email($email, $subject, $message)) ? TRUE : FALSE;
        }
    }
    
    
    
    /**
     * send email
     *
     * @return bool
     * @author Mathew
     **/
    public function send_email($email, $subject, $message)
    {        
        $this->ci->email->clear();
        $config['mailtype'] = ($this->ci->config->item('mailtype', 'ion_auth')) ? $this->ci->config->item('mailtype', 'ion_auth') : 'html';
        $this->ci->email->initialize($config);
        $this->ci->email->set_newline("\r\n");
        $this->ci->email->from($this->ci->config->item('admin_email', 'ion_auth'), $this->ci->config->item('site_title', 'ion_auth'));
        $this->ci->email->to($email);            
        $this->ci->email->subject($subject);            
        $this->ci->email->message($message);
        
        if ($this->ci->email->send() == TRUE)
        {
            $this->set_message('activation_email_successful');
            return TRUE;
        }
        else
        {
            $this->set_error('activation_email_unsuccessful');
            return FALSE;
        }
    }

It should be backward compatible without any changes in config.

Please let me know, whether I am on the right way.
Then I will make the changes also for forgotten password

Best regards
Bernd


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]hovhannes[/eluser]
Hello guys ! Thanks for this really awesome lib ! It is nothing less than tonnes of time and nerves economy Smile !

I am using modular separation with ion auth, and i did some changes to ion auth to work with modular separation.
Firstly i moved views files from views/auth directory to views.

Second i changed paths for loading models and libs in constructor of Ion_auth.php library file.

Now it looks like this

Code:
public function __construct()
    {
        $this->ci =& get_instance();
        $this->ci->load->config('auth/ion_auth', TRUE);
        $this->ci->load->library('email');
        $this->ci->load->library('session');
        $this->ci->lang->load('auth/ion_auth');
        $this->ci->load->model('auth/ion_auth_model');
        $this->ci->load->helper('cookie');

        //rest of the code
    }


Before my changes it was

Code:
public function __construct()
    {
        $this->ci =& get_instance();
        $this->ci->load->config('ion_auth', TRUE);
        $this->ci->load->library('email');
        $this->ci->load->library('session');
        $this->ci->lang->load('ion_auth');
        $this->ci->load->model('ion_auth_model');
        $this->ci->load->helper('cookie');

        //rest of the code
    }


Am I on the right way, or there is another way to use ion_auth with modular separation?

Thanks once again, Hov !


Ion Auth - Lightweight Auth System based on Redux Auth 2 - El Forum - 05-12-2010

[eluser]Ben Edmunds[/eluser]
hovhannes,

Glad it's helping you out. You're doing it the right way, that's how we do it in PyroCMS.