public function __invoke() { $user = Auth::getCurrentUser(); if (!$user->isAdmin()) { $this->app->halt(403, 'You are not an admin'); } }
public function call() { $app = $this->app; $current_user = Auth::getCurrentUser(); // Force login by redirecting unauthenticated users to the login page. if (!$current_user->isAuthenticated()) { if ($app->request->getResourceUri() !== '/login') { return $app->response()->redirect('/login'); } } // Add the current user to the template data $app->view->appendData(array('current_user' => $current_user)); $this->next->call(); }
} } if (!array_key_exists("platform", $_GET)) { $platform = "windows"; } else { $platform = $_GET["platform"]; } $query = new PlatformQuery(); $platform = $query->findOneByName($platform); if ($platform == null) { throw new Exception("Invalid platform specified"); } // Getting the rating queries the database each time, so we do it once here: $header = $game->getRatingHeaderForPlatform($platform); $rating = $game->getRatingForPlatform($platform); $user = Auth::getCurrentUser(); if (Auth::checkIfAuthenticated() && array_key_exists("submit_game_review", $_POST) && array_key_exists("submit_game_rating", $_POST)) { $new_review = $_POST["submit_game_review"]; $new_rating = $_POST["submit_game_rating"]; $review = UserReview::getUserReview($game, $platform, $user); if ($review == null) { $review = new UserReview(); $review->setGame($game); $review->setPlatform($platform); $review->setUser($user); UserAccess::addUserEvent($user, $_SERVER['REMOTE_ADDR'], UserAccessType::addreview); } else { //we're editing an old review UserAccess::addUserEvent($user, $_SERVER['REMOTE_ADDR'], UserAccessType::editreview); } $review->setRatingId($new_rating);
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/../config/config.web.php'; //ini_set('display_errors','1'); //{{{统一输出函数 function ajaxOutput() { global $code, $msg, $data, $respType, $newCrumb, $callback; $code = intval($code); $msg = (string) $msg; Output::out($respType, $code, $msg, $data, $callback, $newCrumb); return true; } register_shutdown_function('ajaxOutput'); //}}} //公共参数处理及校验 $respType = isset($_REQUEST['resp_type']) ? $_REQUEST['resp_type'] : Output::TYPE_JSON; $callback = Output::TYPE_JSON == $respType && isset($_GET['callback']) ? $_GET['callback'] : ''; session_start(); $currentUserId = Auth::isLogined(); if (!$currentUserId) { if (!@in_array(Utility::getPhpUrl(), $NO_LOGIN_AJAX_URLS)) { $code = 2; $msg = '需要重新登录'; die; } } else { $currentUserInfo = Auth::getCurrentUser(); Template::assign(array('currentUser' => $currentUserInfo)); }
protected function getCurrentUser() { return Auth::getCurrentUser(); }