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.
Completed
Push — develop ( edd268...5f1bfc )
by Dane
03:00
created

AccountController::email()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 4
Ratio 18.18 %

Importance

Changes 0
Metric Value
dl 4
loc 22
rs 9.2
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2016 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\User;
32
use Pterodactyl\Repositories\UserRepository;
33
use Pterodactyl\Http\Controllers\Controller;
34
use Pterodactyl\Exceptions\DisplayValidationException;
35
36
class AccountController extends Controller
37
{
38
    /**
39
     * Display base account information page.
40
     *
41
     * @param  \Illuminate\Http\Request $request
42
     * @return \Illuminate\Contracts\View\View
43
     */
44
    public function index(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...
45
    {
46
        return view('base.account');
47
    }
48
49
    /**
50
     * Update details for a users account.
51
     * @param  \Illuminate\Http\Request $request
52
     * @return void
53
     */
54
    public function update(Request $request)
55
    {
56
        $data = [];
57
58
        // Request to update account Password
59
        if ($request->input('do_action') === 'password') {
60
            $this->validate($request, [
61
                'current_password' => 'required',
62
                'new_password' => 'required|confirmed|' . User::PASSWORD_RULES,
63
                'new_password_confirmation' => 'required',
64
            ]);
65
66
            $data['password'] = $request->input('new_password');
67
68
        // Request to update account Email
69
        } else if ($request->input('do_action') === 'email') {
70
            $data['email'] = $request->input('new_email');
71
72
        // Request to update account Identity
73
        } else if ($request->input('do_action') === 'identity') {
74
            $data = $request->only(['name_first', 'name_last', 'username']);
75
76
        // Unknown, hit em with a 404
77
        } else {
78
            return abort(404);
79
        }
80
81
        if (
82
            in_array($request->input('do_action'), ['email', 'password'])
83
            && ! password_verify($request->input('password'), $request->user()->password)
84
        ) {
85
            Alert::danger(trans('base.account.invalid_pass'))->flash();
86
            return redirect()->route('account');
87
        }
88
89
        try {
90
            $repo = new UserRepository;
91
            $repo->update($request->user()->id, $data);
92
            Alert::success('Your account details were successfully updated.')->flash();
93
        } catch (DisplayValidationException $ex) {
94
            return redirect()->route('account')->withErrors(json_decode($ex->getMessage()));
95
        } catch (\Exception $ex) {
96
            Log::error($ex);
97
            Alert::danger(trans('base.account.exception'))->flash();
98
        }
99
100
        return redirect()->route('account');
101
    }
102
}
103