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]
  • #946 / May 27, 2011 5:22pm

    Ben Edmunds

    812 posts

    malcomhfc,

    Awesome, that does usually help, haha. 

    v2 is still alpha so no docs yet.  Once I feel it has been tested enough and has most all of the features I want to add I’ll write up some new docs.

  • #947 / May 27, 2011 8:05pm

    malcomhfc

    27 posts

    $user = $this->ion_auth->user()->row();

    does this work for the logged in user running the function? What im doing is

    'comment' => $this->comment_m->getWebsite((array('doUser' => $user->id))));

    what its supposed to do is get all the records with field id matching the user id.

    What actually seems to happen is that it defaults to user 1. The function seems to work but i think im using wrong ion_auth code since it seems to think id 1.

    Was just wondering if there was another bit of code to use? If not only one way to learn to debug, right? :D

    —think its best for me to download version 1. 😊

    thanks. 😊

  • #948 / May 28, 2011 2:04pm

    Ben Edmunds

    812 posts

    Sorry for the confusion, that will just return the first user, to pull the currently logged in user do this:

    $user = $this->ion_auth->current()->user()->row();


    If you want to pull a different user by id you can do:

    $user = $this->ion_auth->user($user_id_to_query)->row();
  • #949 / May 29, 2011 7:51am

    malcomhfc

    27 posts

    works perfect thanks again 😊

  • #950 / May 29, 2011 7:16pm

    jark

    3 posts

    I’m having some trouble just getting the default reset password link to work. I configured ion_auth to use username as the identity, but the problem persists even if I change the identity to email.

    If I surf to auth/forgot_password and enter in a valid identity - an identity I’ve used to successfully login with - the following errors are spit out:

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Trying to get property of non-object
    
    Filename: libraries/Ion_auth.php
    
    Line Number: 195
    
    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Trying to get property of non-object
    
    Filename: libraries/Ion_auth.php
    
    Line Number: 196
    
    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Trying to get property of non-object
    
    Filename: libraries/Ion_auth.php
    
    Line Number: 205

    It does not matter the usage/configuration combo for identity. If configured for username, if I enter either username or password (even though it explicitly asks for a password) it errors out. The same happens when configured for email.

    I’ve not made any changes to the library file, but here are the applicable lines:

    195:                'identity'        => $user->{$this->ci->config->item('identity', 'ion_auth')},
    196:                'forgotten_password_code' => $user->forgotten_password_code
    197:            );
    198:
    199:            $message = $this->ci->load->view($this->ci->config->item('email_templates', 'ion_auth').$this->ci->config->item('email_forgot_password', 'ion_auth'), $data, true);
    200:            $this->ci->email->clear();
    201:            $config['mailtype'] = $this->ci->config->item('email_type', 'ion_auth');
    202:            $this->ci->email->initialize($config);
    203:            $this->ci->email->set_newline("\r\n");
    204:            $this->ci->email->from($this->ci->config->item('admin_email', 'ion_auth'), $this->ci->config->item('site_title', 'ion_auth'));
    205:            $this->ci->email->to($user->email);

    Any ideas what I either might be doing wrong or could do to fix? Thanks in advance!

  • #951 / May 31, 2011 2:59pm

    JonoB

    133 posts

    in the example controller, there is a function change_password.

    If the action is successful, then some flashdata is set, and the logout function is called.

    if ($change)
    { //if the password was successfully changed
        $this->session->set_flashdata('message', $this->ion_auth->messages());
        $this->logout();
    }
    function logout()
    {
        $this->data['title'] = "Logout";
    
        //log the user out
        $logout = $this->ion_auth->logout();
    
        //redirect them back to the page they came from
        redirect('auth', 'refresh');
    }

    $this->ion_auth->logout(), amongst other things calls

    $this->ci->session->sess_destroy();

    This means, that once the redirect in the auth/logout function happens, the flashdata will be lost.

    Is there any point in setting flash data in auth/change_password?

  • #952 / May 31, 2011 3:02pm

    roark

    2 posts

    Hi Ben,

    Great ‘plugin’ thanks for the great work!

    Regarding the flashdata/messaging/errors implementation, what do you think about setting the message type i.e.

    $this->data['message'] = array('type'=>'error','details'=>(validation_errors()) ? validation_errors() : $this->session->flashdata('message'));

    And…

    $this->session->set_flashdata('message', array('type'=>'success','details'=>$this->ion_auth->messages()));

    This will allow us to style the front-end depening on the message type…

    <?php if (!empty($message['details'])): ?>
        <div class="message <?=$message['type']?>">
            <?php if(is_array($message['details'])):?>
            <ul>
                <?php foreach($message['details'] AS $error): ?>
                <li><?=$error?></li>
                <?php endforeach;?>
            </ul>
            <?php else: ?>
            <?=$message['details']?>
            <?php endif; ?>
        </div>
        <?php endif;?>

    It may not be the ideal way to handle this, but I’ve implemented it successfully in one of my projects.

    Thanks again!

  • #953 / May 31, 2011 3:13pm

    malcomhfc

    27 posts

    Nice idea roark 😊

    May come in handy for some people, me included. 😊

  • #954 / Jun 05, 2011 11:47am

    DephNet[Paul]

    11 posts

    Hi Guys,

    After spending a few days trying to write my own authentication library, I have decided that I would rather use a library that has constant updates to it and Ion Auth looks like it will fit my needs.

    I do however have a few questions before I commit to using Ion Auth so here goes, Sorry if these have been asked, and answered, elsewhere I spent a few hours searching the forums and could not find any answers.

    1) Am I able to set certain pages to be accessible to everyone, and certain pages to be “members only”, or does this put the entire site behind a login box?
    2) Am I able to style the pages myself? I assume I can by simply editing the views.
    3) How extensible is this? For example, if I wanted to interface with WHMCS, to auto generate login details, am I able to do that?
    4) Is a “git pull” the only way of keeping upto date with Ion Auth, or does Ben release “stable” versions of Ion Auth regularly?

    Many thanks for your help
    —Paul

  • #955 / Jun 05, 2011 12:54pm

    JonoB

    133 posts

    Hi Guys,

    After spending a few days trying to write my own authentication library, I have decided that I would rather use a library that has constant updates to it and Ion Auth looks like it will fit my needs.

    I do however have a few questions before I commit to using Ion Auth so here goes, Sorry if these have been asked, and answered, elsewhere I spent a few hours searching the forums and could not find any answers.

    1) Am I able to set certain pages to be accessible to everyone, and certain pages to be “members only”, or does this put the entire site behind a login box?
    2) Am I able to style the pages myself? I assume I can by simply editing the views.
    3) How extensible is this? For example, if I wanted to interface with WHMCS, to auto generate login details, am I able to do that?
    4) Is a “git pull” the only way of keeping upto date with Ion Auth, or does Ben release “stable” versions of Ion Auth regularly?

    Many thanks for your help
    —Paul

    1. Sure. Set up a MY_Controller and use something like $this->ion_auth->logged_in()
    or $this->ion_auth->is_group(‘admin’)). See http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY

    2. Sure. Apply your own css as you see fit

    3. No problem…limits are only as far as your programming skills will take you. You may of course have to modify the lib

    4. As far as what I have seen, generally whats released onto Git is stable. I will leave Ben to answer this one though…

  • #956 / Jun 05, 2011 12:58pm

    DephNet[Paul]

    11 posts

    Hi Jono,

    Thanks for your prompt response, with regards to question 2 again. Am I correct in thinking I can change the HTML markup as well as the CSS for the pages?

    I will probably download Ion Auth later today and have a play with it before I commit to using it.

    —Paul

  • #957 / Jun 05, 2011 1:06pm

    JonoB

    133 posts

    Am I correct in thinking I can change the HTML markup as well as the CSS for the pages?

    Sure you can. Its the first thing I changed when I downloaded ion-auth 😊

  • #958 / Jun 06, 2011 12:32am

    Clone

    5 posts

    Just an FYI.  $this->ion_auth->change_password() is not documented here. http://benedmunds.com/ion_auth/

  • #959 / Jun 06, 2011 4:11am

    JonoB

    133 posts

    Just an FYI.  $this->ion_auth->change_password() is not documented here. http://benedmunds.com/ion_auth/

    It is, however, in the sample controller that comes with the package:
    https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/master/controllers/auth.php

    //change password
    function change_password()
    {
      ...
      $change = $this->ion_auth->change_password($identity, $this->input->post('old'), $this->input->post('new'));
      ...
    }
  • #960 / Jun 06, 2011 10:25am

    DephNet[Paul]

    11 posts

    Right,

    So I have downloaded Ion Auth and had a quick play with it last night and it is just what I want, although I have a little problem error messages.

    Starting with the forgot_password() function in the Auth controller I have slowly started to change the error checking logic. I have so far come up with:

    function forgot_password() {
                $this->data["title"] = "Recover Password";
    
                $this->data["form"]    = array("id" => "content", "name" => "content");
                $this->data["email"]   = array("id" => "email"  , "name" => "email"  );
                
                if(isset($_POST["submit"])) {
                    if(empty($_POST["email"])) {
                        $this->data["message"] = array("type" => "error",   "body" => "Email address not detected, please check and try again");
                    } else {
                        if(!preg_match("/@/i", $_POST["email"])) {
                            $this->data["message"] = array("type" => "error",   "body" => "Invalid email address detected, please check and try again");
                        } else {
                            if(!checkdnsrr(substr(strstr($_POST["email"], "@"), 1),'MX')) {
                                $this->data["message"] = array("type" => "error",   "body" => "Invalid email domain detected, please check and try again");
                            } else {
                                $query = "SELECT * FROM users WHERE email = ?";
                                $query = $this->db->query($query, $_POST["email"]);
    
                                if ($query->num_rows() != 1) {
                                    $this->data["message"] = array("type" => "error",   "body" => "Email address not found, please check and try again");
                                } else {
                                    $this->data["message"] = array("type" => "success", "body" => "This is a success message");
                                }
                            }
                        }
                    }
                }
    
                $this->load->view("auth/forgot_password", $this->data);
            }

    I have noticed that a default Ion Auth install uses $this->ion_auth->errors() which reads the language file for displaying the error in the correct language. How can I make use of $this->ion_auth->errors() within my script to call the correct error message from the language file.

    Sorry if this is a noobish question, this is my first time using a pre written library for CI.

    —Paul

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

ExpressionEngine News!

#eecms, #events, #releases