public function index_post() { if (!$this->post('auth')) { $this->response(NULL, 400); } $auth = $this->post('auth'); $user = $this->user_model->auth($auth); if (!is_null($user)) { if (phpass_check($user, $auth)) { $val['token'] = jwd_create_token($user); $result = $this->user_model->update($user['id'], $val); unset($user['password']); $this->response(array('token' => $val['token'], 'user' => $user, 200)); } else { $this->response(array('message' => array('password' => 'Contraseña Incorrecta')), 401); } } else { $this->response(array('message' => array('email' => 'Correo Incorrecto')), 401); } }
public function index_post() { if (!$this->post('user')) { $this->response(array('error' => 'BAD REQUEST'), 400); } $user = $this->post('user'); $user['password'] = phpass_hash($user); $userId = $this->user_model->save($user); if (!is_null($userId)) { $user['id'] = $userId; unset($user['password']); $val['token'] = jwd_create_token($user); $result = $this->user_model->update($userId, $val); if (!is_null($result)) { $this->response(array('user' => $user, 'token' => $val['token']), 200); } else { $this->response(array('error' => 'Internal Server Error'), 500); } } else { $this->response(array('error' => 'Internal Server Error'), 500); } }