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 | $fileType = FileType::find("1");
|
---|
24 |
|
---|
25 | return view("dashboard.settings.index")->with([
|
---|
26 | "user" => auth()->user(),
|
---|
27 | "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
|
---|
28 | "active_tab" => "account",
|
---|
29 | "fileType" => $fileType
|
---|
30 | ]);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public function updateUsername(UsernameSettingsRequest $request)
|
---|
34 | {
|
---|
35 | $user = auth()->user();
|
---|
36 | $user->username = $request->username;
|
---|
37 | $user->updated_at = Carbon::now();
|
---|
38 | $user->save();
|
---|
39 |
|
---|
40 | auth()->logout();
|
---|
41 | session()->flush();
|
---|
42 |
|
---|
43 | return redirect()->route("auth.loginShow");
|
---|
44 | }
|
---|
45 |
|
---|
46 | public function updatePassword(UsernameSettingsRequest $request)
|
---|
47 | {
|
---|
48 | $user = auth()->user();
|
---|
49 | $user->password = bcrypt($request->password);
|
---|
50 | $user->updated_at = Carbon::now();
|
---|
51 | $user->save();
|
---|
52 |
|
---|
53 | auth()->logout();
|
---|
54 | session()->flush();
|
---|
55 |
|
---|
56 | return redirect()->route("auth.loginShow");
|
---|
57 | }
|
---|
58 |
|
---|
59 | public function updateEmail(EmailSettingsRequest $request)
|
---|
60 | {
|
---|
61 | $user = auth()->user();
|
---|
62 |
|
---|
63 | $user->email = $request->email;
|
---|
64 | $user->is_active = false;
|
---|
65 | $user->security_code = $user->generateSecurityCode();
|
---|
66 | $user->verify_token = $user->generateVerifyToken();
|
---|
67 | $user->updated_at = Carbon::now();
|
---|
68 |
|
---|
69 | $user->save();
|
---|
70 |
|
---|
71 | $user->notify(new VerifyNewEmail($user));
|
---|
72 |
|
---|
73 | auth()->logout();
|
---|
74 | session()->flush();
|
---|
75 |
|
---|
76 | return redirect()->route("auth.loginShow");
|
---|
77 | }
|
---|
78 |
|
---|
79 | public function fileTypes(FileTypeRequest $request)
|
---|
80 | {
|
---|
81 | $fileType = FileType::find("1");
|
---|
82 |
|
---|
83 | $fileType->mimes = $request->mimes;
|
---|
84 | $fileType->max_size = $request->max_size;
|
---|
85 | $fileType->user_id = auth()->id();
|
---|
86 | $fileType->updated_at = Carbon::now();
|
---|
87 |
|
---|
88 | if(auth()->user()->hasPermission("manage_file_types")) {
|
---|
89 | $fileType->save();
|
---|
90 |
|
---|
91 | Alert::flash("File validations updated successfully");
|
---|
92 |
|
---|
93 | return redirect()->back();
|
---|
94 | }
|
---|
95 | else {
|
---|
96 | Alert::flash("You don't have permission to change file validations", "error");
|
---|
97 |
|
---|
98 | return redirect()->back();
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | }
|
---|