php - Multiple User Types in Laravel 4 - Login Issues -
i doing project school , need more 1 user type : user, registrar , teacher.
i followed laravel documentation , got user working (login/register).
then tried adding user: registrar. got registration working , it's adding user in "registrar" table.
but when i'm trying log in using "users" table, not "registrar" one, , giving me controller method "not found" error.
model: registrar.php
<?php use illuminate\auth\userinterface; use illuminate\auth\reminders\remindableinterface; class registrar extends eloquent implements userinterface, remindableinterface { protected $table = 'registrar'; protected $hidden = array('password'); public function getauthidentifier() { return $this->getkey(); } public function getauthpassword() { return $this->password; } }
routes:
route::get('/', array('uses' => 'homecontroller@authenticateuser')); route::get('/student/member', array('uses' => 'userscontroller@getstudent')); route::get('logout', array('uses' => 'userscontroller@dologout')); route::controller('users', 'userscontroller'); route::controller('password', 'reminderscontroller'); route::controller('registrar', 'registrarcontroller'); route::get('/registrar/member', array('uses' => 'registrarcontroller@getregistrar'));
registrarcontroller, sign-in method:
public function postsignin() { if (auth::attempt(array('email'=>input::get('login_input')) { return redirect::to('registrar/member')->with('status', 'you logged in!'); } else { return redirect::to('registrar/login') ->with('error', 'your username/password combination incorrect') ->withinput(); } }
other functions inside:
class registrarcontroller extends basecontroller { public function __construct() { $this->beforefilter('csrf', array('on'=>'post')); $this->beforefilter('auth', array('only'=>array('getregistrar'))); } public function getregister() { return view::make('registrar.register'); } public function getregistrar() { return view::make('registrar.member'); }
login.blade.php
{{ form::open(array('url'=>'registrar/signin', 'class'=>'form-signin' , 'id'=>'login-form')) }} . . . . -- form close--
i'm wondering if line not problem in signin function:
if (auth::attempt(array('email'=>input::get('login_input')) { return redirect::to('registrar/member')->with('status', 'you logged in!')
as i'm not sure how system checks database table use, or default on "users".
you can swap model during runtime:
$provider = new \illuminate\auth\eloquentuserprovider(app('hash'), 'registrar'); auth::setprovider($provider);
Comments
Post a Comment