|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services\Validation\Requests; |
|
4
|
|
|
|
|
5
|
|
|
use App\Services\Validation\BaseDataValidator; |
|
6
|
|
|
use App\Services\Validation\Contracts\DataValidator; |
|
7
|
|
|
use App\Models\Applicant; |
|
8
|
|
|
use Illuminate\Validation\Rule; |
|
9
|
|
|
use Illuminate\Support\Facades\Validator; |
|
10
|
|
|
use App\Services\Validation\Rules\PasswordCorrectRule; |
|
11
|
|
|
use App\Services\Validation\Rules\PasswordFormatRule; |
|
12
|
|
|
|
|
13
|
|
|
class UpdateApplicationProfileValidator extends BaseDataValidator implements DataValidator |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The Applicant this application is indented to belong to |
|
17
|
|
|
* |
|
18
|
|
|
* @var Applicant |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $applicant; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Construct a validator for Update Application Profile form. |
|
24
|
|
|
* |
|
25
|
|
|
* @param Applicant $applicant The applicant this profile is intended to belong to. |
|
26
|
|
|
*/ |
|
27
|
9 |
|
public function __construct(Applicant $applicant) |
|
28
|
|
|
{ |
|
29
|
9 |
|
$this->applicant = $applicant; |
|
30
|
9 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Get the validation rules that apply to the request. |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed[] |
|
36
|
|
|
*/ |
|
37
|
9 |
|
public function rules() : array |
|
38
|
|
|
{ |
|
39
|
|
|
return [ |
|
40
|
|
|
// Name validation |
|
41
|
9 |
|
'profile_name' => 'required|string|max:191', |
|
42
|
|
|
|
|
43
|
|
|
// Email validation |
|
44
|
|
|
'profile_email' => [ |
|
45
|
9 |
|
'required', |
|
46
|
9 |
|
'string', |
|
47
|
9 |
|
'max:191', |
|
48
|
9 |
|
'email', |
|
49
|
|
|
// Email may match existing email for this user, |
|
50
|
|
|
// but must be unique if changed. |
|
51
|
9 |
|
Rule::unique('users', 'email')->ignore($this->applicant->user->id) |
|
52
|
|
|
], |
|
53
|
|
|
|
|
54
|
|
|
//Password validation |
|
55
|
|
|
'old_password' => [ |
|
56
|
9 |
|
'nullable', |
|
57
|
9 |
|
'required_with:new_password', |
|
58
|
9 |
|
new PasswordCorrectRule |
|
59
|
|
|
], |
|
60
|
|
|
'new_password' => [ |
|
61
|
9 |
|
'nullable', |
|
62
|
9 |
|
'min:8', |
|
63
|
9 |
|
new PasswordFormatRule, |
|
64
|
9 |
|
'confirmed' |
|
65
|
|
|
], |
|
66
|
|
|
|
|
67
|
|
|
//Social Media Validation |
|
68
|
|
|
/* |
|
69
|
|
|
* Twitters Terms of Service only allows ". A username can only contain |
|
70
|
|
|
* alphanumeric characters (letters A-Z, numbers 0-9) with the exception |
|
71
|
|
|
* of underscores" |
|
72
|
|
|
* This regex will allow only alphamumeric characters and the underscore. |
|
73
|
|
|
* Keep this handy if we need to validate other usernames. |
|
74
|
|
|
*/ |
|
75
|
|
|
'twitter_username' => [ |
|
76
|
|
|
'nullable', //Some people may not have a handle. |
|
77
|
|
|
'max:15', //Per Twitter's Terms/Service. |
|
78
|
|
|
'regex:/^[A-Za-z0-9_]+$/', |
|
79
|
|
|
], |
|
80
|
|
|
'linkedin_url' => [ |
|
81
|
|
|
'nullable', // Some people may not be on LinkedIn |
|
82
|
|
|
'regex:/^(https:\\/\\/|http:\\/\\/)?www\\.linkedin\\.com\\/in\\/[^\\/]+(\\/)?$/', // Validation for linkedIn profile URLS only. |
|
83
|
|
|
], |
|
84
|
|
|
|
|
85
|
|
|
//Other Information Tagline |
|
86
|
|
|
'tagline' => [ |
|
87
|
|
|
'nullable', |
|
88
|
|
|
'string' |
|
89
|
|
|
], |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns a validator made with this data |
|
95
|
|
|
* |
|
96
|
|
|
* @param mixed[] $data Data to validate. |
|
97
|
|
|
* @return Validator |
|
98
|
|
|
*/ |
|
99
|
9 |
|
public function validator(array $data) : \Illuminate\Validation\Validator |
|
100
|
|
|
{ |
|
101
|
9 |
|
return Validator::make($data, $this->rules()); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|