Uploading: image.png…
public function login(){
if($this->Auth->user('id')){
$this->Flash->success(ucwords('You are already login!'));
return $this->redirect(['prefix' => false, 'controller' => 'Students', 'action' => 'logout']);
}
$student = $this->Students->newEmptyEntity();
$this->Auth->setConfig('authenticate', [
'Form' => [
'fields' => ['username' => 'code'],
'userModel' => 'Students',
'finder' => 'auth',
],
]);
if ($this->request->is('post')) {
$student = $this->Auth->identify();
$auth = $this->Students->find()
->where([
'Students.code like'=>'%'.$this->request->getData('code').'%',
])
->count();
if($auth > 0){
dd($student);
if (!empty($student)) {
$this->Auth->setUser($student);
$student = $this->Students->get($this->Auth->user('id'));
if($this->Students->save($student)){
$result=['message'=>ucwords('Log In Complete'),'result'=>ucwords('success'),
'redirect' => Router::url(['prefix' => 'Student', 'controller' => 'Reservations', 'action' => 'index'])];
return $this->response->withStatus(200)->withType('application/json')
->withStringBody(json_encode($result));
}else{
$result=['message'=>ucwords('Log In Complete'),'result'=>ucwords('success'),
'redirect' => Router::url(['prefix' => 'Student', 'controller' => 'Reservations', 'action' => 'index'])];
return $this->response->withStatus(200)->withType('application/json')
->withStringBody(json_encode($result));
}
}else{
$result=['message'=>ucwords('Please Check you ID Number'),'result'=>ucwords('error')];
return $this->response->withStatus(422)->withType('application/json')
->withStringBody(json_encode($result));
}
}else{
$result=['message'=>ucwords('Cannot Count'),'result'=>ucwords('error')];
return $this->response->withStatus(422)->withType('application/json')
->withStringBody(json_encode($result));
}
}
$this->set(compact('student'));
}