xref: /webtrees/app/Http/RequestHandlers/EmailPreferencesPage.php (revision ba1d7494e9648df5a87aaa3fece3e098e5ce26b1)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22use Fisharebest\Webtrees\Http\ViewResponseTrait;
23use Fisharebest\Webtrees\I18N;
24use Fisharebest\Webtrees\Services\EmailService;
25use Fisharebest\Webtrees\Site;
26use Psr\Http\Message\ResponseInterface;
27use Psr\Http\Message\ServerRequestInterface;
28use Psr\Http\Server\RequestHandlerInterface;
29
30use function filter_var;
31
32use const FILTER_VALIDATE_DOMAIN;
33
34/**
35 * Edit the email preferences.
36 */
37class EmailPreferencesPage implements RequestHandlerInterface
38{
39    use ViewResponseTrait;
40
41    /** @var EmailService */
42    private $email_service;
43
44    /**
45     * AdminSiteController constructor.
46     *
47     * @param EmailService $email_service
48     */
49    public function __construct(EmailService $email_service)
50    {
51        $this->email_service = $email_service;
52    }
53
54    /**
55     * @param ServerRequestInterface $request
56     *
57     * @return ResponseInterface
58     */
59    public function handle(ServerRequestInterface $request): ResponseInterface
60    {
61        $mail_ssl_options       = $this->email_service->mailSslOptions();
62        $mail_transport_options = $this->email_service->mailTransportOptions();
63
64        $title = I18N::translate('Sending email');
65
66        $SMTP_ACTIVE    = Site::getPreference('SMTP_ACTIVE');
67        $SMTP_AUTH      = Site::getPreference('SMTP_AUTH');
68        $SMTP_AUTH_USER = Site::getPreference('SMTP_AUTH_USER');
69        $SMTP_FROM_NAME = $this->email_service->senderEmail();
70        $SMTP_HELO      = $this->email_service->localDomain();
71        $SMTP_HOST      = Site::getPreference('SMTP_HOST');
72        $SMTP_PORT      = Site::getPreference('SMTP_PORT');
73        $SMTP_SSL       = Site::getPreference('SMTP_SSL');
74        $DKIM_DOMAIN    = Site::getPreference('DKIM_DOMAIN');
75        $DKIM_SELECTOR  = Site::getPreference('DKIM_SELECTOR');
76        $DKIM_KEY       = Site::getPreference('DKIM_KEY');
77
78        $smtp_from_name_valid = $this->email_service->isValidEmail($SMTP_FROM_NAME);
79        $smtp_helo_valid      = filter_var($SMTP_HELO, FILTER_VALIDATE_DOMAIN);
80
81        $this->layout = 'layouts/administration';
82
83        return $this->viewResponse('admin/site-mail', [
84            'mail_ssl_options'       => $mail_ssl_options,
85            'mail_transport_options' => $mail_transport_options,
86            'title'                  => $title,
87            'smtp_helo_valid'        => $smtp_helo_valid,
88            'smtp_from_name_valid'   => $smtp_from_name_valid,
89            'SMTP_ACTIVE'            => $SMTP_ACTIVE,
90            'SMTP_AUTH'              => $SMTP_AUTH,
91            'SMTP_AUTH_USER'         => $SMTP_AUTH_USER,
92            'SMTP_FROM_NAME'         => $SMTP_FROM_NAME,
93            'SMTP_HELO'              => $SMTP_HELO,
94            'SMTP_HOST'              => $SMTP_HOST,
95            'SMTP_PORT'              => $SMTP_PORT,
96            'SMTP_SSL'               => $SMTP_SSL,
97            'DKIM_DOMAIN'            => $DKIM_DOMAIN,
98            'DKIM_SELECTOR'          => $DKIM_SELECTOR,
99            'DKIM_KEY'               => $DKIM_KEY,
100        ]);
101    }
102}
103