|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Http\Controllers\Frontend; |
|
17
|
|
|
|
|
18
|
|
|
use Rinvex\Fort\Http\Controllers\AbstractController; |
|
19
|
|
|
use Rinvex\Fort\Contracts\VerificationBrokerContract; |
|
20
|
|
|
use Rinvex\Fort\Http\Requests\Frontend\EmailVerification; |
|
21
|
|
|
|
|
22
|
|
|
class EmailVerificationController extends AbstractController |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Show the email verification request form. |
|
26
|
|
|
* |
|
27
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
public function request() |
|
30
|
|
|
{ |
|
31
|
|
|
return view('rinvex.fort::frontend.verification.email.request'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Process the email verification request form. |
|
36
|
|
|
* |
|
37
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\EmailVerification $request |
|
38
|
|
|
* |
|
39
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
40
|
|
|
*/ |
|
41
|
|
|
public function send(EmailVerification $request) |
|
42
|
|
|
{ |
|
43
|
|
|
$result = app('rinvex.fort.verifier') |
|
44
|
|
|
->broker($this->getBroker()) |
|
45
|
|
|
->sendVerificationLink($request->except('_token')); |
|
46
|
|
|
|
|
47
|
|
|
switch ($result) { |
|
48
|
|
|
case VerificationBrokerContract::LINK_SENT: |
|
49
|
|
|
return intend([ |
|
50
|
|
|
'intended' => url('/'), |
|
51
|
|
|
'with' => ['rinvex.fort.alert.success' => trans($result)], |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
|
|
default: |
|
55
|
|
|
return intend([ |
|
56
|
|
|
'back' => true, |
|
57
|
|
|
'withInput' => $request->only('email'), |
|
58
|
|
|
'withErrors' => ['email' => trans($result)], |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Process the email verification. |
|
65
|
|
|
* |
|
66
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\EmailVerification $request |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
69
|
|
|
*/ |
|
70
|
|
|
public function verify(EmailVerification $request) |
|
71
|
|
|
{ |
|
72
|
|
|
$result = app('rinvex.fort.verifier')->broker($this->getBroker())->verify($request->except('_token')); |
|
73
|
|
|
|
|
74
|
|
|
switch ($result) { |
|
75
|
|
|
case VerificationBrokerContract::EMAIL_VERIFIED: |
|
76
|
|
|
return intend([ |
|
77
|
|
|
'intended' => url('/'), |
|
78
|
|
|
'with' => ['rinvex.fort.alert.success' => trans($result)], |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
case VerificationBrokerContract::INVALID_USER: |
|
82
|
|
|
case VerificationBrokerContract::INVALID_TOKEN: |
|
83
|
|
|
default: |
|
84
|
|
|
return intend([ |
|
85
|
|
|
'route' => 'rinvex.fort.frontend.verification.email.request', |
|
86
|
|
|
'withInput' => $request->only('email'), |
|
87
|
|
|
'withErrors' => ['token' => trans($result)], |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.