I am new to laravel and am trying to implement a login feature with sentry where by i have two groups in the database,the 'admin' group and the 'user' where by each group will be redirected to their respected views,but this gives me the following error
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) Call to a member function inGroup() on a non-object
Open: C:\wamp\www\library\app\controllers\UserController.php
The area points to this area of the code
{
echo 'User is suspended.';
}
catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
{
echo 'User is banned.';
}
$user = Sentry::getUser();
$admin = Sentry::findGroupByName('admin');
$users = Sentry::findGroupByName('user');
if ($user->inGroup($admin)) return Redirect::intended('admin');
elseif ($user->inGroup($users)) return Redirect::intended('user');
Here is my complete code for the login process
public function postLogin(){
try
{
// Login credentials
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
// Authenticate the user
Sentry::authenticate($credentials, false);
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
{
echo 'Login field is required.';
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
{
echo 'Password field is required.';
}
catch (Cartalyst\Sentry\Users\WrongPasswordException $e)
{
echo 'Wrong password, try again.';
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
echo 'User was not found.';
}
catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
{
echo 'User is not activated.';
}
catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
{
echo 'User is suspended.';
}
catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
{
echo 'User is banned.';
}
$user = Sentry::getUser();
$admin = Sentry::findGroupByName('admin');
$users = Sentry::findGroupByName('user');
if ($user->inGroup($admin)) return Redirect::intended('admin');
elseif ($user->inGroup($users)) return Redirect::intended('user');
}