0

I am attempting to log in users with:

$login = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), TRUE);

However it fails when trying to set the autologin cookie, with ErrorException [ Notice ]: Trying to get property of non-object when it gets to:

// Token data
$data = array(
    'user_id'    => $user->pk(),
    'expires'    => time() + $this->_config['lifetime'],
    'user_agent' => sha1(Request::$user_agent),
);

// Create a new autologin token
$token = ORM::factory('User_Token')
            ->values($data)
            ->create();

// var_dump($token); // null

// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);

If I var_dump($token) it says it is null. I have checked the database and it appears to be added correctly. My config has driver => 'ORM'. Logging in works if the remember me flag is set to FALSE. Why is $token not an object? Is there something I have missed?

xylar
  • 7,433
  • 17
  • 55
  • 100
  • @ITroubs updated the question with `$data` – xylar Mar 21 '13 at 15:28
  • The notice is at what exact line? – ITroubs Mar 21 '13 at 15:28
  • @ITroubs at `Cookie::set('authautologin', $token->token, $this->_config['lifetime']);` It seems `$token->token` is failing. – xylar Mar 21 '13 at 15:30
  • well if var_dump($token); returns null then $token->token won't be possible.... so there was something wrong with your ORM mapping – ITroubs Mar 21 '13 at 15:32
  • try to split the creation of your token and to var_dump it after every function call. maybe that will clear where the problem comes from – ITroubs Mar 21 '13 at 15:35

1 Answers1

0

I caused the error by overriding the create() method in class ORM_Base extends Kohana_ORM which then called the parent::create() but directed the user_token to the wrong create(). Fixed by removing the create() I added.

xylar
  • 7,433
  • 17
  • 55
  • 100