xref: /webtrees/app/Module/LoginBlockModule.php (revision 6ccdf4f0fd1b65a5d54259c969912382ce49629d)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5e2a378d3SGreg Roach * This program is free software: you can redistribute it and/or modify
6e2a378d3SGreg Roach * it under the terms of the GNU General Public License as published by
7e2a378d3SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8e2a378d3SGreg Roach * (at your option) any later version.
9e2a378d3SGreg Roach * This program is distributed in the hope that it will be useful,
10e2a378d3SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11e2a378d3SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12e2a378d3SGreg Roach * GNU General Public License for more details.
13e2a378d3SGreg Roach * You should have received a copy of the GNU General Public License
14e2a378d3SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15e2a378d3SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1976692c8bSGreg Roach
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
23e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
241e7a7a28SGreg Roachuse Illuminate\Support\Str;
25*6ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
26e2a378d3SGreg Roach
27e2a378d3SGreg Roach/**
28e2a378d3SGreg Roach * Class LoginBlockModule
29e2a378d3SGreg Roach */
3037eb8894SGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface
31c1010edaSGreg Roach{
3249a243cbSGreg Roach    use ModuleBlockTrait;
3349a243cbSGreg Roach
34961ec755SGreg Roach    /**
350cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
36961ec755SGreg Roach     *
37961ec755SGreg Roach     * @return string
38961ec755SGreg Roach     */
3949a243cbSGreg Roach    public function title(): string
40c1010edaSGreg Roach    {
41bbb76c12SGreg Roach        /* I18N: Name of a module */
42bbb76c12SGreg Roach        return I18N::translate('Sign in');
43e2a378d3SGreg Roach    }
44e2a378d3SGreg Roach
45961ec755SGreg Roach    /**
46961ec755SGreg Roach     * A sentence describing what this module does.
47961ec755SGreg Roach     *
48961ec755SGreg Roach     * @return string
49961ec755SGreg Roach     */
5049a243cbSGreg Roach    public function description(): string
51c1010edaSGreg Roach    {
52bbb76c12SGreg Roach        /* I18N: Description of the “Sign in” module */
53bbb76c12SGreg Roach        return I18N::translate('An alternative way to sign in and sign out.');
54e2a378d3SGreg Roach    }
55e2a378d3SGreg Roach
5676692c8bSGreg Roach    /**
5776692c8bSGreg Roach     * Generate the HTML content of this block.
5876692c8bSGreg Roach     *
59e490cd80SGreg Roach     * @param Tree     $tree
6076692c8bSGreg Roach     * @param int      $block_id
615f2ae573SGreg Roach     * @param string   $ctype
62727f238cSGreg Roach     * @param string[] $cfg
6376692c8bSGreg Roach     *
6476692c8bSGreg Roach     * @return string
6576692c8bSGreg Roach     */
665f2ae573SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
67c1010edaSGreg Roach    {
68e2a378d3SGreg Roach        if (Auth::check()) {
69cdc90107SGreg Roach            $title   = I18N::translate('Sign out');
70147e99aaSGreg Roach            $content = view('modules/login_block/sign-out', [
71cf30a8edSGreg Roach                'user' => Auth::user(),
72cf30a8edSGreg Roach            ]);
73e2a378d3SGreg Roach        } else {
74cdc90107SGreg Roach            $title   = I18N::translate('Sign in');
75147e99aaSGreg Roach            $content = view('modules/login_block/sign-in', [
76c1010edaSGreg Roach                'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'),
77cf30a8edSGreg Roach            ]);
78e2a378d3SGreg Roach        }
79e2a378d3SGreg Roach
806a8879feSGreg Roach        if ($ctype !== '') {
81147e99aaSGreg Roach            return view('modules/block-template', [
821e7a7a28SGreg Roach                'block'      => Str::kebab($this->name()),
839c6524dcSGreg Roach                'id'         => $block_id,
849c6524dcSGreg Roach                'config_url' => '',
85cf30a8edSGreg Roach                'title'      => $title,
869c6524dcSGreg Roach                'content'    => $content,
879c6524dcSGreg Roach            ]);
88e2a378d3SGreg Roach        }
89b2ce94c6SRico Sonntag
90b2ce94c6SRico Sonntag        return $content;
91e2a378d3SGreg Roach    }
92e2a378d3SGreg Roach
93e2a378d3SGreg Roach    /** {@inheritdoc} */
94c1010edaSGreg Roach    public function loadAjax(): bool
95c1010edaSGreg Roach    {
96e2a378d3SGreg Roach        return false;
97e2a378d3SGreg Roach    }
98e2a378d3SGreg Roach
99e2a378d3SGreg Roach    /** {@inheritdoc} */
100c1010edaSGreg Roach    public function isUserBlock(): bool
101c1010edaSGreg Roach    {
102e2a378d3SGreg Roach        return true;
103e2a378d3SGreg Roach    }
104e2a378d3SGreg Roach
105e2a378d3SGreg Roach    /** {@inheritdoc} */
10663276d8fSGreg Roach    public function isTreeBlock(): bool
107c1010edaSGreg Roach    {
108e2a378d3SGreg Roach        return true;
109e2a378d3SGreg Roach    }
110e2a378d3SGreg Roach
11176692c8bSGreg Roach    /**
112a45f9889SGreg Roach     * Update the configuration for a block.
113a45f9889SGreg Roach     *
114*6ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
115a45f9889SGreg Roach     * @param int     $block_id
116a45f9889SGreg Roach     *
117a45f9889SGreg Roach     * @return void
118a45f9889SGreg Roach     */
119*6ccdf4f0SGreg Roach    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
120a45f9889SGreg Roach    {
121a45f9889SGreg Roach    }
122a45f9889SGreg Roach
123a45f9889SGreg Roach    /**
12476692c8bSGreg Roach     * An HTML form to edit block settings
12576692c8bSGreg Roach     *
126e490cd80SGreg Roach     * @param Tree $tree
12776692c8bSGreg Roach     * @param int  $block_id
128a9430be8SGreg Roach     *
129a9430be8SGreg Roach     * @return void
13076692c8bSGreg Roach     */
131e364afe4SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id): void
132c1010edaSGreg Roach    {
133e2a378d3SGreg Roach    }
134e2a378d3SGreg Roach}
135