<commit_before><?php

/**
 *    Copyright 2015-2017 ppy Pty. Ltd.
 *
 *    This file is part of osu!web. osu!web is distributed with the hope of
 *    attracting more community contributions to the core ecosystem of osu!.
 *
 *    osu!web is free software: you can redistribute it and/or modify
 *    it under the terms of the Affero GNU General Public License version 3
 *    as published by the Free Software Foundation.
 *
 *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
 *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *    See the GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace App\Http\Controllers;

use App\Http\Controllers\Store\Controller as Controller;
use App\Models\Store;
use Auth;
use Request;
use Validator;

class StoreController extends Controller
{
    // bootstrap setup in BaseController
    protected $layout = 'master';

    // Section display for the menu at the top
    protected $section = 'store';

    public function __construct()
    {
        $this->middleware('auth', ['only' => [
            'getInvoice',
            'postNewAddress',
            'postUpdateAddress',
        ]]);

        $this->middleware('check-user-restricted', ['only' => [
            'getInvoice',
            'postNewAddress',
            'postUpdateAddress',
        ]]);

        $this->middleware('verify-user', ['only' => [
            'getInvoice',
            'postUpdateAddress',
        ]]);

        return parent::__construct();
    }

    // GET /store

    public function getIndex()
    {
        return ujs_redirect('/store/listing');
    }

    public function getListing()
    {
        return view('store.index')
            ->with('cart', $this->userCart())
            ->with('products', Store\Product::latest()->simplePaginate(30));
    }

    public function getInvoice($id = null)
    {
        $order = Store\Order::whereHasInvoice()
            ->with('items.product')
            ->findOrFail($id);

        if (Auth::user()->user_id !== $order->user_id && !Auth::user()->isAdmin()) {
            abort(403);
        }

        $sentViaAddress = Store\Address::sender();
        $forShipping = Auth::user()->isAdmin() && get_bool(Request::input('for_shipping'));
        $copies = clamp(get_int(request('copies')), 1, config('store.invoice.max_copies'));

        return view('store.invoice', compact('order', 'forShipping', 'copies', 'sentViaAddress'));
    }

    public function missingMethod($parameters = [])
    {
        abort(404);
    }

    public function postUpdateAddress()
    {
        $address_id = (int) Request::input('id');
        $address = Store\Address::find($address_id);
        $order = $this->userCart();

        if (!$address || $address->user_id !== Auth::user()->user_id) {<commit_msg>store index has no pager<commit_after><?php

/**
 *    Copyright 2015-2017 ppy Pty. Ltd.
 *
 *    This file is part of osu!web. osu!web is distributed with the hope of
 *    attracting more community contributions to the core ecosystem of osu!.
 *
 *    osu!web is free software: you can redistribute it and/or modify
 *    it under the terms of the Affero GNU General Public License version 3
 *    as published by the Free Software Foundation.
 *
 *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
 *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *    See the GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace App\Http\Controllers;

use App\Http\Controllers\Store\Controller as Controller;
use App\Models\Store;
use Auth;
use Request;
use Validator;

class StoreController extends Controller
{
    // bootstrap setup in BaseController
    protected $layout = 'master';

    // Section display for the menu at the top
    protected $section = 'store';

    public function __construct()
    {
        $this->middleware('auth', ['only' => [
            'getInvoice',
            'postNewAddress',
            'postUpdateAddress',
        ]]);

        $this->middleware('check-user-restricted', ['only' => [
            'getInvoice',
            'postNewAddress',
            'postUpdateAddress',
        ]]);

        $this->middleware('verify-user', ['only' => [
            'getInvoice',
            'postUpdateAddress',
        ]]);

        return parent::__construct();
    }

    // GET /store

    public function getIndex()
    {
        return ujs_redirect('/store/listing');
    }

    public function getListing()
    {
        return view('store.index')
            ->with('cart', $this->userCart())
            ->with('products', Store\Product::latest()->get());
    }

    public function getInvoice($id = null)
    {
        $order = Store\Order::whereHasInvoice()
            ->with('items.product')
            ->findOrFail($id);

        if (Auth::user()->user_id !== $order->user_id && !Auth::user()->isAdmin()) {
            abort(403);
        }

        $sentViaAddress = Store\Address::sender();
        $forShipping = Auth::user()->isAdmin() && get_bool(Request::input('for_shipping'));
        $copies = clamp(get_int(request('copies')), 1, config('store.invoice.max_copies'));

        return view('store.invoice', compact('order', 'forShipping', 'copies', 'sentViaAddress'));
    }

    public function missingMethod($parameters = [])
    {
        abort(404);
    }

    public function postUpdateAddress()
    {
        $address_id = (int) Request::input('id');
        $address = Store\Address::find($address_id);
        $order = $this->userCart();

        if (!$address || $address->user_id !== Auth::user()->user_id) {
{'fraction_non_alphanumeric': 0.13694481830417227, 'fraction_numerical': 0.005720053835800807, 'mean_word_length': 2.5705705705705704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2125642', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1652, 'n_words': 454}