[194a359] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Http\Controllers\Dashboard;
|
---|
| 4 |
|
---|
[e6c1f87] | 5 | use App\Helpers\Alert;
|
---|
[194a359] | 6 | use App\Http\Requests\Dashboard\EmailSettingsRequest;
|
---|
| 7 | use App\Http\Requests\Dashboard\PasswordSettingsRequest;
|
---|
| 8 | use App\Http\Requests\Dashboard\UsernameSettingsRequest;
|
---|
| 9 | use App\Models\User;
|
---|
| 10 | use App\Http\Controllers\Controller;
|
---|
| 11 | use App\Notifications\VerifyNewEmail;
|
---|
[d795fa6] | 12 | use Carbon\Carbon;
|
---|
[e6c1f87] | 13 | use Illuminate\Contracts\Validation\Validator;
|
---|
| 14 | use Illuminate\Http\Request;
|
---|
| 15 | use Illuminate\Validation\ValidationException;
|
---|
[194a359] | 16 |
|
---|
| 17 | class SettingsController extends Controller
|
---|
| 18 | {
|
---|
| 19 | public function settings()
|
---|
| 20 | {
|
---|
| 21 | return view("dashboard.settings.index")->with([
|
---|
| 22 | "user" => auth()->user(),
|
---|
[e6c1f87] | 23 | "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
|
---|
[bd9e8e3] | 24 | "active_tab" => "account"
|
---|
[194a359] | 25 | ]);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public function updateUsername(UsernameSettingsRequest $request)
|
---|
| 29 | {
|
---|
[bd9e8e3] | 30 | $user = auth()->user();
|
---|
| 31 | $user->username = $request->username;
|
---|
| 32 | $user->save();
|
---|
| 33 |
|
---|
| 34 | auth()->logout();
|
---|
| 35 | session()->flush();
|
---|
| 36 |
|
---|
| 37 | return redirect()->route("auth.loginShow");
|
---|
[194a359] | 38 | }
|
---|
| 39 |
|
---|
[e6c1f87] | 40 | public function updatePassword(UsernameSettingsRequest $request)
|
---|
[194a359] | 41 | {
|
---|
[e6c1f87] | 42 | $user = auth()->user();
|
---|
| 43 | $user->password = bcrypt($request->password);
|
---|
| 44 | $user->save();
|
---|
[194a359] | 45 |
|
---|
[e6c1f87] | 46 | auth()->logout();
|
---|
| 47 | session()->flush();
|
---|
[194a359] | 48 |
|
---|
[e6c1f87] | 49 | return redirect()->route("auth.loginShow");
|
---|
[194a359] | 50 | }
|
---|
| 51 |
|
---|
| 52 | public function updateEmail(EmailSettingsRequest $request)
|
---|
| 53 | {
|
---|
| 54 | $user = auth()->user();
|
---|
| 55 |
|
---|
| 56 | $user->email = $request->email;
|
---|
| 57 | $user->is_active = false;
|
---|
| 58 | $user->security_code = $user->generateSecurityCode();
|
---|
| 59 | $user->verify_token = $user->generateVerifyToken();
|
---|
| 60 |
|
---|
| 61 | $user->save();
|
---|
| 62 |
|
---|
| 63 | $user->notify(new VerifyNewEmail($user));
|
---|
| 64 |
|
---|
| 65 | auth()->logout();
|
---|
| 66 | session()->flush();
|
---|
| 67 |
|
---|
| 68 | return redirect()->route("auth.loginShow");
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | }
|
---|