/** * Returns associative array with information about current session. * * */ public static function apiCurrentSession(Request $r = null) { if (defined('OMEGAUP_SESSION_CACHE_ENABLED') && OMEGAUP_SESSION_CACHE_ENABLED === true && !is_null(self::$current_session)) { return self::$current_session; } if (is_null($r)) { $r = new Request(); } if (is_null($r['auth_token'])) { $r['auth_token'] = SessionController::getAuthToken($r); } $authToken = $r['auth_token']; if ($authToken != null && defined('OMEGAUP_SESSION_CACHE_ENABLED') && OMEGAUP_SESSION_CACHE_ENABLED === true) { Cache::getFromCacheOrSet(Cache::SESSION_PREFIX, $authToken, $r, array('SessionController', 'getCurrentSession'), $session, APC_USER_CACHE_SESSION_TIMEOUT); self::$current_session = $session; } else { self::$current_session = SessionController::getCurrentSession($r); } return self::$current_session; }
public static function apiArbitrateRequest(Request $r) { $result = array("status" => "ok"); if (is_null($r["resolution"])) { throw new InvalidParameterException("invalidParameters"); } // user must be admin of contest to arbitrate security $current_ses = SessionController::getCurrentSession($r); try { $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]); } catch (Exception $e) { throw new NotFoundException($e); } if (is_null($r["contest"])) { throw new NotFoundException("contestNotFound"); } $r["target_user"] = UsersDAO::FindByUsername($r["username"]); $request = ContestUserRequestDAO::getByPK($r["target_user"]->user_id, $r["contest"]->contest_id); if (is_null($request)) { throw new InvalidParameterException("userNotInListOfRequests"); } if ($r["resolution"] === "false") { // "false" casts to true. $resolution = false; } else { $resolution = (bool) $r["resolution"]; } $request->setAccepted($resolution); $request->setExtraNote($r["note"]); $request->setLastUpdate(gmdate('Y-m-d H:i:s')); ContestUserRequestDAO::save($request); // Save this action in the history $history = new ContestUserRequestHistory(); $history->user_id = $request->user_id; $history->contest_id = $request->user_id; $history->time = $request->last_update; $history->admin_id = $current_ses["id"]; $history->accepted = $request->accepted; ContestUserRequestHistoryDAO::save($history); self::$log->info("Arbitrated contest for user, new accepted user_id=" . $r["target_user"]->user_id . ", state=" . $resolution); return $result; }
public static function apiArbitrateRequest(Request $r) { $result = array('status' => 'ok'); if (is_null($r['resolution'])) { throw new InvalidParameterException('invalidParameters'); } // user must be admin of contest to arbitrate security $current_ses = SessionController::getCurrentSession($r); try { $r['contest'] = ContestsDAO::getByAlias($r['contest_alias']); } catch (Exception $e) { throw new NotFoundException($e); } if (is_null($r['contest'])) { throw new NotFoundException('contestNotFound'); } $r['target_user'] = UsersDAO::FindByUsername($r['username']); $request = ContestUserRequestDAO::getByPK($r['target_user']->user_id, $r['contest']->contest_id); if (is_null($request)) { throw new InvalidParameterException('userNotInListOfRequests'); } if ($r['resolution'] === 'false') { // "false" casts to true. $resolution = false; } else { $resolution = (bool) $r['resolution']; } $request->setAccepted($resolution); $request->setExtraNote($r['note']); $request->setLastUpdate(gmdate('Y-m-d H:i:s')); ContestUserRequestDAO::save($request); // Save this action in the history $history = new ContestUserRequestHistory(); $history->user_id = $request->user_id; $history->contest_id = $request->user_id; $history->time = $request->last_update; $history->admin_id = $current_ses['id']; $history->accepted = $request->accepted; ContestUserRequestHistoryDAO::save($history); self::$log->info('Arbitrated contest for user, new accepted user_id=' . $r['target_user']->user_id . ', state=' . $resolution); return $result; }