Exemplo n.º 1
0
    $userData = $userGetHandler->getUserBySecret($secret);
    $slim->returnData($userData);
});
$app->get('/:id/badges', function ($id) use($userBadgesHandler, $slim, $app) {
    $userBadgesHandler->setLanguage($app->request()->params('lang'));
    $userBadges = $userBadgesHandler->getUserBadges($id);
    $slim->returnData($userBadges);
});
$app->get('/:id/logout', function () use($app) {
    \session_destroy();
    $app->response()->write("Congratulations! You've now officially logged out!");
});
$app->put('/(:id)', function ($id = null) use($userHandler, $app) {
    if (empty($id)) {
        $id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : -1;
    }
    $data = json_decode($app->request()->getBody(), true);
    //only allow certain attributes to be set via the webservice
    $allowedAttributes = array("username");
    $allowedData = array();
    foreach ($allowedAttributes as $attribute) {
        $allowedData[$attribute] = $data[$attribute];
    }
    $app->response()->write($userHandler->updateUser($id, $allowedData));
});
if (!isset($_SESSION)) {
    session_cache_limiter(false);
    session_start();
}
// start Slim app
$app->run();
Exemplo n.º 2
0
 /**
  * Update a user from the database.
  *
  * @param array $appUser Array of user infos from the application.
  * @param array $user    Array of user infos from OAuth.
  *
  * @return array The updated user from the database
  */
 protected function updateApplicationUser(array $appUser, array $user)
 {
     $userHandler = new UserHandler();
     $dbUser = $userHandler->updateUser($appUser['id'], $user);
     return $dbUser;
 }