multiuser login by their role #559
-
I want to ask about how to do so that after the login authentication process is successful it will redirect to a different view according to users roles? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Ok. In that case the quick way to do it is modifying AuthController's attemptLogin() method. public function attemptLogin()
{
// default code goes here ...
// Is the user being forced to reset their password?
if ($this->auth->user()->force_pass_reset === true) {
return redirect()->to(route_to('reset-password') . '?token=' . $this->auth->user()->reset_hash)->withCookies();
}
// add logic to manage different views
$authorization = service('authorization');
if ($authorization->inGroup('admin', $this->auth->id())) {
$whereToGo = route_to('admin_dashboard');
} elseif ($authorization->inGroup('reguler_users', $this->auth->id())) {
$whereToGo = route_to('user_dashbord');
} else {
$whereToGo = route_to('default_home');
}
$redirectURL = session('redirect_url') ?? $whereToGo;;
unset($_SESSION['redirect_url']);
// end of logic to manage different views code
return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
} The best way to modify AuthController is to extend it to your app/controllers folder. And don't forget to change login routes to reflect changes. |
Beta Was this translation helpful? Give feedback.
-
ive changed my code as you will, but still cant redirect to different views. here is my code public function attemptLogin()
|
Beta Was this translation helpful? Give feedback.
Ok. In that case the quick way to do it is modifying AuthController's attemptLogin() method.
Example code: