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

[eluser]malcomhfc[/eluser]
Ben when i echo $user i just get Array.

Im trying to insert the logged in user into the database table website(for comment system and learning purposes. I know it looks bad but im learning Smile)

Code:
if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $this->ion_auth->user()->result_array())))

Also tried to do it with out result_array

Code:
if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $this->ion_auth->user()->result())))

Any idea why the output is Array?

Code:
Error Number: 1054

Unknown column 'Array' in 'field list'

INSERT INTO `comments` (`doWebsite`, `doUser`) VALUES ('http://test.com', Array)

[eluser]Ben Edmunds[/eluser]
malcomhfc,

You probably only want to insert the user id. You can't stick an array in a DB field without serializing it, and that is bad practice for most situations.

Are you using Ion Auth v1 or v2?

v1 code is:
Code:
$user = $this->ion_auth->get_user();
if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))

v2 code is:
Code:
$user = $this->ion_auth->user()->result();
if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))

[eluser]malcomhfc[/eluser]
I just get the error

Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/account.php

Line Number: 32

the line is the one above ^. Im using version 2 for ion_auth. I take it the problem could just be my code in the model?

its just a simple function

Code:
function addDomain($options = array())
     {
         //required values
        if(!$this->_required(
            array('doWebsite', 'doUser'),$options)
        )return false;
        
        $this->db->insert('comments', $options);
        
        return $this->db->insert_id();
     }

Thanks a lot for your assistance Ben Smile

[eluser]Ben Edmunds[/eluser]
malcomhfc,


It could be because I gave you the wrong v2 code Wink it should be:
Code:
$user = $this->ion_auth->user()->row();
if($this->comment_m->addWebsite(array('doWebsite' => $this->input->post('doWebsite'), 'doUser' => $user->id)))

If that doesn't work, please answer these questions:

1. What's on line 32?

2. Are you sure your logged in?

3. What do you get if you var_dump($user)?

4. What do you get if you do:
Code:
var_dump($this->ion_auth->current()->user()->row());

[eluser]malcomhfc[/eluser]
Ah that worked thank you. Using the correct code helps most times Big Grin. Thanks so much!

Was that in the docs and i have missed it or is there new docs to be released once ion_auth 2 is finished? dont know php well enough to look through your library and see the correct usage Smile I have a habit of using everything bleeding edge.

Thanks again Ben.

[eluser]Ben Edmunds[/eluser]
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.

[eluser]malcomhfc[/eluser]
$user = $this->ion_auth->user()->row();

does this work for the logged in user running the function? What im doing is
Code:
'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? Big Grin

--think its best for me to download version 1. Smile

thanks. Smile

[eluser]Ben Edmunds[/eluser]
Sorry for the confusion, that will just return the first user, to pull the currently logged in user do this:
Code:
$user = $this->ion_auth->current()->user()->row();


If you want to pull a different user by id you can do:
Code:
$user = $this->ion_auth->user($user_id_to_query)->row();

[eluser]malcomhfc[/eluser]
works perfect thanks again Smile

[eluser]jark[/eluser]
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:

Code:
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:

Code:
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!




Theme © iAndrew 2016 - Forum software by © MyBB