RegisteredUserController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 39
c 2
b 0
f 0
dl 0
loc 71
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A validateHandle() 0 11 2
B store() 0 50 6
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\User;
7
use App\Providers\RouteServiceProvider;
8
use Illuminate\Auth\Events\Registered;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Auth;
11
use Illuminate\Support\Facades\Hash;
12
use Illuminate\Support\Facades\DB;
13
use Illuminate\Support\Facades\Mail;
14
use Illuminate\Support\Facades\Validator;
15
16
class RegisteredUserController extends Controller
17
{
18
19
    public function create()
20
    {
21
        return view('auth.register');
22
    }
23
24
    public function validateHandle(Request $request)
25
    {
26
        $validator = Validator::make($request->all(), [
27
            'littlelink_name' => 'required|string|max:50|unique:users|regex:/^[\p{L}0-9-_]+$/u',
28
        ]);
29
    
30
        if ($validator->fails()) {
31
            return response()->json(['valid' => false]);
32
        }
33
    
34
        return response()->json(['valid' => true]);
35
    }
36
37
    public function store(Request $request)
38
    {
39
        $request->validate([
40
            'name' => 'required|string|max:255',
41
            'littlelink_name' => 'required|string|max:50|unique:users|regex:/^[\p{L}0-9-_]+$/u',
42
            'email' => 'required|string|email|max:255|unique:users',
43
            'password' => 'required|string|min:8',
44
        ]);
45
46
        $name = $request->input('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
47
48
        if(env('MANUAL_USER_VERIFICATION') == true){
49
            $block = 'yes';
50
        } else {
51
            $block = 'no';
52
        }
53
54
        Auth::login($user = User::create([
55
            'name' => $request->name,
56
            'email' => $request->email,
57
            'littlelink_name' => $request->littlelink_name,
58
            'password' => Hash::make($request->password),
59
            'role' => 'user',
60
        ]));
61
62
        $user->block = $block;
63
        $user->save();
64
65
66
            $user = $request->name;
67
            $email = $request->email;
68
            
69
            if(env('REGISTER_AUTH') == 'verified'){
70
                if(env('MANUAL_USER_VERIFICATION') == true){
71
                try {
72
                Mail::send('auth.user-confirmation', ['user' => $user, 'email' => $email], function ($message) use ($user) {
0 ignored issues
show
Unused Code introduced by
The import $user is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
73
                    $message->to(env('ADMIN_EMAIL'))
74
                            ->subject('New user registration');
75
                });
76
            } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
77
        }
78
    
79
            try {
80
            $request->user()->sendEmailVerificationNotification();
81
            } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
82
        }
83
84
        event(new Registered($user));
85
86
        return redirect(url('dashboard'));
87
    }
88
}
89