AccountVerificationController::store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.9666
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Support\Facades\Auth;
7
8
class AccountVerificationController extends Controller
9
{
10
    use SendsConfirmationEmails;
11
12
    /**
13
     * Where to redirect users after login.
14
     *
15
     * @var string
16
     */
17
    protected $redirectTo = '/';
18
19
    /**
20
     * Create a new controller instance.
21
     */
22
    public function __construct()
23
    {
24
        $this->middleware('auth');
25
        $this->middleware('can.student');
26
    }
27
28
    /**
29
     * Confirm an account.
30
     *
31
     * @param string $token
32
     *
33
     * @return \Illuminate\Http\RedirectResponse
34
     */
35
    public function store($token)
36
    {
37
        $user = Auth::user();
38
        if ($user->verification_token === $token) {
0 ignored issues
show
Bug introduced by
Accessing verification_token on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
            $user->verified = true;
0 ignored issues
show
Bug introduced by
Accessing verified on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
40
            $user->verification_token = null;
41
            $user->save();
42
            flash('Your account is now confirmed.')->success();
43
        } else {
44
            flash('Invalid account confirmation.')->error();
45
        }
46
47
        return redirect($this->redirectTo);
48
    }
49
50
    /**
51
     * Send account confirmation email.
52
     *
53
     * @return \Illuminate\Http\RedirectResponse
54
     */
55
    public function sendEmail()
56
    {
57
        if (Auth::user()->verified) {
0 ignored issues
show
Bug introduced by
Accessing verified on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
58
            flash('Your account is already confirmed.')->error();
59
        } else {
60
            $this->sendAccountConfirmationEmail(Auth::user());
61
            flash('A confirmation e-mail was sent. Please check your e-mail account.')->success();
62
        }
63
64
        return redirect($this->redirectTo);
65
    }
66
}
67