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

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

bug fixes, edited export, added fileSeeder for DB testing

  • 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 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}
Note: See TracBrowser for help on using the repository browser.