GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

APIController::revoke()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 4
nop 2
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>
5
 * Some Modifications (c) 2015 Dylan Seidt <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Pterodactyl\Http\Controllers\Base;
27
28
use Log;
29
use Alert;
30
use Illuminate\Http\Request;
31
use Pterodactyl\Models\APIKey;
32
use Pterodactyl\Models\APIPermission;
33
use Pterodactyl\Repositories\APIRepository;
34
use Pterodactyl\Exceptions\DisplayException;
35
use Pterodactyl\Http\Controllers\Controller;
36
use Pterodactyl\Exceptions\DisplayValidationException;
37
38
class APIController extends Controller
39
{
40
    /**
41
     * Display base API index page.
42
     *
43
     * @param  \Illuminate\Http\Request  $request
44
     * @return \Illuminate\View\View
45
     */
46
    public function index(Request $request)
47
    {
48
        return view('base.api.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('base.api.index', a...->user()->id)->get())); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 48 which is incompatible with the return type documented by Pterodactyl\Http\Control...se\APIController::index of type Illuminate\View\View.
Loading history...
49
            'keys' => APIKey::where('user_id', $request->user()->id)->get(),
50
        ]);
51
    }
52
53
    /**
54
     * Display API key creation page.
55
     *
56
     * @param  \Illuminate\Http\Request  $request
57
     * @return \Illuminate\View\View
58
     */
59
    public function create(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        return view('base.api.new', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('base.api.new', arr...'_user')->toArray()))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 61 which is incompatible with the return type documented by Pterodactyl\Http\Control...e\APIController::create of type Illuminate\View\View.
Loading history...
62
            'permissions' => [
63
                'user' => collect(APIPermission::permissions())->pull('_user'),
64
                'admin' => collect(APIPermission::permissions())->except('_user')->toArray(),
65
            ],
66
        ]);
67
    }
68
69
    /**
70
     * Handle saving new API key.
71
     *
72
     * @param  \Illuminate\Http\Request  $request
73
     * @return \Illuminate\Http\RedirectResponse
74
     */
75 View Code Duplication
    public function store(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        try {
78
            $repo = new APIRepository($request->user());
79
            $secret = $repo->create($request->intersect([
80
                'memo', 'allowed_ips',
81
                'admin_permissions', 'permissions',
82
            ]));
83
            Alert::success('An API Key-Pair has successfully been generated. The API secret for this public key is shown below and will not be shown again.<br /><br /><code>' . $secret . '</code>')->flash();
84
85
            return redirect()->route('account.api');
86
        } catch (DisplayValidationException $ex) {
87
            return redirect()->route('account.api.new')->withErrors(json_decode($ex->getMessage()))->withInput();
88
        } catch (DisplayException $ex) {
89
            Alert::danger($ex->getMessage())->flash();
90
        } catch (\Exception $ex) {
91
            Log::error($ex);
92
            Alert::danger('An unhandled exception occured while attempting to add this API key.')->flash();
93
        }
94
95
        return redirect()->route('account.api.new')->withInput();
96
    }
97
98
    /**
99
     * Handle revoking API key.
100
     *
101
     * @param  \Illuminate\Http\Request  $request
102
     * @param  string                    $key
103
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
104
     */
105
    public function revoke(Request $request, $key)
106
    {
107
        try {
108
            $repo = new APIRepository($request->user());
109
            $repo->revoke($key);
110
111
            return response('', 204);
112
        } catch (\Exception $ex) {
113
            Log::error($ex);
114
115
            return response()->json([
116
                'error' => 'An error occured while attempting to remove this key.',
117
            ], 503);
118
        }
119
    }
120
}
121