Вы можете достичь этого как.
Для CakePHP 3.x: регистрация в функции login()
.
После входа в систему пользователь CakePHP возвращает массив объекта $user
. Вы можете использовать $user['id']
для проверки записей в модели Profile
, например
public function login() {
$this->layout = null;
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
// Check for profile record
$profile = $this->Users->Profiles->find()
->where([
'Profiles.user_id' => $user['id']
])->first();
if (!$profile) {
$this->Flash->error(__('Your profile is not ready yet. Please try again later'));
return somewhere;
} else {
$this->Auth->setUser($user);
$this->Flash->success(__('Login success'));
return $this->redirect($this->Auth->redirectUrl());
}
}
$this->Flash->errorAlert(__('Your username or password was incorrect.'));
}
}
Для CakePHP 2.x: проверка в функции входа в систему ()
Этот пример будет работать с CakePHP 2.x.
public function login() {
$this->layout = null;
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$profile = $this->Profile->find('first', [
'user_id' => $this->Auth->user('id')
]);
if (!$profile) {
$this->Flash->errorAlert(__('Your profile is not ready yet. Please try again later'));
} else {
return $this->redirect($this->Auth->redirectUrl());
}
}
$this->Flash->errorAlert(__('Your username or password was incorrect.'));
}
if ($this->Session->read('Auth.User')) {
$this->Session->setFlash('You are logged in!');
return $this->redirect('/panel');
}
}