|
1
|
|
|
<?php |
|
2
|
|
|
namespace Xetaravel\Models\Validators; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Support\Facades\App; |
|
5
|
|
|
use Illuminate\Support\Facades\Validator as FacadeValidator; |
|
6
|
|
|
use Illuminate\Validation\Validator; |
|
7
|
|
|
|
|
8
|
|
|
class UserValidator |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Get the validator for an incoming registration request. |
|
12
|
|
|
* |
|
13
|
|
|
* @param array $data The data to validate. |
|
14
|
|
|
* |
|
15
|
|
|
* @return \Illuminate\Validation\Validator |
|
16
|
|
|
*/ |
|
17
|
|
|
public static function create(array $data): Validator |
|
18
|
|
|
{ |
|
19
|
|
|
$rules = [ |
|
20
|
|
|
'username' => 'required|min:4|max:20|unique:users', |
|
21
|
|
|
'email' => 'required|email|max:50|unique:users', |
|
22
|
|
|
'password' => 'required|min:6|confirmed', |
|
23
|
|
|
'terms' => 'required|min:1' |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
// Bipass the captcha for the unit testing. |
|
27
|
|
|
if (App::environment() != 'testing') { |
|
28
|
|
|
$rules = array_merge($rules, ['g-recaptcha-response' => 'required|recaptcha']); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return FacadeValidator::make($data, $rules); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the validator for an incoming email update request. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $data The data to validate. |
|
38
|
|
|
* |
|
39
|
|
|
* @return \Illuminate\Validation\Validator |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function updateEmail(array $data): Validator |
|
42
|
|
|
{ |
|
43
|
|
|
$rules = [ |
|
44
|
|
|
'email' => 'required|email|max:50|unique:users' |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
return FacadeValidator::make($data, $rules); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the validator for an incoming password update request. |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $data The data to validate. |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Illuminate\Validation\Validator |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function updatePassword(array $data): Validator |
|
58
|
|
|
{ |
|
59
|
|
|
$rules = [ |
|
60
|
|
|
'oldpassword' => 'required', |
|
61
|
|
|
'password' => 'required|min:6|confirmed' |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
return FacadeValidator::make($data, $rules); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|