/** * Login process * * @return mixed */ public function loginAction() { if (!$this->request->isPost()) { $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW); return $this->view->pick('secure/login'); } $validate_input = Validator::requiredKeys($this->request->getPost(), ['username' => '', 'password' => '']); if (!$validate_input->ok) { $this->flash->error(Validator::stringFromArray($validate_input->errors, 'Te falta: ')); return $this->response->redirect('/login'); } $response = $this->sdk->authenticate($validate_input->data->username, $validate_input->data->password); if (!$response->success) { $this->flash->error($response->message); return $this->response->redirect('/login'); } $this->session->set('identity', $response->userData->_id); $this->session->set('user_data', $response->userData); $this->session->set('user_session_token', $response->token); if ($this->isLogged()) { return $this->response->redirect('/'); } return $this->response->redirect('/login'); }