Passed
Push — dev5 ( 846a42...455ff1 )
by Ron
07:21
created

SettingsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 36.17%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 41
dl 0
loc 110
ccs 17
cts 47
cp 0.3617
rs 10
c 1
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A submitLogo() 0 19 1
A submitEmailSettings() 0 23 2
A submitCustomizeSystem() 0 15 1
A customizeSystem() 0 4 1
A logoSettings() 0 3 1
A emailSettings() 0 4 1
A __construct() 0 3 1
A sendTestEmail() 0 2 1
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

98
    public function sendTestEmail(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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