1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Installer; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use App\Settings; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use Illuminate\Support\Facades\Log; |
10
|
|
|
use Illuminate\Support\Facades\Auth; |
11
|
|
|
use App\Http\Controllers\Controller; |
12
|
|
|
|
13
|
|
|
class SettingsController extends Controller |
14
|
|
|
{ |
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->middleware('auth'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// Bring up the user security settings form |
21
|
|
|
public function userSecurity() |
22
|
|
|
{ |
23
|
|
|
$passExpire = config('users.passExpires') != null ? config('users.passExpires') : 0; |
24
|
|
|
|
25
|
|
|
return view('installer.userSecurity', [ |
26
|
|
|
'passExpire' => $passExpire |
27
|
|
|
]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// Submit the user security settings form |
31
|
|
|
public function submitUserSecurity(Request $request) |
32
|
|
|
{ |
33
|
|
|
$request->validate([ |
34
|
|
|
'passExpire' => 'required|numeric' |
35
|
|
|
]); |
36
|
|
|
|
37
|
|
|
// Determine if the password expires field is updated |
38
|
|
|
$oldExpire = config('users.passExpires'); |
39
|
|
|
if($request->passExpire != $oldExpire) |
40
|
|
|
{ |
41
|
|
|
// Update the setting in the database |
42
|
|
|
Settings::where('key', 'users.passExpires')->update([ |
43
|
|
|
'value' => $request->passExpire |
44
|
|
|
]); |
45
|
|
|
// If the setting is changing from never to xx days, update all users |
46
|
|
|
if($request->passExpire == 0) |
47
|
|
|
{ |
48
|
|
|
User::whereNotNull('password_expires')->update([ |
49
|
|
|
'password_expires' => null |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
else |
53
|
|
|
{ |
54
|
|
|
$newExpire = Carbon::now()->addDays($request->passExpire); |
55
|
|
|
User::whereNull('password_expires')->update([ |
56
|
|
|
'password_expires' => $newExpire |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
Log::info('User Settings have been changed by User ID-'.Auth::user()->user_id); |
62
|
|
|
return redirect()->back()->with('success', 'User Security Updated'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|