Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]Todlerone[/eluser]
[quote author="Todlerone" date="1291699661"]Hello everyone. Sorry for the simple questions. I've successfully implemented Ion Auth as a log in. Works great. Now I'm trying to add some functionality to my website. I have a model that stores personal information (limited). All I'm trying to do is add their username to the table (not through a form) for creating/editing the data. The form doesn't error but the $user['username'] comes up empty. Sorry I don't have the code (it's at work). What is the difference between passing variables with $data['username'] and $this->data['username']?

TY[/quote]

Ty Ben. I worked at this for sometime and eventually got it to work. I now understand what I had done wrong. I am however still stuck at the dropdown menu for the create user. I redid the user login form in code I was familiar with but still don't get anything listed.

Code:
function create_user(){
//other standard code from this controller here
if ($this->form_validation->run() == true && $this->ion_auth->register($username,$password,$email,$additional_data)) { //check to see if we are creating the user
                  //redirect them back to the admin page
                $this->session->set_flashdata('message', "User Created");
               redirect("admin/admin_main/get_users_array", 'refresh');
        }else{ //display the create user form
               //set the flash data error message if there is one
                $this->data['groups'] = $this->ion_auth_model->get_groups();
            
            $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
            
            $data['user'] = $this->ion_auth->get_user_array();
            $this->title="Create User";    
            $this->thisPage="Admin";
            $this->load->view('header', $data);
            $this->load->view('admin/admin_create_user', $this->data);
            $this->load->view('sidebars/sidebar_admin_main');
            $this->load->view('footer');
        }
    }// end create_user()


//the view form

<div class="post">
        <h1 class="title">Add user to JCC Database. </h1>
        &lt;?php echo validation_errors(); ?&gt;
        &lt;?php echo form_open('admin/admin_main/create_user'); ?&gt;
        <fieldset>
            <legend>Personal Information</legend>
            <label for="first_name">First Name:</label>
                &lt;input type="text" name="first_name" value="&lt;?php echo set_value('first_name'); ?&gt;"/&gt;

            <label for="last_name">Last Name:</label>
                &lt;input type="text" name="last_name" value="&lt;?php echo set_value('last_name'); ?&gt;" /&gt;

            <label for="group_id">Group Member:</label>
                <select name="group_id"><option value=''>Choose a group...</option>
                &lt;?php foreach ($groups as $grp){?&gt;
                &lt;?php echo "<option value='".$grp['id']."' >".$grp['description']."</option>"; ?&gt;
                &lt;?php } ?&gt;</select>
                    
            <label for="jcc_demo_Gender">Password:</label>
                &lt;input type="password" name="password" value="&lt;?php echo set_value('password'); ?&gt;" /&gt;

            <label for="jcc_demo_DOB">Confirm Password:</label>
                &lt;input type="password" name="password_confirm"  value="&lt;?php echo set_value('password_confirm'); ?&gt;" /&gt;
        </fieldset>
        <p>&lt;input type="submit" name="Submit" value="Create User" class="button" /&gt;&lt;/p>
        &lt;/form&gt;
</div>&lt;!-- end #post --&gt;


TY for your time

[eluser]Ben Edmunds[/eluser]
The first issue is that you are referencing the groups inside your foreach (grp) as an array when they are an object.

Whenever you have issue like this you need to troubleshoot it. Just start with a print_r or var_dump of what your having an issue with and drill down from there.

[eluser]ci_lover[/eluser]
Hello everybody, great thread.

I have a question, how do I get all logged in users ?

Is there a way to pass a user's id, to the function:

ion_auth->is_logged();

for example it becomes:

ion_auth->is_logged(user_id);


This would be helpful.

Thanks.

[eluser]Ben Edmunds[/eluser]
If you use DB sessions you should could query your sessions table.

[eluser]ci_lover[/eluser]
That's a new idea, I didn't think of that ..

I ended up making another DB table for online users.

Great work you done here Ben. Thanks a lot.

[eluser]Unknown[/eluser]
Hello everyone!

First of all, I want to thank you for your great library!
I'm using it for my current project and I'm very pleased with it...

But I have one question:
When a user changes his/her email address, is it possible that he needs to confirm the new address before it's inserted into the database?

Thank you :-)

mhamp

[eluser]xatrix[/eluser]
Once the user is logged in, here's how to redirect him to the page that required auth.

In Ion_Auth.php
Code:
public function logged_in()
    {
        $this->ci->session->set_flashdata('referrer', current_url());
        $identity = $this->ci->config->item('identity', 'ion_auth');

        return (bool) $this->ci->session->userdata($identity);
    }

In Auth.php

Code:
if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember))
            { //if the login is successful
                //redirect them from whence they came
                $this->session->set_flashdata('message', $this->ion_auth->messages());
                redirect($this->session->flashdata('referrer'));
            }
}

Basically it will only set flashdata when it has to check if the user is logged in, and redirect when he is.

Also in your Auth.php, loading a view counts as a server request. So before you load the login view, tell CI to keep the data:
Code:
$this->session->keep_flashdata('referrer');
$this->load->view('auth/login', $this->data);

* however, I'm not sure what happens if you call logged_in multiple times. There must be some way to check that flashdata has been set, so that the same key isn't overwritten (is that even possible?) and reduce code crap. Any ideas?

[eluser]rhussain[/eluser]
Hi Ben,

I've noticed that the session library is loaded a few times in Ion_Auth.
It's loaded in the library class constructor and in the model and in auth.php(which I assume is just example code on how to use Ion_Auth - am I right there?).

Is it necessary to do this in all three files?

Can I just have the session library loaded by Ion_auth.php and get rid of the call from auth.php and ion_auth_model.php? Or is one of the other files more suitable?

I know it's not that much trouble cos extra calls to the session class are ignored but I suppose I'm a bit picky about that sort of thing... :-)

I have tried it as described above and it seems to work but I am new to CI and Ion_Auth so I wondered if there would be any deeper impliactions.

Thanks for Ion_Auth by the way its been a great help!!!

[eluser]kikz4life[/eluser]
hi there Ben Edmunds,

first of all adv meri xmas. ^_^.

i have a slight problem. I'm read almost all the threads in your ionAuth before using your library. I've encountered a problem when i created a new user then tried to login, the page just keep refreshing. No output error just the page keeps refreshing. Tried in FF, chrome and IE.

Anyone else encountered this?

[eluser]chenda0331[/eluser]
Thank you for giving me this! That's what I need!




Theme © iAndrew 2016 - Forum software by © MyBB