|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services\Validation; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Validator; |
|
6
|
|
|
use App\Services\Validation\Rules\PasswordFormatRule; |
|
7
|
|
|
|
|
8
|
|
|
class RegistrationValidator |
|
9
|
|
|
{ |
|
10
|
|
|
public static function basicRules() |
|
11
|
|
|
{ |
|
12
|
|
|
return [ |
|
13
|
|
|
'first_name' => 'required|string|max:255', |
|
14
|
|
|
'last_name' => 'required|string|max:255', |
|
15
|
|
|
'email' => 'required|string|email|max:255|unique:users', |
|
16
|
|
|
'password' => [ |
|
17
|
|
|
'required', |
|
18
|
|
|
'min:8', |
|
19
|
|
|
new PasswordFormatRule, |
|
20
|
|
|
'confirmed' |
|
21
|
|
|
], |
|
22
|
|
|
]; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public static function managerRegistrationExtraRules() |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
'department' => 'required|integer', |
|
29
|
|
|
'gov_email' => 'nullable|required_unless:department,0|string|email|unique:users', // gov_email is required unless department is set to 0 (Not in Goverment) |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get a validator for an incoming registration request. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $data Incoming registration data. |
|
|
|
|
|
|
37
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function userValidator(array $data) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
return Validator::make($data, self::basicRules()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get a validator for an incoming Manager registration request. |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $data Incoming registration data. |
|
|
|
|
|
|
48
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function managerValidator(array $data) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$managerRules = array_merge(self::basicRules(), self::managerRegistrationExtraRules()); |
|
53
|
|
|
return Validator::make($data, $managerRules); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get a validator for an incoming finishManagerRegistration request. |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $data Incoming registration data. |
|
|
|
|
|
|
60
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function finalizeManagerValidator(array $data) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
return Validator::make($data, self::managerRegistrationExtraRules()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get a validator for an incoming HR Advisor registration request. |
|
69
|
|
|
* |
|
70
|
|
|
* @param array $data Incoming registration data. |
|
|
|
|
|
|
71
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function hrValidator(array $data) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
$hrRules = array_merge(self::basicRules(), self::managerRegistrationExtraRules()); |
|
76
|
|
|
return Validator::make($data, $hrRules); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get a validator for an incoming finishHrRegistration request. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $data Incoming registration data. |
|
|
|
|
|
|
83
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function finalizeHrValidator(array $data) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return Validator::make($data, self::managerRegistrationExtraRules()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|