public function executeViewSessionArrays(\Library\HttpRequest $rq) { $output = array(); switch ($rq->getData("type")) { case "pm": $output = var_dump(\Applications\PMTool\Helpers\PmHelper::GetSessionPms($this->user())); break; case "project": $output = var_dump(\Applications\PMTool\Helpers\ProjectHelper::GetSessionProjects($this->user())); break; case "task": $output = var_dump(\Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->user())); break; case "route": $output = var_dump($this->user->getAttribute(\Library\Enums\SessionKeys::SessionRoutes)); break; default: break; } //echo '<pre>', print_r($output), '</pre>'; \Library\HttpResponse::encodeJson($output); die; }
/** * Set the default response from WS * * @param string $resxKey * @param string $step * @param \Applications\PMTool\Models\Dao\Project_manager $user * @return aeeay */ public function SendResponseWS($result, $params) { if ($params["step"] === "success") { $result["result"] = 1; $result["message"] = $params["resx_file"] === "ws_defaults" || array_key_exists("directory", $params) && $params["directory"] === "common" ? $this->app->i8n->getCommonResource($params["resx_file"], "message_success_" . $params["resx_key"]) : $this->app->i8n->getLocalResource($params["resx_file"], "message_success_" . $params["resx_key"]); } else { $result["result"] = 0; $result["message"] = $params["resx_file"] === "ws_defaults" || array_key_exists("directory", $params) && $params["directory"] === "common" ? $this->app->i8n->getCommonResource($params["resx_file"], "message_error_" . $params["resx_key"]) : $this->app->i8n->getLocalResource($params["resx_file"], "message_error_" . $params["resx_key"]); } echo \Library\HttpResponse::encodeJson($result); }
/** * Method that receives the call from JS Client to login a user * * @param \Library\HttpRequest $rq: the request * @return json object A JSON object with the result bool value and success/error message */ public function executeAuthenticate(\Library\HttpRequest $rq) { //Initialize the response to error. $result = $this->InitResponseWS(); //Let's retrieve the inputs from AJAX POST request $data_sent = $this->dataPost(); $authProvider = new AuthProvider($this->app->config->get("encryption_key"), $this->managers->getManagerOf('Login')); $authProvider->prepareUser($data_sent); if ($authProvider->getUser() instanceof \Library\Interfaces\IUser) { $this->app->auth->authenticate($authProvider->getUser()); $this->user->setAttribute(\Library\Enums\SessionKeys::UserTypeObject, $authProvider->getUserType()); if ($authProvider->getUser()) { $user = $this->app->user; $routes = array_filter($this->app->router->routes(), function ($route) use($user) { return count($route->role()) == 0 || in_array($user->getRole(), $route->role()); }); \Applications\PMTool\Helpers\UserHelper::SaveRoutes($user, $routes); switch ($authProvider->getUser()->getType()) { case 'technician_id': \Applications\PMTool\Helpers\TaskHelper::UnsetCurrentSessionTask($this->user); break; case 'pm_id': \Applications\PMTool\Helpers\PmHelper::StoreSessionPm($this, $authProvider->getUserType(), true); break; } $result = $this->InitResponseWS("success"); $result['role'] = $user->getRole(); } } //return the JSON data echo \Library\HttpResponse::encodeJson($result); }