Skip to content

Commit 4bde31b

Browse files
committed
add form request helper for email verification
1 parent de811ea commit 4bde31b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Auth;
4+
5+
use Illuminate\Auth\Events\Verified;
6+
use Illuminate\Foundation\Http\FormRequest;
7+
8+
class EmailVerificationRequest extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*
13+
* @return bool
14+
*/
15+
public function authorize()
16+
{
17+
if (! hash_equals((string) $this->route('id'),
18+
(string) $this->user()->getKey())) {
19+
return false;
20+
}
21+
22+
if (! hash_equals((string) $this->route('hash'),
23+
sha1($this->user()->getEmailForVerification()))) {
24+
return false;
25+
}
26+
27+
return true;
28+
}
29+
30+
/**
31+
* Get the validation rules that apply to the request.
32+
*
33+
* @return array
34+
*/
35+
public function rules()
36+
{
37+
return [
38+
//
39+
];
40+
}
41+
42+
/**
43+
* Fulfill the email verification request.
44+
*
45+
* @return void
46+
*/
47+
public function fulfill()
48+
{
49+
$this->user()->markEmailAsVerified();
50+
51+
event(new Verified($this->user()));
52+
}
53+
54+
/**
55+
* Configure the validator instance.
56+
*
57+
* @param \Illuminate\Validation\Validator $validator
58+
* @return void
59+
*/
60+
public function withValidator($validator)
61+
{
62+
return $validator;
63+
}
64+
}

0 commit comments

Comments
 (0)