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 — master ( c31bff...117582 )
by Caspar
10:25
created

UsersManagementController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Profile;
6
use App\Models\User;
7
use App\Traits\CaptureIpTrait;
8
use Auth;
9
use Illuminate\Http\Request;
10
use jeremykenedy\LaravelRoles\Models\Role;
11
use Validator;
12
13
class UsersManagementController extends Controller
14
{
15
    /**
16
     * Create a new controller instance.
17
     *
18
     * @return void
19
     */
20
    public function __construct()
21
    {
22
        $this->middleware('auth');
23
    }
24
25
    /**
26
     * Display a listing of the resource.
27
     *
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function index()
31
    {
32
        $users = User::all();
33
        $roles = Role::all();
34
35
        return View('usersmanagement.show-users', compact('users', 'roles'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return View('usersmanage...pact('users', 'roles')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
36
    }
37
38
    /**
39
     * Show the form for creating a new resource.
40
     *
41
     * @return \Illuminate\Http\Response
42
     */
43
    public function create()
44
    {
45
        $roles = Role::all();
46
47
        $data = [
48
            'roles' => $roles,
49
        ];
50
51
        return view('usersmanagement.create-user')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('usersmanage...ate-user')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
52
    }
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param \Illuminate\Http\Request $request
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(Request $request)
62
    {
63
        $validator = Validator::make($request->all(),
64
            [
65
                'scoutname'             => 'required|max:255',
66
                'first_name'            => 'required|max:255',
67
                'last_name'             => 'required|max:255',
68
                'password'              => 'required|min:6|max:20|confirmed',
69
                'password_confirmation' => 'required|same:password',
70
                'role'                  => 'required',
71
            ],
72
            [
73
                'scoutname.required'  => trans('auth.scoutNameRequired'),
74
                'first_name.required' => trans('auth.fNameRequired'),
75
                'last_name.required'  => trans('auth.lNameRequired'),
76
                'password.required'   => trans('auth.passwordRequired'),
77
                'password.min'        => trans('auth.PasswordMin'),
78
                'password.max'        => trans('auth.PasswordMax'),
79
                'role.required'       => trans('auth.roleRequired'),
80
            ]
81
        );
82
83
        if ($validator->fails()) {
84
            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...
85
        }
86
87
        $ipAddress = new CaptureIpTrait();
88
        $profile = new Profile();
89
        $name_gen = (($request->input('scoutname') != null) ? $request->input('first_name').'_'.$request->input('scoutname').'_'.$request->input('last_name') : $request->input('first_name').'_'.$request->input('last_name'));
90
91
        $user = User::create([
92
            'scoutname'        => $request->input('scoutname'),
93
            'first_name'       => $request->input('first_name'),
94
            'last_name'        => $request->input('last_name'),
95
            'name_gen'         => $name_gen,
96
            'password'         => bcrypt($request->input('password')),
97
            'token'            => str_random(64),
98
            'admin_ip_address' => $ipAddress->getClientIp(),
99
            'activated'        => 1,
100
        ]);
101
102
        $user->profile()->save($profile);
103
        $user->attachRole($request->input('role'));
104
        $user->save();
105
106
        return redirect('users')->with('success', trans('usersmanagement.createSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('users')...gement.createSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
107
    }
108
109
    /**
110
     * Display the specified resource.
111
     *
112
     * @param int $id
113
     *
114
     * @return \Illuminate\Http\Response
115
     */
116
    public function show($id)
117
    {
118
        $user = User::find($id);
119
120
        return view('usersmanagement.show-user')->withUser($user);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('usersmanage...user')->withUser($user) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
121
    }
122
123
    /**
124
     * Show the form for editing the specified resource.
125
     *
126
     * @param int $id
127
     *
128
     * @return \Illuminate\Http\Response
129
     */
130
    public function edit($id)
131
    {
132
        $user = User::findOrFail($id);
133
        $roles = Role::all();
134
135
        foreach ($user->roles as $user_role) {
136
            $currentRole = $user_role;
137
        }
138
139
        $data = [
140
            'user'        => $user,
141
            'roles'       => $roles,
142
            'currentRole' => $currentRole,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $currentRole seems to be defined by a foreach iteration on line 135. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
143
        ];
144
145
        return view('usersmanagement.edit-user')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('usersmanage...dit-user')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
146
    }
147
148
    /**
149
     * Update the specified resource in storage.
150
     *
151
     * @param \Illuminate\Http\Request $request
152
     * @param int                      $id
153
     *
154
     * @return \Illuminate\Http\Response
155
     */
156
    public function update(Request $request, $id)
157
    {
158
        $currentUser = Auth::user();
0 ignored issues
show
Unused Code introduced by
The assignment to $currentUser is dead and can be removed.
Loading history...
159
        $user = User::find($id);
160
        $ipAddress = new CaptureIpTrait();
161
162
        $validator = Validator::make($request->all(), [
163
            'scoutname'  => 'nullable|string|max:255',
164
            'first_name' => 'required|string|max:255',
165
            'last_name'  => 'required|string|max:255',
166
            'password'   => 'nullable|string|min:6|confirmed',
167
        ]);
168
169
        if ($validator->fails()) {
170
            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...
171
        }
172
173
        $name_gen = (($request->input('scoutname') != null) ? $request->input('first_name').'_'.$request->input('scoutname').'_'.$request->input('last_name') : $request->input('first_name').'_'.$request->input('last_name'));
174
175
        $user->scoutname = $request->input('scoutname');
176
        $user->first_name = $request->input('first_name');
177
        $user->last_name = $request->input('last_name');
178
        $user->name_gen = $name_gen;
179
180
        if ($request->input('password') != null) {
181
            $user->password = bcrypt($request->input('password'));
182
        }
183
184
        $user->detachAllRoles();
185
        $user->attachRole($request->input('role'));
186
        $user->updated_ip_address = $ipAddress->getClientIp();
187
        $user->save();
188
189
        return back()->with('success', trans('usersmanagement.updateSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->with('suc...gement.updateSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
190
    }
191
192
    /**
193
     * Remove the specified resource from storage.
194
     *
195
     * @param int $id
196
     *
197
     * @return \Illuminate\Http\Response
198
     */
199
    public function destroy($id)
200
    {
201
        $currentUser = Auth::user();
202
        $user = User::findOrFail($id);
203
        $ipAddress = new CaptureIpTrait();
204
205
        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...
206
            $user->deleted_ip_address = $ipAddress->getClientIp();
207
            $user->save();
208
            $user->delete();
209
210
            return redirect('users')->with('success', trans('usersmanagement.deleteSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('users')...gement.deleteSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
211
        }
212
213
        return back()->with('error', trans('usersmanagement.deleteSelfError'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->with('err...ment.deleteSelfError')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
214
    }
215
}
216