I'm looking for a CakePHP 3.x update for this question. Basically, I am authenticating users using the Auth
component in CakePHP 3 and need to include groups
.
My model relations are as follows:
User hasMany Groups
Group hasMany Users
So basically it's a many-to-many relationship.
Currently, my login function looks like this:
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
$this->viewBuilder()->layout('login');
}
Is there a way to do this with the Auth
component?