source: app/Http/Controllers/Dashboard/SettingsController.php@ 79aa35c

Last change on this file since 79aa35c 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
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 {
23 return view("dashboard.settings.index")->with([
24 "user" => auth()->user(),
[c6b84df]25 "active_tab" => "account",
[0a1fb54]26 "fileType" => FileType::find("1")
[194a359]27 ]);
28 }
29
30 public function updateUsername(UsernameSettingsRequest $request)
31 {
[bd9e8e3]32 $user = auth()->user();
33 $user->username = $request->username;
[c6b84df]34 $user->updated_at = Carbon::now();
[bd9e8e3]35 $user->save();
36
[0a1fb54]37 Alert::flash("Username updated successfully");
38
[bd9e8e3]39 auth()->logout();
40 session()->flush();
41
[0a1fb54]42 return redirect()->route("auth.showLogin");
[194a359]43 }
44
[ec7b69d]45 public function updatePassword(PasswordSettingsRequest $request)
[194a359]46 {
[e6c1f87]47 $user = auth()->user();
48 $user->password = bcrypt($request->password);
[c6b84df]49 $user->updated_at = Carbon::now();
[e6c1f87]50 $user->save();
[194a359]51
[0a1fb54]52 Alert::flash("Password updated successfully");
53
[e6c1f87]54 auth()->logout();
55 session()->flush();
[194a359]56
[0a1fb54]57 return redirect()->route("auth.showLogin");
[194a359]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();
[c6b84df]68 $user->updated_at = Carbon::now();
[194a359]69
70 $user->save();
71
72 $user->notify(new VerifyNewEmail($user));
73
[0a1fb54]74 Alert::flash("Email updated successfully");
75
[194a359]76 auth()->logout();
77 session()->flush();
78
[0a1fb54]79 return redirect()->route("auth.showLogin");
[194a359]80 }
81
[c6b84df]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
[194a359]105}
Note: See TracBrowser for help on using the repository browser.