VerificationController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
c 0
b 0
f 0
dl 0
loc 63
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A validator() 0 4 1
A verify_user() 0 40 3
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Activation;
0 ignored issues
show
Bug introduced by
The type App\Activation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use App\Http\Controllers\Controller;
7
use App\Models\User;
8
use App\Providers\RouteServiceProvider;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Validator;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class VerificationController extends Controller
14
{
15
    // use VerifiesEmails;
16
17
    protected $redirectTo = RouteServiceProvider::HOME;
18
19
    public function __construct()
20
    {
21
        // $this->middleware('auth');
22
        // $this->middleware('signed')->only('verify');
23
        // $this->middleware('throttle:6,1')->only('verify', 'resend');
24
    }
25
26
    /**
27
     * verify user token.
28
     */
29
    public function verify_user(Request $request)
30
    {
31
        $token = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $token is dead and can be removed.
Loading history...
32
        $activation = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $activation is dead and can be removed.
Loading history...
33
        $user_id = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $user_id is dead and can be removed.
Loading history...
34
        $user = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
35
        $data = $request->all();
36
        $this->validator($data)->validate();
37
        $token = $request->get('token');
38
        $activation = Activation::where('token', $token)->first();
39
        if ($activation === null) {
40
            return response()->json(
41
                [
42
                    'error' => [
43
                        'code' => 300,
44
                        'message' => 'Send activation code again.',
45
                    ],
46
                ],
47
                Response::HTTP_UNPROCESSABLE_ENTITY
48
            );
49
        }
50
        $user_id = $activation->user_id;
51
        $user = User::find($user_id);
52
        if ($user === null) {
53
            return response()->json(
54
                [
55
                    'error' => [
56
                        'code' => 301,
57
                        'message' => 'There is not such user.',
58
                    ],
59
                ],
60
                Response::HTTP_UNPROCESSABLE_ENTITY
61
            );
62
        }
63
        $user->is_active = 1;
64
        $user->email_verified_at = date('Y-m-d H:i:s');
65
        $user->save();
66
        Activation::where('user_id', $user_id)->delete();
67
        return response()->json([
68
            'csrfToken' => csrf_token(),
69
        ]);
70
    }
71
72
    protected function validator(array $data)
73
    {
74
        return Validator::make($data, [
75
            'token' => ['required', 'string', 'max:255'],
76
        ]);
77
    }
78
}
79