Passed
Push — develop ( 77087a...7447be )
by Francisco
03:37
created

AccountVerificationController::sendEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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
The property verification_token does not exist on boolean.
Loading history...
39
            $user->verified = true;
0 ignored issues
show
Bug introduced by
The property verified does not exist on boolean.
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
The property verified does not exist on boolean.
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