|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Auth\Http\Requests\Tenantarea; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
|
8
|
|
|
use Cortex\Foundation\Exceptions\GenericException; |
|
9
|
|
|
|
|
10
|
|
|
class PhoneVerificationRequest extends FormRequest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Determine if the user is authorized to make this request. |
|
14
|
|
|
* |
|
15
|
|
|
* @throws \Cortex\Foundation\Exceptions\GenericException |
|
16
|
|
|
* |
|
17
|
|
|
* @return bool |
|
18
|
|
|
*/ |
|
19
|
|
|
public function authorize(): bool |
|
20
|
|
|
{ |
|
21
|
|
|
$user = $this->user($this->route('guard')) |
|
22
|
|
|
?? $this->attemptUser($this->route('guard')) |
|
|
|
|
|
|
23
|
|
|
?? app('cortex.auth.member')->whereNotNull('phone')->where('phone', $this->get('phone'))->first(); |
|
24
|
|
|
|
|
25
|
|
|
// Redirect users if their phone already verified, no need to process their request |
|
26
|
|
|
if ($user && $user->hasVerifiedPhone()) { |
|
27
|
|
|
throw new GenericException(trans('cortex/auth::messages.verification.phone.already_verified'), route('tenantarea.account.settings')); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// Phone field required before verification |
|
31
|
|
|
if ($user && ! $user->phone) { |
|
32
|
|
|
throw new GenericException(trans('cortex/auth::messages.account.phone_required'), route('tenantarea.account.settings')); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Country field required for phone verification |
|
36
|
|
|
if ($user && ! $user->country_code) { |
|
37
|
|
|
throw new GenericException(trans('cortex/auth::messages.account.country_required'), route('tenantarea.account.settings')); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Email verification required for phone verification |
|
41
|
|
|
if ($user && ! $user->hasVerifiedPhone()) { |
|
42
|
|
|
throw new GenericException(trans('cortex/auth::messages.account.email_verification_required'), route('tenantarea.verification.email.request')); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the validation rules that apply to the request. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function rules(): array |
|
54
|
|
|
{ |
|
55
|
|
|
return []; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: