Add mailman check
This commit is contained in:
parent
a15b54f98d
commit
0dcb3b7d5b
|
@ -4,6 +4,7 @@ namespace App\Mailgateway\Actions;
|
|||
|
||||
use App\Mailgateway\Models\Mailgateway;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
|
@ -13,6 +14,10 @@ class StoreAction
|
|||
|
||||
public function handle(array $input)
|
||||
{
|
||||
if (!(new $input['type']['cls']($input['type']['params']))->works()) {
|
||||
throw ValidationException::withMessages(['erorr' => 'Verbindung fehlgeschlagen.']);
|
||||
}
|
||||
|
||||
Mailgateway::create($input);
|
||||
}
|
||||
|
||||
|
@ -22,7 +27,7 @@ class StoreAction
|
|||
'name' => 'required|string|max:255',
|
||||
'domain' => 'required|string|max:255',
|
||||
'type.cls' => ['required', 'string', 'max:255', Rule::in(app('mail-gateways'))],
|
||||
'type.params' => 'present',
|
||||
...collect(request()->input('type.cls')::rules('storeValidator'))->mapWithKeys(fn ($rules, $key) => ["type.params.{$key}" => $rules]),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,21 @@
|
|||
|
||||
namespace App\Mailgateway\Types;
|
||||
|
||||
use App\Mailman\Support\MailmanService;
|
||||
|
||||
class MailmanType extends Type
|
||||
{
|
||||
public string $url;
|
||||
public string $user;
|
||||
public string $password;
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->url = data_get($params, 'url');
|
||||
$this->user = data_get($params, 'user');
|
||||
$this->password = data_get($params, 'password');
|
||||
}
|
||||
|
||||
public static function name(): string
|
||||
{
|
||||
return 'Mailman';
|
||||
|
@ -11,7 +24,7 @@ class MailmanType extends Type
|
|||
|
||||
public function works(): bool
|
||||
{
|
||||
return true;
|
||||
return app(MailmanService::class)->setCredentials($this->url, $this->user, $this->password)->check();
|
||||
}
|
||||
|
||||
public static function fields(): array
|
||||
|
|
|
@ -16,4 +16,11 @@ abstract class Type
|
|||
$field['name'] => $field['default'],
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
public static function rules(string $validator): array
|
||||
{
|
||||
return collect(static::fields())->mapWithKeys(fn ($field) => [
|
||||
$field['name'] => $field[$validator],
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue