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.

ProfilesController   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 314
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 314
rs 10
c 0
b 0
f 0
wmc 22

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdMultiKey() 0 3 1
A __construct() 0 3 1
B updateUserPassword() 0 30 3
A profile_validator() 0 4 1
A sendGoodbyEmail() 0 3 1
A getSeperationKey() 0 3 1
A deleteUserAccount() 0 47 3
A getUserByUsername() 0 3 1
B edit() 0 24 2
A validator() 0 4 1
B updateUserAccount() 0 30 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Profile;
6
use App\Models\Theme;
7
use App\Models\User;
8
use App\Notifications\SendGoodbyeEmail;
0 ignored issues
show
Bug introduced by
The type App\Notifications\SendGoodbyeEmail was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use App\Traits\CaptureIpTrait;
10
use Illuminate\Database\Eloquent\ModelNotFoundException;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Facades\Session;
13
use jeremykenedy\Uuid\Uuid;
14
use Validator;
15
use View;
16
17
class ProfilesController extends Controller
18
{
19
    protected $idMultiKey = '618423'; //int
20
    protected $seperationKey = '****';
21
22
    /**
23
     * Create a new controller instance.
24
     *
25
     * @return void
26
     */
27
    public function __construct()
28
    {
29
        $this->middleware('auth');
30
    }
31
32
    /**
33
     * Get a validator for an incoming registration request.
34
     *
35
     * @param array $data
36
     *
37
     * @return \Illuminate\Contracts\Validation\Validator
38
     */
39
    public function profile_validator(array $data)
40
    {
41
        return Validator::make($data, [
42
            'theme_id'         => '',
43
        ]);
44
    }
45
46
    /**
47
     * Fetch user
48
     * (You can extract this to repository method).
49
     *
50
     * @param $username
51
     *
52
     * @return mixed
53
     */
54
    public function getUserByUsername($name_gen)
55
    {
56
        return User::with('profile')->where('name_gen', $name_gen)->firstOrFail();
57
    }
58
59
    /**
60
     * Display the specified resource.
61
     *
62
     * @param string $username
63
     *
64
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
65
     */
66
    public function show($name_gen)
67
    {
68
        try {
69
            $user = $this->getUserByUsername($name_gen);
70
        } catch (ModelNotFoundException $exception) {
71
            abort(404);
72
        }
73
74
        $currentTheme = Theme::find($user->profile->theme_id);
75
76
        $data = [
77
            'user'         => $user,
78
            'currentTheme' => $currentTheme,
79
        ];
80
81
        return view('profiles.show')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('profiles.show')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
82
    }
83
84
    /**
85
     * /profiles/username/edit.
86
     *
87
     * @param $name_gen
88
     *
89
     * @return mixed
90
     */
91
    public function edit($name_gen)
92
    {
93
        try {
94
            $user = $this->getUserByUsername($name_gen);
95
        } catch (ModelNotFoundException $exception) {
96
            return view('pages.status')
97
                ->with('error', trans('profile.notYourProfile'))
98
                ->with('error_title', trans('profile.notYourProfileTitle'));
99
        }
100
101
        $themes = Theme::where('status', 1)
102
                        ->orderBy('name', 'asc')
103
                        ->get();
104
105
        $currentTheme = Theme::find($user->profile->theme_id);
106
107
        $data = [
108
            'user'         => $user,
109
            'themes'       => $themes,
110
            'currentTheme' => $currentTheme,
111
112
        ];
113
114
        return view('profiles.edit')->with($data);
115
    }
116
117
    /**
118
     * Update a user's profile.
119
     *
120
     * @param $name_gen
121
     * @param Request $request
122
     *
123
     * @return mixed
124
     */
125
    public function update($name_gen, Request $request)
126
    {
127
        $user = $this->getUserByUsername($name_gen);
128
129
        $ipAddress = new CaptureIpTrait();
130
131
        $profile_validator = $this->profile_validator($request->all());
132
133
        if ($profile_validator->fails()) {
134
            return back()->withErrors($profile_validator)->withInput();
135
        }
136
137
        $profile = new Profile();
138
        $user->profile()->save($profile);
139
140
        $user->updated_ip_address = $ipAddress->getClientIp();
141
142
        $user->save();
143
144
        return redirect('profile/'.$user->name_gen.'/edit')->with('success', trans('profile.updateSuccess'));
145
    }
146
147
    /**
148
     * Get a validator for an incoming update user request.
149
     *
150
     * @param array $data
151
     *
152
     * @return \Illuminate\Contracts\Validation\Validator
153
     */
154
    public function validator(array $data)
155
    {
156
        return Validator::make($data, [
157
            'scoutn_name' => 'max:255',
158
        ]);
159
    }
160
161
    /**
162
     * Update the specified resource in storage.
163
     *
164
     * @param \Illuminate\Http\Request $request
165
     * @param int                      $id
166
     *
167
     * @return \Illuminate\Http\Response
168
     */
169
    public function updateUserAccount(Request $request, $id)
170
    {
171
        $user = User::findOrFail($id);
172
        $ipAddress = new CaptureIpTrait();
173
        $name_gen = (($request->input('scout_name') != null) ? $request->input('first_name').'_'.$request->input('scout_name').'_'.$request->input('last_name') : $request->input('first_name').'_'.$request->input('last_name'));
174
175
        $validator = Validator::make($request->all(), [
0 ignored issues
show
Unused Code introduced by
The assignment to $validator is dead and can be removed.
Loading history...
176
            'scout_name' => 'max:255',
177
            'first_name' => 'required|max:255',
178
            'last_name'  => 'required|max:255',
179
        ]);
180
181
        $rules = [];
182
183
        $validator = $this->validator($request->all(), $rules);
0 ignored issues
show
Unused Code introduced by
The call to App\Http\Controllers\Pro...Controller::validator() has too many arguments starting with $rules. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

183
        /** @scrutinizer ignore-call */ 
184
        $validator = $this->validator($request->all(), $rules);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
184
185
        if ($validator->fails()) {
186
            return back()->withErrors($validator)->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->withError...validator)->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
187
        }
188
189
        $user->scout_name = $request->input('scout_name');
190
        $user->first_name = $request->input('first_name');
191
        $user->last_name = $request->input('last_name');
192
        $user->name_gen = $name_gen;
193
194
        $user->updated_ip_address = $ipAddress->getClientIp();
195
196
        $user->save();
197
198
        return redirect('profile/'.$user->name_gen.'/edit')->with('success', trans('profile.updateAccountSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('profile...updateAccountSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
199
    }
200
201
    /**
202
     * Update the specified resource in storage.
203
     *
204
     * @param \Illuminate\Http\Request $request
205
     * @param int                      $id
206
     *
207
     * @return \Illuminate\Http\Response
208
     */
209
    public function updateUserPassword(Request $request, $id)
210
    {
211
        $user = User::findOrFail($id);
212
        $ipAddress = new CaptureIpTrait();
213
214
        $validator = Validator::make($request->all(),
215
            [
216
                'password'              => 'required|min:6|max:20|confirmed',
217
                'password_confirmation' => 'required|same:password',
218
            ],
219
            [
220
                'password.required' => trans('auth.passwordRequired'),
221
                'password.min'      => trans('auth.PasswordMin'),
222
                'password.max'      => trans('auth.PasswordMax'),
223
            ]
224
        );
225
226
        if ($validator->fails()) {
227
            return back()->withErrors($validator)->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->withError...validator)->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
228
        }
229
230
        if ($request->input('password') != null) {
231
            $user->password = bcrypt($request->input('password'));
232
        }
233
234
        $user->updated_ip_address = $ipAddress->getClientIp();
235
236
        $user->save();
237
238
        return redirect('profile/'.$user->name_gen.'/edit')->with('success', trans('profile.updatePWSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('profile...file.updatePWSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
239
    }
240
241
    /**
242
     * Update the specified resource in storage.
243
     *
244
     * @param \Illuminate\Http\Request $request
245
     * @param int                      $id
246
     *
247
     * @throws \Exception
248
     *
249
     * @return \Illuminate\Http\Response
250
     */
251
    public function deleteUserAccount(Request $request, $id)
252
    {
253
        $currentUser = \Auth::user();
254
        $user = User::findOrFail($id);
255
        $ipAddress = new CaptureIpTrait();
256
257
        $validator = Validator::make($request->all(),
258
            [
259
                'checkConfirmDelete' => 'required',
260
            ],
261
            [
262
                'checkConfirmDelete.required' => trans('profile.confirmDeleteRequired'),
263
            ]
264
        );
265
266
        if ($user->id != $currentUser->id) {
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
267
            return redirect('profile/'.$user->name_gen.'/edit')->with('error', trans('profile.errorDeleteNotYour'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('profile...e.errorDeleteNotYour')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
268
        }
269
270
        if ($validator->fails()) {
271
            return back()->withErrors($validator)->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->withError...validator)->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
272
        }
273
274
        // Create and encrypt user account restore token
275
        $sepKey = $this->getSeperationKey();
276
        $userIdKey = $this->getIdMultiKey();
277
        $restoreKey = config('settings.restoreKey');
278
        $encrypter = config('settings.restoreUserEncType');
279
        $level1 = $user->id * $userIdKey;
280
        $level2 = urlencode(Uuid::generate(4).$sepKey.$level1);
281
        $level3 = base64_encode($level2);
282
        $level4 = openssl_encrypt($level3, $encrypter, $restoreKey);
283
        $level5 = base64_encode($level4);
284
285
        // Save Restore Token and Ip Address
286
        $user->token = $level5;
287
        $user->deleted_ip_address = $ipAddress->getClientIp();
288
        $user->save();
289
290
        // Soft Delete User
291
        $user->delete();
292
293
        // Clear out the session
294
        $request->session()->flush();
295
        $request->session()->regenerate();
296
297
        return redirect('/login/')->with('success', trans('profile.successUserAccountDeleted'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('/login/...ssUserAccountDeleted')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
298
    }
299
300
    /**
301
     * Send GoodBye Email Function via Notify.
302
     *
303
     * @param array  $user
304
     * @param string $token
305
     *
306
     * @return void
307
     */
308
    public static function sendGoodbyEmail(User $user, $token)
309
    {
310
        $user->notify(new SendGoodbyeEmail($token));
311
    }
312
313
    /**
314
     * Get User Restore ID Multiplication Key.
315
     *
316
     * @return string
317
     */
318
    public function getIdMultiKey()
319
    {
320
        return $this->idMultiKey;
321
    }
322
323
    /**
324
     * Get User Restore Seperation Key.
325
     *
326
     * @return string
327
     */
328
    public function getSeperationKey()
329
    {
330
        return $this->seperationKey;
331
    }
332
}
333