Passed
Push — master ( dbc196...489072 )
by Greg
05:38
created

EmailPreferencesPage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
dl 0
loc 63
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 41 1
A __construct() 0 3 1
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
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22
use Fisharebest\Webtrees\Http\ViewResponseTrait;
23
use Fisharebest\Webtrees\I18N;
24
use Fisharebest\Webtrees\Services\EmailService;
25
use Fisharebest\Webtrees\Site;
26
use Psr\Http\Message\ResponseInterface;
27
use Psr\Http\Message\ServerRequestInterface;
28
use Psr\Http\Server\RequestHandlerInterface;
29
30
use function filter_var;
31
32
use const FILTER_VALIDATE_DOMAIN;
33
34
/**
35
 * Edit the email preferences.
36
 */
37
class 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