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]
  • #316 / May 12, 2010 11:20am

    GlennJ

    65 posts

    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.

  • #317 / May 12, 2010 11:20am

    Phil Sturgeon

    2889 posts

    Awesome! 😉

  • #318 / May 12, 2010 11:32am

    joytopia

    76 posts

    Phil and Ben,

    now I have written it for register.

    config:

    /**
         * 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:

    /**
         * 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

  • #319 / May 12, 2010 1:11pm

    hovhannes

    2 posts

    Hello guys ! Thanks for this really awesome lib ! It is nothing less than tonnes of time and nerves economy 😊 !

    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

    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

    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 !

  • #320 / May 12, 2010 1:13pm

    Ben Edmunds

    812 posts

    hovhannes,

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

  • #321 / May 12, 2010 1:19pm

    hovhannes

    2 posts

    Thanks Ben 😊

  • #322 / May 12, 2010 5:53pm

    davidjlynch

    8 posts

    Hi Ben,

    I am new to codeigniter, great work, just one thing, I cannot seem to get the email_check to return error message ‘Email already in use’ or something similar using the below;

    $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email|callback_email_check');

    /

    **
         * Checks email
         *
         * @return bool
         * @author Mathew
         **/
        public function email_check($email = '')
        {
            if (empty($email))
            {
            return FALSE;
            }
            return $this->db->where('email', $email)
                ->where($this->ion_auth->_extra_where)
                ->count_all_results($this->tables['users']) > 0;
        }

    also tried using you callback function on page 25 of this post, any help would be greatly appreciated.

    Thanks in advance

  • #323 / May 12, 2010 5:59pm

    Ben Edmunds

    812 posts

    davidjlynch,

    Add the callback function I posted earlier to your controller and it should work.

    Let me know if you get any errors.

  • #324 / May 13, 2010 2:48am

    Timothy_

    100 posts

    Does anyone have a good solution to retrieving the users that are currently logged in?

    Thanks,

    Tim

  • #325 / May 13, 2010 5:19am

    joytopia

    76 posts

    Email functions: bug-fixes and new features

    Bug-fixes:

    forgotten_password and forgotten_password_complete:
    in case of success an error-message was set instead of set_message.

    Plain-text version of emails did not show the link.
    This is fixed by the email_with_markers feature.

    New features:

    email_with_markers:

    $config['email_templates']     = 'auth/email_with_markers/';

    now uses a set of email templates with markers ###subject###, ###message### and ###alt_message###

    So you have a comfortable control over functionality, look an feel of your emails.

    You can use the methods

    $this->ion_auth->get_message_from_template($template, $data)


    and

    $this->ion_auth->send_email($email, $subject, $message, $alt_message = '')

    everywhere in your application to easily send well designed admin-emails.

    Now supports mailtype

    simply set

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


    Send email and / or return a data-array

    /**
         * 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['send_email']     = 'email';

    So you can easily do so something with calculated data directly after the registration, i.e. update some fields in the database or show the new user his user_id or make your own confirmation-process.


    I tested as well as I could. It should be fully backward compatible.
    As I am not yet on GitHub, I post the files here.

    Thank you for your feedback!

    Best regards

    Bernd

  • #326 / May 13, 2010 1:22pm

    joytopia

    76 posts

    Does anyone have a good solution to retrieving the users that are currently logged in?

    Thanks,

    Tim

    What about showing the username from table ci_sessions WHERE last_activity > now() - 360

    Best regards
    Bernd

  • #327 / May 13, 2010 4:46pm

    Ben Edmunds

    812 posts

    Bernd,

    Those changes sound pretty good to me but I haven’t had a chance to go through the code yet (crazy week!).  Any chance you could do a github pull request anytime soon?  If not, I can probably get around to going through it sometime next week.


    Thanks!

  • #328 / May 13, 2010 9:15pm

    megabyte

    179 posts

    Library looks utterly amazing. I think both Ben and Phil rock, although I don’t know them, lol.

    Anyway my question is:

    How bug free is it now? would you recommend for or against using it on a live website.

  • #329 / May 13, 2010 10:30pm

    Ben Edmunds

    812 posts

    megabyte,

    I know us and I agree, we do rock.

    There are no known bugs at the moment and I am using the library on several production sites plus all of the sites that are using PyroCMS are using Ion Auth under the hood.

  • #330 / May 13, 2010 10:34pm

    megabyte

    179 posts

    What about the bug fixes joytopia mentioned?

    Are these actual bugs that needed to be fixed?

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

ExpressionEngine News!

#eecms, #events, #releases