1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers\Auth; |
||
4 | |||
5 | use App\User; |
||
6 | use Carbon\Carbon; |
||
7 | use App\UserInitialize; |
||
8 | use Illuminate\Http\Request; |
||
9 | use Illuminate\Validation\Rule; |
||
10 | use Illuminate\Support\Facades\Log; |
||
11 | use App\Http\Controllers\Controller; |
||
12 | use Illuminate\Support\Facades\Auth; |
||
13 | use Illuminate\Support\Facades\Hash; |
||
14 | use Illuminate\Support\Facades\Route; |
||
15 | |||
16 | class InitializeUserController extends Controller |
||
17 | { |
||
18 | // |
||
19 | public function __construct() |
||
20 | { |
||
21 | $this->middleware('guest'); |
||
22 | } |
||
23 | |||
24 | // Bring up the "Finish User Setup" form |
||
25 | public function initializeUser($hash) |
||
26 | { |
||
27 | // Validate the hash token |
||
28 | $user = UserInitialize::where('token', $hash)->get(); |
||
29 | |||
30 | if ($user->isEmpty()) { |
||
31 | Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id); |
||
32 | Log::warning('Visitor at IP Address ' . \Request::ip() . ' tried to access invalid initialize hash - ' . $hash); |
||
33 | return abort(404); |
||
1 ignored issue
–
show
|
|||
34 | } |
||
35 | |||
36 | Log::debug('Route ' . Route::currentRouteName() . ' visited.'); |
||
37 | Log::debug('Link Hash -' . $hash); |
||
38 | return view('account.initializeUser', ['hash' => $hash]); |
||
39 | } |
||
40 | |||
41 | // Submit the initialize user form |
||
42 | public function submitInitializeUser(Request $request, $hash) |
||
43 | { |
||
44 | // Verify that the link matches the assigned email address |
||
45 | $valid = UserInitialize::where('token', $hash)->first(); |
||
46 | if (empty($valid)) { |
||
47 | Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id); |
||
48 | Log::warning('Visitor at IP Address ' . \Request::ip() . ' tried to submit an invalid User Initialization link - ' . $hash); |
||
49 | return abort(404); |
||
1 ignored issue
–
show
Are you sure the usage of
abort(404) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||
50 | } |
||
51 | |||
52 | // Validate the form |
||
53 | $request->validate([ |
||
54 | 'username' => [ |
||
55 | 'required', |
||
56 | Rule::in([$valid->username]), |
||
57 | ], |
||
58 | 'newPass' => 'required|string|min:6|confirmed' |
||
59 | ]); |
||
60 | |||
61 | // Get the users information |
||
62 | $userData = User::where('username', $valid->username)->first(); |
||
63 | |||
64 | $nextChange = config('auth.passwords.settings.expire') != null ? Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
||
65 | |||
66 | // Update the password |
||
67 | User::find($userData->user_id)->update( |
||
68 | [ |
||
69 | 'password' => bcrypt($request->newPass), |
||
70 | 'password_expires' => $nextChange |
||
71 | ] |
||
72 | ); |
||
73 | |||
74 | // Remove the initialize instance |
||
75 | UserInitialize::find($valid->id)->delete(); |
||
76 | |||
77 | // Log in the user |
||
78 | Auth::loginUsingID($userData->user_id); |
||
79 | |||
80 | // Redirect the user to the dashboard |
||
81 | Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id); |
||
82 | Log::debug('Initialize Data - ', $request->toArray()); |
||
83 | Log::notice('User has setup account', ['user_id' => $userData->user_id]); |
||
84 | return redirect(route('dashboard')); |
||
85 | } |
||
86 | } |
||
87 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.