Whenever i logged in i have redirected all to 'welcome.php'. But if i want user to redirect on user page and admin to redirect on admin page. what can I do. ? i have defined types of users already just want to redirect them separately. for eg. user and admin option is there when a new user gets register/signup.
in UsersController.php
public function login()
{
$this->viewBuilder()->setLayout('login');
$this->request->allowMethod(['get', 'post']);
$result = $this->Authentication->getResult();
if ($result->isValid()) {
$redirect = $this->request->getQuery('redirect', [
'controller' => 'Users',
'action' => 'welcome',
]);
return $this->redirect($redirect);
}
if ($this->request->is('post') && !$result->isValid()) {
$this->Flash->error(__('Invalid username or password'));
}
}
signup.php
<label for="utype" class="text-gray-600 mb-2 ">
Usertype</label>
<div class="form-check ">
<label class="radio-inline">
<input type="radio" name="utype" value="admin"
class=" px-3 py-2 border border-gray-300 rounded-md
" />;
Admin </label>
<label class="radio-inline">
<input type="radio" name="utype" value="user"
class="px-3 py-2 border border-gray-300 rounded-md"
checked/>;
User </label>
</div>
</div>