source: app/Http/Controllers/Dashboard/SettingsController.php@ c6b84df

develop
Last change on this file since c6b84df was c6b84df, checked in by beratkjufliju <kufliju@…>, 3 years ago

added fileTypes controller, notifications, excel export, edited views

  • Property mode set to 100644
File size: 2.8 KB
Line 
1<?php
2
3namespace App\Http\Controllers\Dashboard;
4
5use App\Helpers\Alert;
6use App\Http\Requests\Dashboard\EmailSettingsRequest;
7use App\Http\Requests\Dashboard\FileTypeRequest;
8use App\Http\Requests\Dashboard\PasswordSettingsRequest;
9use App\Http\Requests\Dashboard\UsernameSettingsRequest;
10use App\Models\FileType;
11use App\Models\User;
12use App\Http\Controllers\Controller;
13use App\Notifications\VerifyNewEmail;
14use Carbon\Carbon;
15use Illuminate\Contracts\Validation\Validator;
16use Illuminate\Http\Request;
17use Illuminate\Validation\ValidationException;
18
19class 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
80
81 public function fileTypes(FileTypeRequest $request)
82 {
83 $fileType = FileType::find("1");
84
85 $fileType->mimes = $request->mimes;
86 $fileType->max_size = $request->max_size;
87 $fileType->user_id = auth()->id();
88 $fileType->updated_at = Carbon::now();
89
90 if(auth()->user()->hasPermission("manage_file_types")) {
91 $fileType->save();
92
93 Alert::flash("File validations updated successfully");
94
95 return redirect()->back();
96 }
97 else {
98 Alert::flash("You don't have permission to change file validations", "error");
99
100 return redirect()->back();
101 }
102 }
103
104}
Note: See TracBrowser for help on using the repository browser.