1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Http\Controllers\Dashboard;
|
---|
4 |
|
---|
5 | use App\Helpers\Alert;
|
---|
6 | use App\Http\Requests\Dashboard\EmailSettingsRequest;
|
---|
7 | use App\Http\Requests\Dashboard\FileTypeRequest;
|
---|
8 | use App\Http\Requests\Dashboard\PasswordSettingsRequest;
|
---|
9 | use App\Http\Requests\Dashboard\UsernameSettingsRequest;
|
---|
10 | use App\Models\FileType;
|
---|
11 | use App\Models\User;
|
---|
12 | use App\Http\Controllers\Controller;
|
---|
13 | use App\Notifications\VerifyNewEmail;
|
---|
14 | use Carbon\Carbon;
|
---|
15 | use Illuminate\Contracts\Validation\Validator;
|
---|
16 | use Illuminate\Http\Request;
|
---|
17 | use Illuminate\Validation\ValidationException;
|
---|
18 |
|
---|
19 | class SettingsController extends Controller
|
---|
20 | {
|
---|
21 | public function settings()
|
---|
22 | {
|
---|
23 | return view("dashboard.settings.index")->with([
|
---|
24 | "user" => auth()->user(),
|
---|
25 | "active_tab" => "account",
|
---|
26 | "fileType" => FileType::find("1")
|
---|
27 | ]);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public function updateUsername(UsernameSettingsRequest $request)
|
---|
31 | {
|
---|
32 | $user = auth()->user();
|
---|
33 | $user->username = $request->username;
|
---|
34 | $user->updated_at = Carbon::now();
|
---|
35 | $user->save();
|
---|
36 |
|
---|
37 | Alert::flash("Username updated successfully");
|
---|
38 |
|
---|
39 | auth()->logout();
|
---|
40 | session()->flush();
|
---|
41 |
|
---|
42 | return redirect()->route("auth.showLogin");
|
---|
43 | }
|
---|
44 |
|
---|
45 | public function updatePassword(UsernameSettingsRequest $request)
|
---|
46 | {
|
---|
47 | $user = auth()->user();
|
---|
48 | $user->password = bcrypt($request->password);
|
---|
49 | $user->updated_at = Carbon::now();
|
---|
50 | $user->save();
|
---|
51 |
|
---|
52 | Alert::flash("Password updated successfully");
|
---|
53 |
|
---|
54 | auth()->logout();
|
---|
55 | session()->flush();
|
---|
56 |
|
---|
57 | return redirect()->route("auth.showLogin");
|
---|
58 | }
|
---|
59 |
|
---|
60 | public function updateEmail(EmailSettingsRequest $request)
|
---|
61 | {
|
---|
62 | $user = auth()->user();
|
---|
63 |
|
---|
64 | $user->email = $request->email;
|
---|
65 | $user->is_active = false;
|
---|
66 | $user->security_code = $user->generateSecurityCode();
|
---|
67 | $user->verify_token = $user->generateVerifyToken();
|
---|
68 | $user->updated_at = Carbon::now();
|
---|
69 |
|
---|
70 | $user->save();
|
---|
71 |
|
---|
72 | $user->notify(new VerifyNewEmail($user));
|
---|
73 |
|
---|
74 | Alert::flash("Email updated successfully");
|
---|
75 |
|
---|
76 | auth()->logout();
|
---|
77 | session()->flush();
|
---|
78 |
|
---|
79 | return redirect()->route("auth.showLogin");
|
---|
80 | }
|
---|
81 |
|
---|
82 | public function fileTypes(FileTypeRequest $request)
|
---|
83 | {
|
---|
84 | $fileType = FileType::find("1");
|
---|
85 |
|
---|
86 | $fileType->mimes = $request->mimes;
|
---|
87 | $fileType->max_size = $request->max_size;
|
---|
88 | $fileType->user_id = auth()->id();
|
---|
89 | $fileType->updated_at = Carbon::now();
|
---|
90 |
|
---|
91 | if(auth()->user()->hasPermission("manage_file_types")) {
|
---|
92 | $fileType->save();
|
---|
93 |
|
---|
94 | Alert::flash("File validations updated successfully");
|
---|
95 |
|
---|
96 | return redirect()->back();
|
---|
97 | }
|
---|
98 | else {
|
---|
99 | Alert::flash("You don't have permission to change file validations", "error");
|
---|
100 |
|
---|
101 | return redirect()->back();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|