Skip to content

Instantly share code, notes, and snippets.

@pedropuppim
Created May 31, 2018 12:50
Show Gist options
  • Save pedropuppim/7fe559a325842e5de41189751e8604d7 to your computer and use it in GitHub Desktop.
Save pedropuppim/7fe559a325842e5de41189751e8604d7 to your computer and use it in GitHub Desktop.
login_cakephp3.php
<?php
public function login()
{
$this->layout = 'login_page';
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user){
if ($user['ativo']==1) {
$this->Auth->setUser($user);
$this->LogsAcesso();
return $this->redirect($this->Auth->redirectUrl());
}
}
$this->Flash->error(__('Usuário não encontrado ou dados incorretos.'));
}
}
public function LogsAcesso(){
$this->LoadModel('Acessos');
$save['Acessos']['user_id']=$this->Auth->user('id');
$save['Acessos']['ip']=$this->request->clientIp();
$acesso = $this->Acessos->newEntity();
$acesso = $this->Acessos->patchEntity($acesso, $save);
$this->Acessos->save($acesso);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment