|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Installer; |
|
4
|
|
|
|
|
5
|
|
|
use App\User; |
|
6
|
|
|
use App\Settings; |
|
7
|
|
|
use Carbon\Carbon; |
|
8
|
|
|
use App\Mail\TestEmail; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use Illuminate\Support\Facades\Log; |
|
11
|
|
|
use Illuminate\Support\Facades\Auth; |
|
12
|
|
|
use Illuminate\Support\Facades\Mail; |
|
13
|
|
|
use App\Http\Controllers\Controller; |
|
14
|
|
|
use Illuminate\Support\Facades\Route; |
|
15
|
|
|
use Illuminate\Support\Facades\Config; |
|
16
|
|
|
|
|
17
|
|
|
class SettingsController extends Controller |
|
18
|
|
|
{ |
|
19
|
12 |
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
12 |
|
$this->middleware(['auth', 'can:is_installer']); |
|
22
|
12 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
// Bring up the change logo form |
|
25
|
2 |
|
public function logoSettings() |
|
26
|
|
|
{ |
|
27
|
2 |
|
return view('installer.logoSettings'); |
|
28
|
|
|
} |
|
29
|
|
|
// Submit the new company logo |
|
30
|
2 |
|
public function submitLogo(Request $request) |
|
31
|
|
|
{ |
|
32
|
2 |
|
$request->validate([ |
|
33
|
2 |
|
'file' => 'mimes:jpeg,bmp,png,jpg,gif' |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
2 |
|
$file = $request->file; |
|
37
|
2 |
|
$fileName = $file->getClientOriginalName(); |
|
38
|
2 |
|
$file->storeAs('img', $fileName, 'public'); |
|
39
|
|
|
|
|
40
|
2 |
|
Settings::where('key', 'app.logo')->update([ |
|
41
|
2 |
|
'value' => '/storage/img/' . $fileName |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
2 |
|
Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id); |
|
45
|
2 |
|
Log::debug('Submitted Data - ', $request->toArray()); |
|
46
|
2 |
|
Log::notice('A new company logo has been uploaded by User ID-' . Auth::user()->user_id); |
|
47
|
|
|
|
|
48
|
2 |
|
return response()->json(['url' => '/storage/img/' . $fileName]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
// Timezone and Logo forms |
|
64
|
|
|
public function customizeSystem() |
|
65
|
|
|
{ |
|
66
|
|
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
67
|
|
|
return view('installer.customize'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// Submit the timezone form |
|
71
|
|
|
public function submitCustomizeSystem(Request $request) |
|
72
|
|
|
{ |
|
73
|
|
|
$request->validate([ |
|
74
|
|
|
'timezone' => 'required' |
|
75
|
|
|
]); |
|
76
|
|
|
|
|
77
|
|
|
Settings::where('key', 'app.timezone')->update([ |
|
78
|
|
|
'value' => $request->timezone |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
82
|
|
|
Log::debug('Submitted Data - ', $request->toArray()); |
|
83
|
|
|
Log::notice('Tech Bench Settings Updated', ['user_id' => Auth::user()->user_id]); |
|
84
|
|
|
|
|
85
|
|
|
return redirect()->back()->with('success', 'Timezone Successfully Updated'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
// Email Settings form |
|
91
|
|
|
public function emailSettings() |
|
92
|
|
|
{ |
|
93
|
|
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
94
|
|
|
return view('installer.emailSettings'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Send a test email |
|
98
|
|
|
public function sendTestEmail(Request $request) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
// to be added |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// Submit the test email form |
|
104
|
|
|
public function submitEmailSettings(Request $request) |
|
105
|
|
|
{ |
|
106
|
|
|
$request->validate([ |
|
107
|
|
|
'host' => 'required', |
|
108
|
|
|
'port' => 'required|numeric', |
|
109
|
|
|
'encryption' => 'required', |
|
110
|
|
|
'username' => 'required' |
|
111
|
|
|
]); |
|
112
|
|
|
|
|
113
|
|
|
// Update each setting |
|
114
|
|
|
Settings::where('key', 'mail.host')->update(['value' => $request->host]); |
|
115
|
|
|
Settings::where('key', 'mail.port')->update(['value' => $request->port]); |
|
116
|
|
|
Settings::where('key', 'mail.encryption')->update(['value' => $request->encryption]); |
|
117
|
|
|
Settings::where('key', 'mail.username')->update(['value' => $request->username]); |
|
118
|
|
|
if(!empty($request->password)) |
|
119
|
|
|
{ |
|
120
|
|
|
Settings::where('key', 'mail.password')->update(['value' => $request->password]); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
124
|
|
|
Log::debug('Submitted Data - ', $request->toArray()); |
|
125
|
|
|
Log::notice('Email Settings have been changed by User ID-'.Auth::user()->user_id); |
|
126
|
|
|
return redirect()->back()->with('success', 'Tech Bench Successfully Updated'); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.