-
Notifications
You must be signed in to change notification settings - Fork 2
/
EmailServiceRequest.php
136 lines (117 loc) · 4.88 KB
/
EmailServiceRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Sendportal\Base\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Sendportal\Base\Models\EmailServiceType;
class EmailServiceRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'name' => ['required']
];
if (!$this->route('id')) {
$rules['type_id'] = ['required', 'integer'];
}
return array_merge($rules, self::resolveValidationRules($this->input('type_id')));
}
/**
* Get the validation messages
*
* @return array
*/
public function messages()
{
switch ((int) $this->input('type_id')) {
case EmailServiceType::SES:
return [
'settings.key.required' => __('The AWS Email Service requires you to enter a key'),
'settings.secret.required' => __('The AWS Email Service requires you to enter a secret'),
'settings.region.required' => __('The AWS Email Service requires you to enter a region'),
'settings.configuration_set_name.required' => __('The AWS Email Service requires you to enter a configuration set name'),
];
case EmailServiceType::SENDGRID:
return [
'settings.key.required' => __('The Sendgrid Email Service requires you to enter a key'),
];
case EmailServiceType::POSTMARK:
return [
'settings.key.required' => __('The Postmark Email Service requires you to enter a key'),
];
case EmailServiceType::MAILGUN:
return [
'settings.key.required' => __('The Mailgun Email Service requires you to enter a key'),
'settings.domain.required' => __('The Mailgun Email Service requires you to enter a domain'),
'settings.zone.required' => __('The Mailgun Email Service requires you to enter a zone'),
];
case EmailServiceType::MAILJET:
return [
'settings.key.required' => __('The Mailjet Email Service requires you to enter a key'),
'settings.secret.required' => __('The Mailgun Email Service requires you to enter a secret'),
'settings.zone.required' => __('The Mailgun Email Service requires you to enter a zone'),
];
case EmailServiceType::SMTP:
return [
'settings.domain.required' => __('The Smtp Email Service requires you to enter a domain'),
'settings.port.required' => __('The Smtp Email Service requires you to enter a port'),
'settings.username.required' => __('The Smtp Email Service requires you to enter an username'),
'settings.password.required' => __('The Smtp Email Service requires you to enter a password'),
'settings.encryption.required' => __('The Smtp Email Service requires you to enter an encryption'),
];
default:
return [];
}
}
public static function resolveValidationRules($typeId): array
{
switch ($typeId) {
case EmailServiceType::SES:
return [
'settings.key' => 'required',
'settings.secret' => 'required',
'settings.region' => 'required',
'settings.configuration_set_name' => 'required'
];
case EmailServiceType::SENDGRID:
case EmailServiceType::POSTMARK:
return [
'settings.key' => 'required',
];
case EmailServiceType::MAILGUN:
return [
'settings.key' => 'required',
'settings.domain' => 'required',
'settings.zone' => ['required', 'in:US,EU']
];
case EmailServiceType::MAILJET:
return [
'settings.key' => 'required',
'settings.secret' => 'required',
'settings.zone' => ['required', 'in:Default,US'],
];
case EmailServiceType::SMTP:
return [
'settings.domain' => 'required',
'settings.port' => 'required',
'settings.username' => 'required',
'settings.password' => 'required',
'settings.encryption' => 'required'
];
default:
return [];
}
}
}