Passed
Branch dev5a (c41270)
by Ron
12:51
created

UserController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Log;
7
use App\Domains\Roles\GetRoles;
8
use App\Domains\User\GetUserDetails;
9
use App\Domains\User\SetUserDetails;
10
use App\Http\Controllers\Controller;
11
use App\Http\Requests\Admin\NewUserRequest;
12
use Illuminate\Http\Request;
13
14
class UserController extends Controller
15
{
16
    //  Check if a username is in use
17 4
    public function checkUser($username, $type)
18
    {
19 4
        $user = (new GetUserDetails)->checkForDuplicate($type, $username);
20
21 4
        if(!$user)
22
        {
23 2
            return response()->json(['duplicate' => false]);
24
        }
25
26 2
        return response()->json([
27 2
            'duplicate' => true,
28 2
            'user'      => $user->full_name,
29 2
            'username'  => $user->username,
30 2
            'active'    => $user->deleted_at == null ? 1 : 0,
31
        ]);
32
    }
33
34
    //  Show the add user form
35 2
    public function create()
36
    {
37 2
        return view('admin.newUser', [
38 2
            'roles' => (new GetRoles)->getRoleList()->makeHidden('allow_edit'),
39
        ]);
40
    }
41
42
    //  Submit the add user form
43 2
    public function store(NewUserRequest $request)
44
    {
45 2
        $newID = (new SetUserDetails)->createUser($request);
46 2
        Log::notice('New user created by '.Auth::user()->full_name.'. New User ID - '.$newID.'. User Data - ', $request->toArray());
47
48 2
        return response()->json(['success' => true]);
49
    }
50
}
51