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

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

added confirmation modal on userSettings

  • Property mode set to 100644
File size: 2.9 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 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(PasswordSettingsRequest $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}
Note: See TracBrowser for help on using the repository browser.