Passed
Push — dev5 ( 236dfc...16c2ad )
by Ron
07:50
created

SettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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