source: app/Http/Controllers/Dashboard/SettingsController.php@ 4521f25

Last change on this file since 4521f25 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
RevLine 
[194a359]1<?php
2
3namespace App\Http\Controllers\Dashboard;
4
[e6c1f87]5use App\Helpers\Alert;
[194a359]6use App\Http\Requests\Dashboard\EmailSettingsRequest;
[c6b84df]7use App\Http\Requests\Dashboard\FileTypeRequest;
[194a359]8use App\Http\Requests\Dashboard\PasswordSettingsRequest;
9use App\Http\Requests\Dashboard\UsernameSettingsRequest;
[c6b84df]10use App\Models\FileType;
[194a359]11use App\Models\User;
12use App\Http\Controllers\Controller;
13use App\Notifications\VerifyNewEmail;
[d795fa6]14use Carbon\Carbon;
[e6c1f87]15use Illuminate\Contracts\Validation\Validator;
16use Illuminate\Http\Request;
17use Illuminate\Validation\ValidationException;
[194a359]18
19class SettingsController extends Controller
20{
21 public function settings()
22 {
[c6b84df]23 $fileType = FileType::find("1");
24
[194a359]25 return view("dashboard.settings.index")->with([
26 "user" => auth()->user(),
[e6c1f87]27 "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
[c6b84df]28 "active_tab" => "account",
29 "fileType" => $fileType
[194a359]30 ]);
31 }
32
33 public function updateUsername(UsernameSettingsRequest $request)
34 {
[bd9e8e3]35 $user = auth()->user();
36 $user->username = $request->username;
[c6b84df]37 $user->updated_at = Carbon::now();
[bd9e8e3]38 $user->save();
39
40 auth()->logout();
41 session()->flush();
42
43 return redirect()->route("auth.loginShow");
[194a359]44 }
45
[e6c1f87]46 public function updatePassword(UsernameSettingsRequest $request)
[194a359]47 {
[e6c1f87]48 $user = auth()->user();
49 $user->password = bcrypt($request->password);
[c6b84df]50 $user->updated_at = Carbon::now();
[e6c1f87]51 $user->save();
[194a359]52
[e6c1f87]53 auth()->logout();
54 session()->flush();
[194a359]55
[e6c1f87]56 return redirect()->route("auth.loginShow");
[194a359]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();
[c6b84df]67 $user->updated_at = Carbon::now();
[194a359]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
[c6b84df]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
[194a359]102}
Note: See TracBrowser for help on using the repository browser.