GCTC-NTGC /
TalentCloud
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Http\Controllers\Controller; |
||||
| 6 | use App\Models\User; |
||||
| 7 | use App\Services\Validation\Rules\PasswordCorrectRule; |
||||
| 8 | use App\Services\Validation\Rules\PasswordFormatRule; |
||||
| 9 | use Facades\App\Services\WhichPortal; |
||||
| 10 | use Illuminate\Http\Request; |
||||
| 11 | use Illuminate\Support\Facades\Auth; |
||||
| 12 | use Illuminate\Support\Facades\Hash; |
||||
| 13 | use Illuminate\Support\Facades\Lang; |
||||
| 14 | use Illuminate\Validation\Rule; |
||||
| 15 | |||||
| 16 | class SettingsController extends Controller |
||||
| 17 | { |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * Show the form for editing the logged-in User's settings |
||||
| 21 | * |
||||
| 22 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 23 | * @return \Illuminate\Http\Response |
||||
| 24 | */ |
||||
| 25 | public function editAuthenticated(Request $request) |
||||
| 26 | { |
||||
| 27 | return $this->edit($request, $request->user()); |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Display the specified resource. |
||||
| 33 | * |
||||
| 34 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 35 | * @param \App\Models\User $user Incoming User. |
||||
| 36 | * @return \Illuminate\Http\Response |
||||
| 37 | */ |
||||
| 38 | public function edit(Request $request, User $user) |
||||
| 39 | { |
||||
| 40 | $this->authorize('view', $user); |
||||
| 41 | $this->authorize('update', $user); |
||||
| 42 | |||||
| 43 | $data = [ |
||||
| 44 | // Localized strings. |
||||
| 45 | 'settings' => Lang::get('common/settings'), |
||||
| 46 | // Applicant data. |
||||
| 47 | 'user' => $user, |
||||
| 48 | // Update routes. |
||||
| 49 | 'submit_personal' => route(WhichPortal::prefixRoute('settings.personal.update'), $user), |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 50 | 'submit_password' => route(WhichPortal::prefixRoute('settings.password.update'), $user), |
||||
| 51 | 'submit_government' => route(WhichPortal::prefixRoute('settings.government.update'), $user), |
||||
| 52 | 'submit_contact_preferences' => route(WhichPortal::prefixRoute('settings.contact_preferences.update'), $user), |
||||
| 53 | 'submit_delete' => route('settings.account.delete', $user), |
||||
| 54 | 'activate_two_factor' => route(WhichPortal::prefixRoute('two_factor.activate')), |
||||
| 55 | 'deactivate_two_factor' => route(WhichPortal::prefixRoute('two_factor.deactivate')), |
||||
| 56 | 'forget_remembered_devices' => route(WhichPortal::prefixRoute('two_factor.forget')), |
||||
| 57 | 'generate_recovery_codes' => route(WhichPortal::prefixRoute('recovery_codes.show')) |
||||
| 58 | ]; |
||||
| 59 | |||||
| 60 | return view( |
||||
|
0 ignored issues
–
show
The function
view was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 61 | 'common/settings', |
||||
| 62 | $data |
||||
| 63 | ); |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | /** |
||||
| 67 | * Update personal information |
||||
| 68 | * |
||||
| 69 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 70 | * @param \App\Models\User $user Incoming User. |
||||
| 71 | * @return \Illuminate\Http\Response |
||||
| 72 | */ |
||||
| 73 | public function updatePersonal(Request $request, User $user) |
||||
| 74 | { |
||||
| 75 | $validData = $request->validate([ |
||||
| 76 | 'first_name' => 'required|string|max:191', |
||||
| 77 | 'last_name' => 'required|string|max:191', |
||||
| 78 | 'email' => [ |
||||
| 79 | 'required', |
||||
| 80 | 'email:rfc', |
||||
| 81 | 'max:191', |
||||
| 82 | // Email may match existing email for this user, must be unique if changed. |
||||
| 83 | Rule::unique('users', 'email')->ignore($user->id) |
||||
| 84 | ] |
||||
| 85 | ]); |
||||
| 86 | |||||
| 87 | if ($validData) { |
||||
| 88 | $user->update([ |
||||
| 89 | 'first_name' => $validData['first_name'], |
||||
| 90 | 'last_name' => $validData['last_name'], |
||||
| 91 | 'email' => $validData['email'], |
||||
| 92 | ]); |
||||
| 93 | } |
||||
| 94 | |||||
| 95 | return redirect()->route(WhichPortal::prefixRoute('settings.edit'))->withSuccess(Lang::get('success.update_personal')); |
||||
|
0 ignored issues
–
show
The function
redirect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 96 | } |
||||
| 97 | |||||
| 98 | /** |
||||
| 99 | * Update password. |
||||
| 100 | * |
||||
| 101 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 102 | * @param \App\Models\User $user Incoming User. |
||||
| 103 | * @return \Illuminate\Http\Response |
||||
| 104 | */ |
||||
| 105 | public function updatePassword(Request $request, User $user) |
||||
| 106 | { |
||||
| 107 | $validData = $request->validate([ |
||||
| 108 | 'current_password' => ['required', new PasswordCorrectRule], |
||||
| 109 | 'new_password' => ['required', 'min:9', 'max:100', new PasswordFormatRule], |
||||
| 110 | 'new_confirm_password' => ['required', 'same:new_password'] |
||||
| 111 | ]); |
||||
| 112 | |||||
| 113 | if ($validData) { |
||||
| 114 | $user->update(['password' => Hash::make($validData['new_password'])]); |
||||
| 115 | } |
||||
| 116 | |||||
| 117 | return redirect()->route(WhichPortal::prefixRoute('settings.edit'))->withSuccess(Lang::get('success.update_password')); |
||||
|
0 ignored issues
–
show
The function
redirect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 118 | } |
||||
| 119 | |||||
| 120 | /** |
||||
| 121 | * Update government information. |
||||
| 122 | * |
||||
| 123 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 124 | * @param \App\Models\User $user Incoming User. |
||||
| 125 | * @return \Illuminate\Http\Response |
||||
| 126 | */ |
||||
| 127 | public function updateGovernment(Request $request, User $user) |
||||
| 128 | { |
||||
| 129 | $validData = $request->validate([ |
||||
| 130 | 'gov_email' => 'nullable|required_unless:department,0|email:rfc|max:191', |
||||
| 131 | Rule::unique('users', 'gov_email')->ignore($user->id) |
||||
| 132 | ]); |
||||
| 133 | |||||
| 134 | if ($validData) { |
||||
| 135 | $user->update(['gov_email' => $validData['gov_email']]); |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | return redirect()->route(WhichPortal::prefixRoute('settings.edit'))->withSuccess(Lang::get('success.update_government')); |
||||
|
0 ignored issues
–
show
The function
redirect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 139 | } |
||||
| 140 | |||||
| 141 | /** |
||||
| 142 | * Update contact information. |
||||
| 143 | * |
||||
| 144 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 145 | * @param \App\Models\User $user Incoming User. |
||||
| 146 | * @return \Illuminate\Http\Response |
||||
| 147 | */ |
||||
| 148 | public function updateContactPreferences(Request $request, User $user) |
||||
| 149 | { |
||||
| 150 | $validData = $request->validate([ |
||||
| 151 | 'contact_language' => [ |
||||
| 152 | 'required', |
||||
| 153 | 'string', |
||||
| 154 | Rule::in(['en', 'fr']), |
||||
| 155 | ], |
||||
| 156 | 'job_alerts' => 'boolean|in:0,1', |
||||
| 157 | ]); |
||||
| 158 | |||||
| 159 | if ($validData) { |
||||
| 160 | $user->update(['contact_language' => $validData['contact_language']]); |
||||
| 161 | $user->update(['job_alerts' => $validData['job_alerts']]); |
||||
| 162 | } |
||||
| 163 | |||||
| 164 | return redirect()->route(WhichPortal::prefixRoute('settings.edit'))->withSuccess(Lang::get('success.update_contact_preferences')); |
||||
|
0 ignored issues
–
show
The function
redirect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 165 | } |
||||
| 166 | |||||
| 167 | /** |
||||
| 168 | * Delete (soft) applicant account. |
||||
| 169 | * |
||||
| 170 | * @param \Illuminate\Http\Request $request Incoming request. |
||||
| 171 | * @param \App\Models\User $user Incoming User. |
||||
| 172 | * @return \Illuminate\Http\Response |
||||
| 173 | */ |
||||
| 174 | public function deleteAccount(Request $request, User $user) |
||||
| 175 | { |
||||
| 176 | $user = Auth::user(); |
||||
| 177 | |||||
| 178 | $validData = $request->validate([ |
||||
| 179 | 'confirm_delete' => ['required'] |
||||
| 180 | ]); |
||||
| 181 | |||||
| 182 | if ($validData) { |
||||
| 183 | Auth::logout(); |
||||
| 184 | |||||
| 185 | User::where('id', $user->id)->update([ |
||||
| 186 | 'first_name' => 'DELETED', |
||||
| 187 | 'last_name' => 'DELETED', |
||||
| 188 | 'email' => 'DELETED' . rand(7777777, 88888888), |
||||
| 189 | ]); |
||||
| 190 | } |
||||
| 191 | |||||
| 192 | return redirect()->route('home')->withSuccess(Lang::get('success.delete_account')); |
||||
|
0 ignored issues
–
show
The function
redirect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 193 | } |
||||
| 194 | } |
||||
| 195 |