Пример #1
0
 private function runAppPreFlight($action, $actionName, $mwOptions = NULL, $headers = array())
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'OPTIONS', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'ACCEPT' => 'application/json', 'SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/' . $actionName));
     $app = new \Slim\Slim();
     $app->setName($actionName);
     $mw = function () {
         // Do nothing
     };
     if (isset($mwOptions)) {
         if (is_callable($mwOptions)) {
             $mw = $mwOptions;
         } else {
             $mwOptions['appName'] = $actionName;
             $mw = \CorsSlim\CorsSlim::routeMiddleware($mwOptions);
         }
     }
     $app->options('/:name', $mw, function ($name) use($app, $action) {
     });
     $app->delete('/:name', $mw, function ($name) use($app, $action) {
         if ($app->request->isHead()) {
             $app->status(204);
             return;
         }
         $app->contentType('application/json');
         $app->response->write(json_encode(array("action" => $action, "method" => "DELETE", "name" => $name)));
     });
     foreach ($headers as $key => $value) {
         $app->request->headers()->set($key, $value);
     }
     $app->run();
     return $app;
 }
Пример #2
0
});
$app->post('/view', \CorsSlim\CorsSlim::routeMiddleware(), function () use($app) {
    $response = array();
    $db = new DbHandler();
    $profile = json_decode($app->request->getBody());
    $user = $db->getOneRecord("select uid, \r\n                                      name, \r\n                                      gender, \r\n                                      address,\r\n                                      created, \r\n                                      mainphoto, \r\n                                      aboutme, \r\n                                      education, \r\n                                      ethnicity, \r\n                                      nationality,\r\n                                      relationshipstatus,\r\n                                      smoking\r\n                                      from customers_auth where uid=" . $profile->uid);
    if ($user != NULL) {
        $response['status'] = "success";
        $response['message'] = $user;
    } else {
        $response['status'] = "error";
        $response['message'] = 'No such user is registered';
    }
    utils::echoResponse(200, $response);
});
$app->post('/updateprofile', \CorsSlim\CorsSlim::routeMiddleware(), function () use($app) {
    $profile1 = json_decode($app->request->getBody());
    $profile = $profile1->profile;
    $table_name = "customers_auth";
    $column_names = array('aboutme', 'education', 'ethnicity', 'nationality', 'relationshipstatus', 'smoking');
    $db = new DbHandler();
    $isUserExists = $db->getOneRecord("select 1 from customers_auth where uid=" . $app->jwt->data->userId);
    if ($isUserExists) {
        $result = $db->updateTable("aboutme=\"{$profile->aboutme}\", \r\n                                    education=\"{$profile->education}\", \r\n                                    ethnicity=\"{$profile->ethnicity}\", \r\n                                    nationality=\"{$profile->nationality}\",\r\n                                    smoking=\"{$profile->smoking}\", \r\n                                    relationshipstatus=\"{$profile->relationshipstatus}\"", $table_name, $app->jwt->data->userId);
        if ($result != NULL) {
            $response["status"] = "success";
            $response["message"] = $profile;
            utils::echoResponse(200, $response);
        } else {
            $response["status"] = "error";
            $response["message"] = $profile;