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