php - Laravel 4: Stock Auth login won't persist across pages -


from tutorials, i'm supposed able auth user jump other page, , login persisted. however, not work.

custom compiled php lamp stack. app storage writable.

the difference tutorials i'm using email instead of username. http://laravelbook.com/laravel-user-authentication/ http://codehappy.daylerees.com/authentication

sessions work, able store var session , read out on different page.

models/user.php (stock)

use illuminate\auth\userinterface; use illuminate\auth\reminders\remindableinterface;  class user extends eloquent implements userinterface, remindableinterface {      /**      * database table used model.      *      * @var string      */     protected $table = 'users';      /**      * attributes excluded model's json form.      *      * @var array      */     protected $hidden = array('password');      /**      * unique identifier user.      *      * @return mixed      */     public function getauthidentifier()     {     echo $this->getkey();         return $this->getkey();     }      /**      * password user.      *      * @return string      */     public function getauthpassword()     {         return $this->password;     }      /**      * e-mail address password reminders sent.      *      * @return string      */     public function getreminderemail()     {         return $this->email;     }  } 

config/auth.php

return array(     'driver' => 'eloquent',     'model' => 'user',     'table' => 'users',      'reminder' => array(         'email' => 'emails.auth.reminder',         'table' => 'password_reminders',         'expire' => 60,     ), ); 

config/session.php

return array(     'driver' => 'native',     'lifetime' => 120,     'files' => storage_path().'/sessions',     'connection' => null,     'table' => 'sessions',     'lottery' => array(2, 100),     'cookie' => 'laravel_session',     'path' => '/',     'domain' => null, ); 

routes.php

route::get('/', array('as' => 'home', function(){     return view::make('home'); }));  route::get('login', array('as' => 'login', function () {     return view::make('login'); }))->before('guest');  route::post('login', function () {     $user = array(         'email' => input::get('email'),         'password' => input::get('password')     );      if (auth::attempt($user, true)) {     /*         return redirect::route('home')             ->with('flash_notice', 'you logged in.');       */     } else {         /*         // authentication failure! lets go login page         return redirect::route('login')             ->with('flash_error', 'your email/password combination incorrect.')             ->withinput();             */     }      // shows user logged in     echo (auth::check()) ? 'logged in' : 'not logged in'; });  // shows user not logged in route::get('test', function () {     echo (auth::check() == true) ? 'logged in' : 'not logged in'; }); 

table sql

create table if not exists `users` (   `userid` bigint(10) unsigned not null auto_increment,   `email` varchar(250) default null,   `password` varchar(124) default null,   `name` varchar(250) default null,   `created_at` timestamp not null default current_timestamp,   `updated_at` timestamp null default null on update current_timestamp,   primary key (`userid`),   unique key `email` (`email`) ) engine=innodb  default charset=utf8 auto_increment=3 ;  insert `users` (`userid`, `email`, `password`, `name`, `created_at`, `updated_at`) values (1, 'ben.test@smitty.com', '$2y$10$591gwvqksgxihkruh1s.wehnm1dr/xzavw46vuusbxef7jk0zze1g', 'ben dauphinee', '2013-08-03 23:25:01', '2013-08-07 01:32:46'), (2, 'jim@dandy.com', null, 'jim dandy', '2013-08-03 23:25:01', null); 

resulting auth::user() info

user object (     [table:protected] => users     [hidden:protected] => array         (             [0] => password         )      [connection:protected] =>      [primarykey:protected] => id     [perpage:protected] => 15     [incrementing] => 1     [timestamps] => 1     [attributes:protected] => array         (             [userid] => 1             [email] => bookworm51@hotmail.com             [password] => $2y$10$591gwvqksgxihkruh1s.wehnm1dr/xzavw46vuusbxef7jk0zze1g             [name] => ben dauphinee             [created_at] => 2013-08-03 20:25:01             [updated_at] => 2013-08-06 22:32:46         )      [original:protected] => array         (             [userid] => 1             [email] => bookworm51@hotmail.com             [password] => $2y$10$591gwvqksgxihkruh1s.wehnm1dr/xzavw46vuusbxef7jk0zze1g             [name] => ben dauphinee             [created_at] => 2013-08-03 20:25:01             [updated_at] => 2013-08-06 22:32:46         )      [relations:protected] => array         (         )      [visible:protected] => array         (         )      [fillable:protected] => array         (         )      [guarded:protected] => array         (             [0] => *         )      [touches:protected] => array         (         )      [with:protected] => array         (         )      [exists] => 1     [softdelete:protected] =>  ) 

the problem have used "userid" primary id - have not told laravel.

per laravel docs: "eloquent assume each table has primary key column named id"

either

change userid id in table (my personal recommendation - it'll make life easier if table has id)

or add user.php file:

protected $primarykey = "userid"; 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -