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]
  • #286 / May 06, 2010 7:34pm

    tobefound

    21 posts

    Sorry for double posting here. I’m hooking your Ion Auth into my existing ajax code and I happened to read an article on Phil’s RESTful CI framework (http://philsturgeon.co.uk/news/2009/06/REST-implementation-for-CodeIgniter).

    Would be fantastic to see how that framework together with Ion Auth performs, maybe this already is a work in progress? The match would be perfect.

    /T

  • #287 / May 06, 2010 8:02pm

    Timothy_

    100 posts

    Ok so I did a bit of debugging and found:

    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 `0` = ‘[email protected]’’ at line 2

    SELECT COUNT(*) AS `numrows` WHERE `0` = ‘[email protected]

     

    is happening during

    if (empty($identity) || empty($password) || !$this->identity_check($identity))
            {
                return FALSE;
            }

    which is referring to

    protected function identity_check($identity = '')
        {
            if (empty($identity))
            {
                return FALSE;
            }
    
            return $this->db
                ->where($this->identity_column, $identity)
                ->count_all_results($this->tables['users']) > 0;
        }

    I have also found that

    $this->identity_column

    is returning 0, which means

    $this->identity_column = $this->config->item('identity', 'ion_auth');

    is screwed…

    Why?

    Well because Redux Auth 2 required its ‘config’ file to be autoloaded I had simply changed it to auto load Ion Auth, which seems to not like being autoloaded from the autoload file.

    As soon as I removed that autoload I was able to login.

    Thanks,

    Tim

  • #288 / May 06, 2010 9:00pm

    Ben Edmunds

    812 posts

    Tim,

    Thanks for the debug man, hopefully that’ll help someone in the future. 

    The only thing I can think of without looking into the loader class is this:

    1.  The config is autoloaded into the config array
    2.  Ion Auth tries to load the config file into the config array as config[‘ion_auth’] but the loader doesn’t load it since it is already loaded.
    3.  The identity column is being referenced as config[‘ion_auth’] because of the second parameter but it can’t find it.


    That’s my best guess without checking into it more…

  • #289 / May 06, 2010 9:04pm

    Ben Edmunds

    812 posts

    tobefound,

    I would assume that EllisLab would write their own from scratch as that seems to be their style but of course I would have no issue with them adopting Ion Auth.

    In regards to Ion Auth with ajax and rest, I’m actually working on a project right now that uses Ion Auth in conjunction with ajax and rest for authentication but I won’t be able to release any of the source code.  Maybe I’ll make some nice examples in a couple months when I have time…

  • #290 / May 07, 2010 6:52am

    tobefound

    21 posts

    @ben:

    Time (or the lack of) is what kills us… Anyway, sounds cool. I’m well on my way adopting the RESTful thinking with your Ion lib and I think it will fly just fine.

    Cheers!

  • #291 / May 10, 2010 2:09pm

    joytopia

    76 posts

    Ben,

    I just began to implement the activation email.
    As I do not use html emails, I would propose to set the mailtype in the config:

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

    and change the 3 lines in the library:

    $config['mailtype'] = $this->ci->config->item('mailtype', 'ion_auth');

    Best regards
    Bernd

  • #292 / May 10, 2010 4:49pm

    farocco

    22 posts

    Ben,

    Any thing I have to do to host this on Godaddy?
    I am getting an email error when trying to use the forgot_password.

    Thanks

    Frank

    A PHP Error was encountered

    Severity: Warning

    Message: mail() [function.mail]: Bad parameters to mail() function, mail not sent.

    Filename: libraries/Email.php

    Line Number: 1519

    A PHP Error was encountered

    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at /home/content/n/t/w/ntwfrankfort/html/ci/system/libraries/Exceptions.php:166)

    Filename: libraries/Session.php

    Line Number: 662

    A PHP Error was encountered

    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at /home/content/n/t/w/ntwfrankfort/html/ci/system/libraries/Exceptions.php:166)

    Filename: helpers/url_helper.php

    Line Number: 539

    Hi Ben,

    I just tried a simple php cript to send email using the mail protocol and did not get any errors. Any idea why it is not working in ion-auth.

    Thanks

    Frank

  • #293 / May 10, 2010 9:02pm

    internut

    127 posts

    I’m glad I found Ion.  Just started to look at it and how I can benefit from it.

    Any useful tips on having a registered set of users but basically different groups will be part of the end solution.  Though different groups would have different custom meta fields.

    Wondering if I should just have all fields in the “meta”  table and based on the “group” they belong to output those fields to the user and check required fields (on save) based on the group.

    An admin would really not need to use any of those meta fields of course as its just an admin account.

    Any thoughts on the above much appreciated.  Just trying to wrap my head around the programming as I wire-frame it out.

  • #294 / May 11, 2010 2:38am

    joytopia

    76 posts

    Ben,

    the concept of email-templates seems very useful to customize the appearance of activation emails etc.

    However,at this time the subject is still hard coded. I would propose to put subject and message into the same view and separate them with ###markers###.

    Here my activate.tpl.php (in my case for text emails)

    ###subject###

    <?php echo $this->config->item(‘site_title’, ‘ion_auth’) . ’ - Test: Account Activation’ ?>

    ###message###

    Activate account for <?php echo $identity;?>


    Test: Please click this link to Activate Your Account:
    <?php echo base_url().‘auth/activate/’. $id .’/’. $activation;?>

    and here some changes in function register of the library:

    $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));
    
    
                $this->ci->email->clear();
                $config['mailtype'] = ($this->ci->config->item('mailtype', 'ion_auth')) ? $this->ci->config->item('mailtype', 'ion_auth') : 'html'; // gradido: mailtype from config
                $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);
                
                if($subject) $this->ci->email->subject($subject);
                else $this->ci->email->subject($this->ci->config->item('site_title', 'ion_auth') . ' - Account Activation');
                
                $this->ci->email->message($message);

    I tested it with the register / activate emails. The code is backward compatible. The other email-functions should be similar.

    Best regards
    Bernd

  • #295 / May 11, 2010 6:43am

    crashfellow

    3 posts

    Just implemented this and have been able to get it up and running nicely 😊 just have a couple of questions 😊

    1) How can i change the login to be username instead of email? without breaking the forgottenpassword.

    2) I would like my application to load up the login page straight away when you visit the site (unless your login is still in session) and once logging in your site continues.

    Also on a per page / controller basis, what would i do to check to make sure you are currently logged in?

    Keeping in mind that the admin person should go to one area (ie: /admin) and a non admin would just go to a page (ie: list/display)

    Thanks for this system btw! currently writing a project and using this as the basis for the login and user system 😊

  • #296 / May 11, 2010 7:31am

    joytopia

    76 posts

    crashfellow,

    1. you can set the the identity-column in the config file:

    /**
    * A database column which is used to
    * login with.
    **/
    $config['identity']            = 'username';

    After this you will have to make some changes in the controller and the view, so that the correct field is shown and validated.

    2. The function logged_in() returns true if the user is logged in
    The function is_admin() returns true if the user is an admin.

    3. If you want to show the login form on every page, you can take the example code from the auth-controller, change it to your needs and put into a method which returns the form as a content string, which you can put anywhere you want to.

    Best regards
    Bernd

  • #297 / May 11, 2010 10:13am

    crashfellow

    3 posts

    Thank you for the reply 😊

    I’ve set up the following function for login:

    // check for login
    if (!$this->ion_auth->logged_in()) {
    redirect(base_url() . 'auth/login.html', 'refresh');
    }

    Which is currently working perfectly. However shouldn’t there be a way in a constructor to do so? perhaps in the top of each controllers constructor?

  • #298 / May 11, 2010 10:37am

    Phil Sturgeon

    2889 posts

    Bad!

    Thank you for the reply 😊

    I’ve set up the following function for login:

    // check for login
    if (!$this->ion_auth->logged_in()) {
    redirect(base_url() . 'auth/login.html', 'refresh');
    }

    Which is currently working perfectly. However shouldn’t there be a way in a constructor to do so? perhaps in the top of each controllers constructor?

    Better

    if (!$this->ion_auth->logged_in()) {
      redirect('auth/login', 'refresh');
    }

    Best

    $this->ion_auth->logged_in() or redirect('auth/login');

    Anyhow, the controllers in Ion Auth are the only as an example. You should be putting this in your Controller constructor or even better in your named Base Controller. That is all way out of scope of this simple example controller.

  • #299 / May 11, 2010 7:34pm

    crashfellow

    3 posts

    Thanks for your reply, but you didn’t really have to yell bad! at it did you 😛

    The reason for base url() is because if my code is currently at:

    localhost/site/controller/

    then if i do a redirect, i will then get:

    localhost/site/auth/login/

    which doesn’t work. This base class idea however is perfect, i think that’ll do exactly what i want.

    So would i shift the functionality of Ion Auth into the base controller?

  • #300 / May 12, 2010 2:00am

    Ben Edmunds

    812 posts

    Hey crashfellow,

    The redirect function will insert your base_url.

    You wouldn’t shift the functionality but you would do the checking there.  So in MY_controller you would check if the user is logged in and if not redirect to auth/login.

    And please don’t do this, this really sucks:

    $this->ion_auth->logged_in() or redirect('auth/login');

    Phil is going through a very hard time right now as he struggles with his sexual orientation and his code is suffering greatly for it.

    Do this instead:

    if (!$this->ion_auth->logged_in())
        redirect('auth/login');

    or even this if you’re desperate for white space:

    if (!$this->ion_auth->logged_in()) redirect('auth/login');
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases