/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->check() && $this->auth->user()->isRestricted()) { return error_popup(trans('errors.no_restricted_access')); } return $next($request); }
public function update($id) { $order = Store\Order::findOrFail($id); if ($order->status !== 'paid') { return error_popup("order status {$order->status} is invalid."); } $order->unguard(); $order->update(Request::input('order')); $order->save(); return ['message' => "order {$id} updated"]; }
public function updateProfileCover() { if (Request::hasFile('cover_file') && !Auth::user()->osu_subscriber) { return error_popup(trans('errors.supporter_only')); } try { Auth::user()->profileCustomization()->firstOrCreate([])->setCover(Request::input('cover_id'), Request::file('cover_file')); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } return Auth::user()->defaultJson(); }
public function vote($id) { $discussion = BeatmapDiscussion::findOrFail($id); priv_check('BeatmapDiscussionVote', $discussion)->ensureCan(); $params = get_params(Request::all(), 'beatmap_discussion_vote', ['score:int']); $params['user_id'] = Auth::user()->user_id; if ($discussion->vote($params)) { return $discussion->beatmapsetDiscussion->defaultJson(Auth::user()); } else { return error_popup(trans('beatmaps.discussion-votes.update.error')); } }
public function update($id) { $cover = ForumCover::findOrFail($id); if (Request::hasFile('cover_file') === true) { try { $cover = $cover->updateFile(Request::file('cover_file')->getRealPath(), Auth::user()); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } } return fractal_item_array($cover, new ForumCoverTransformer()); }
public function register($id) { $tournament = Tournament::findOrFail($id); $user = Auth::user(); if (!$tournament->isRegistrationOpen()) { return error_popup('registrations are closed!'); } if (!$tournament->isValidRank($user)) { return error_popup('invalid rank!'); } $tournament->register($user); return ujs_redirect("/tournaments/{$id}"); }
public function update($id) { $cover = TopicCover::findOrFail($id); priv_check('ForumTopicCoverEdit', $cover)->ensureCan(); if (Request::hasFile('cover_file') === true) { try { $cover = $cover->updateFile(Request::file('cover_file')->getRealPath(), Auth::user()); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } } return json_item($cover, new TopicCoverTransformer()); }
public function updateProfileCover() { if (Request::hasFile('cover_file') && !Auth::user()->osu_subscriber) { abort(403); } $customization = Auth::user()->profileCustomization()->firstOrNew([]); $customization->setCover($errors, Request::input('cover_id'), Request::file('cover_file')); if (count($errors) === 0) { return Auth::user()->defaultJson(); } else { return error_popup(implode(',', $errors)); } }
public function update($orderId, $orderItemId) { $item = Store\OrderItem::findOrFail($orderItemId); if ($item->order_id !== (int) $orderId) { return error_popup('invalid order id for this item.'); } if ($item->order->status !== 'paid') { return error_popup("order status {$item->order->status} is invalid."); } $item->unguard(); $item->update(Request::input('item')); $item->save(); return ['message' => "order item {$orderItemId} updated"]; }
public function login() { $ip = Request::getClientIp(); $username = Request::input('username'); $password = Request::input('password'); $remember = Request::input('remember') === 'yes'; $user = User::findForLogin($username); $authError = User::attemptLogin($user, $password, $ip); if ($authError === null) { Request::session()->flush(); Request::session()->regenerateToken(); Auth::login($user, $remember); return ['header' => render_to_string('layout._header_user'), 'header_popup' => render_to_string('layout._popup_user'), 'user' => Auth::user()->defaultJson()]; } else { return error_popup($authError); } }
public function login() { $ip = Request::getClientIp(); if (LoginAttempt::isLocked($ip)) { return error_popup("your IP address is locked. Please wait a few minutes."); } else { $username = Request::input("username"); $password = Request::input("password"); $remember = Request::input("remember") === "yes"; Auth::attempt(['username' => $username, 'password' => $password], $remember); if (Auth::check()) { return Auth::user(); } else { LoginAttempt::failedAttempt($ip, $username); return error_popup("wrong password or username"); } } }
public function login() { $ip = Request::getClientIp(); if (LoginAttempt::isLocked($ip)) { return error_popup('your IP address is locked. Please wait a few minutes.'); } else { $username = Request::input('username'); $password = Request::input('password'); $remember = Request::input('remember') === 'yes'; Auth::attempt(['username' => $username, 'password' => $password], $remember); if (Auth::check()) { return Auth::user()->defaultJson(); } else { LoginAttempt::failedAttempt($ip, $username); return error_popup('wrong password or username'); } } }
public function postSlackAgree() { $user = Auth::user(); if ($user->isSlackEligible() === false) { return error_popup(trans('errors.community.slack.not-eligible')); } $token = config('slack.token'); $contents = file_get_contents("https://osu-public.slack.com/api/users.admin.invite?email={$user->user_email}&token={$token}&set_active=true"); if ($contents === false) { return error_popup(trans('errors.community.slack.slack-error')); } $contents = json_decode($contents, true); if ($contents['ok'] === true) { $user->slackUser()->create([]); return ['ok' => true]; } else { return error_popup(trans(trans('errors.community.slack.slack-error'))); } }
public function store() { $discussion = BeatmapDiscussion::findOrNew(Request::input('beatmap_discussion_id')); $isNewDiscussion = $discussion->id === null; if ($isNewDiscussion) { $beatmapsetDiscussion = BeatmapsetDiscussion::where('beatmapset_id', Request::input('beatmapset_id'))->firstOrFail(); $discussion->beatmapset_discussion_id = $beatmapsetDiscussion->id; } $posts = [new BeatmapDiscussionPost($this->postParams($discussion))]; $previousDiscussionResolved = $discussion->resolved; $discussion->fill($this->discussionParams($isNewDiscussion)); priv_check('BeatmapDiscussionPost', $discussion)->ensureCan(); if ($discussion->resolved === true) { priv_check('BeatmapDiscussionResolve', $discussion)->ensureCan(); } if (!$isNewDiscussion && $discussion->resolved !== $previousDiscussionResolved) { $posts[] = BeatmapDiscussionPost::generateLogResolveChange(Auth::user(), $discussion->resolved); } try { $saved = DB::transaction(function () use($posts, $discussion) { if ($discussion->save() === false) { throw new Exception('failed'); } foreach ($posts as $post) { // done here since discussion may or may not previously exist $post->beatmap_discussion_id = $discussion->id; if ($post->save() === false) { throw new Exception('failed'); } } return true; }); } catch (Exception $_e) { $saved = false; } $postIds = array_pluck($posts, 'id'); if ($saved === true) { return ['beatmapset_discussion' => $posts[0]->beatmapsetDiscussion->defaultJson(Auth::user()), 'beatmap_discussion_post_ids' => $postIds, 'beatmap_discussion_id' => $discussion->id]; } else { return error_popup(trans('beatmaps.discussion-posts.store.error')); } }
public function login() { $ip = Request::getClientIp(); if (LoginAttempt::isLocked($ip)) { return error_popup('your IP address is locked. Please wait a few minutes.'); } else { $usernameOrEmail = Request::input('username'); $user = User::where('username', $usernameOrEmail)->orWhere('user_email', $usernameOrEmail)->first(); $password = Request::input('password'); $remember = Request::input('remember') === 'yes'; $validAuth = $user === null ? false : Auth::getProvider()->validateCredentials($user, compact('password')); if ($validAuth) { Request::session()->flush(); Request::session()->regenerateToken(); Auth::login($user, $remember); return ['header' => render_to_string('layout._header_user', ['_user' => Auth::user()]), 'header_popup' => render_to_string('layout._popup_user', ['_user' => Auth::user()]), 'user' => Auth::user()->defaultJson()]; } else { LoginAttempt::failedAttempt($ip, $user); return error_popup('wrong password or email'); } } }
public function scores($id) { $beatmap = Beatmap::findOrFail($id); $mode = Request::input('mode', Beatmap::modeStr($beatmap->playmode)); $mods = Request::input('enabledMods'); $type = Request::input('type', 'global'); $user = Auth::user(); if (!is_array($mods)) { $mods = []; } if ($type !== 'global' || !empty($mods)) { if ($user === null || !$user->isSupporter()) { return error_popup(trans('errors.supporter_only')); } } try { $query = $beatmap->scoresBest($mode)->defaultListing()->with('user'); } catch (\InvalidArgumentException $ex) { return error_popup($ex->getMessage()); } $query->withMods($mods); switch ($type) { case 'country': $query->fromCountry($user->country_acronym); break; case 'friend': $query->friendsOf($user); break; } $scoresList = json_collection($query->get(), new ScoreTransformer(), 'user'); if ($user !== null) { $score = (clone $query)->where('user_id', $user->user_id)->first(); if ($score !== null) { $userScore = json_item($score, new ScoreTransformer(), 'user'); $userScorePosition = 1 + (clone $query)->limit(null)->where('score', '>', $score->score)->count(); } } return ['scoresList' => $scoresList, 'userScore' => $userScore ?? null, 'userScorePosition' => $userScorePosition ?? null]; }
public function updateProfile() { if (Request::hasFile('cover_file') && !Auth::user()->osu_subscriber) { return error_popup(trans('errors.supporter_only')); } if (Request::hasFile('cover_file') || Request::has('cover_id')) { try { Auth::user()->profileCustomization()->firstOrCreate([])->setCover(Request::input('cover_id'), Request::file('cover_file')); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } } if (Request::has('order')) { $order = Request::input('order'); $error = 'errors.account.profile-order.generic'; // Checking whether the input has the same amount of elements // as the master sections array. if (count($order) !== count(UserProfileCustomization::$sections)) { return error_popup(trans($error)); } // Checking if any section that was sent in input // also appears in the master sections arrray. foreach ($order as $i) { if (!in_array($i, UserProfileCustomization::$sections, true)) { return error_popup(trans($error)); } } // Checking whether the elements sent in input do not repeat. $occurences = array_count_values($order); foreach ($occurences as $i) { if ($i > 1) { return error_popup(trans($error)); } } Auth::user()->profileCustomization()->firstOrCreate([])->setExtrasOrder($order); } return Auth::user()->defaultJson(); }
public function postAddToCart() { $result = $this->userCart()->updateItem(Request::input("item", []), true); if ($result[0]) { return ujs_redirect('/store/cart'); } else { return error_popup($result[1]); } }
public function voteFeature($topicId) { $star = FeatureVote::createNew(['user_id' => Auth::user()->user_id, 'topic_id' => $topicId]); if ($star->getKey() !== null) { return ujs_redirect(route('forum.topics.show', $topicId)); } else { return error_popup(implode(' ', $star->validationErrors()->allMessages())); } }
public function verify() { if ($this->isDone()) { return $this->verified(); } $expireDate = $this->request->session()->get('verification_expire_date'); $tries = $this->request->session()->get('verification_tries'); $key = $this->request->session()->get('verification_key'); if (!present($expireDate) || !present($tries) || !present($key)) { $this->issue(); return error_popup(trans('user_verification.errors.expired')); } if ($expireDate->isPast()) { $this->issue(); return error_popup(trans('user_verification.errors.expired')); } if ($tries > config('osu.user.verification_key_tries_limit')) { $this->issue(); return error_popup(trans('user_verification.errors.retries_exceeded')); } if (str_replace(' ', '', $this->request->input('verification_key')) !== $key) { $this->request->session()->put('verification_tries', $tries + 1); return error_popup(trans('user_verification.errors.incorrect_key')); } return $this->verified(); }
public function putRequestNotification($product_id, $action) { $user = Auth::user(); $product = Store\Product::findOrFail($product_id); if ($product->inStock()) { return error_popup(trans('store.product.notification_in_stock')); } $request = $product->notificationRequests()->where('user_id', $user->user_id)->first(); if ($request && $action === 'create') { return error_popup(trans('store.product.notification_exists')); } elseif ($request) { $request->delete(); } if (!$request && $action === 'delete') { return error_popup(trans('store.product.notification_doesnt_exist')); } elseif (!$request) { $request = Store\NotificationRequest::create(['user_id' => $user->user_id, 'product_id' => $product_id]); } return js_view('layout.ujs-reload'); }
public function disqualify($id) { $beatmapset = Beatmapset::findOrFail($id); priv_check('BeatmapsetDisqualify', $beatmapset)->ensureCan(); if (!$beatmapset->disqualify(Auth::user(), Request::input('comment'))) { return error_popup(trans('beatmaps.nominations.incorrect-state')); } return ['beatmapset' => $beatmapset->defaultJson(Auth::user())]; }