1<?php
2
3namespace Illuminate\Foundation\Auth;
4
5use Illuminate\Auth\Events\Verified;
6use Illuminate\Foundation\Http\FormRequest;
7
8class 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        if (! $this->user()->hasVerifiedEmail()) {
50            $this->user()->markEmailAsVerified();
51
52            event(new Verified($this->user()));
53        }
54    }
55
56    /**
57     * Configure the validator instance.
58     *
59     * @param  \Illuminate\Validation\Validator  $validator
60     * @return void
61     */
62    public function withValidator($validator)
63    {
64        return $validator;
65    }
66}
67