1e2a378d3SGreg Roach<?php 2e2a378d3SGreg Roach/** 3e2a378d3SGreg Roach * webtrees: online genealogy 4*8fcd0d32SGreg 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; 24a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 25e2a378d3SGreg Roach 26e2a378d3SGreg Roach/** 27e2a378d3SGreg Roach * Class LoginBlockModule 28e2a378d3SGreg Roach */ 29c1010edaSGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface 30c1010edaSGreg Roach{ 31e2a378d3SGreg Roach /** {@inheritdoc} */ 328f53f488SRico Sonntag public function getTitle(): string 33c1010edaSGreg Roach { 34bbb76c12SGreg Roach /* I18N: Name of a module */ 35bbb76c12SGreg Roach return I18N::translate('Sign in'); 36e2a378d3SGreg Roach } 37e2a378d3SGreg Roach 38e2a378d3SGreg Roach /** {@inheritdoc} */ 398f53f488SRico Sonntag public function getDescription(): string 40c1010edaSGreg Roach { 41bbb76c12SGreg Roach /* I18N: Description of the “Sign in” module */ 42bbb76c12SGreg Roach return I18N::translate('An alternative way to sign in and sign out.'); 43e2a378d3SGreg Roach } 44e2a378d3SGreg Roach 4576692c8bSGreg Roach /** 4676692c8bSGreg Roach * Generate the HTML content of this block. 4776692c8bSGreg Roach * 48e490cd80SGreg Roach * @param Tree $tree 4976692c8bSGreg Roach * @param int $block_id 505f2ae573SGreg Roach * @param string $ctype 51727f238cSGreg Roach * @param string[] $cfg 5276692c8bSGreg Roach * 5376692c8bSGreg Roach * @return string 5476692c8bSGreg Roach */ 555f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 56c1010edaSGreg Roach { 57e2a378d3SGreg Roach if (Auth::check()) { 58cdc90107SGreg Roach $title = I18N::translate('Sign out'); 59147e99aaSGreg Roach $content = view('modules/login_block/sign-out', [ 60cf30a8edSGreg Roach 'user' => Auth::user(), 61cf30a8edSGreg Roach ]); 62e2a378d3SGreg Roach } else { 63cdc90107SGreg Roach $title = I18N::translate('Sign in'); 64147e99aaSGreg Roach $content = view('modules/login_block/sign-in', [ 65c1010edaSGreg Roach 'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'), 66cf30a8edSGreg Roach ]); 67e2a378d3SGreg Roach } 68e2a378d3SGreg Roach 696a8879feSGreg Roach if ($ctype !== '') { 70147e99aaSGreg Roach return view('modules/block-template', [ 719c6524dcSGreg Roach 'block' => str_replace('_', '-', $this->getName()), 729c6524dcSGreg Roach 'id' => $block_id, 739c6524dcSGreg Roach 'config_url' => '', 74cf30a8edSGreg Roach 'title' => $title, 759c6524dcSGreg Roach 'content' => $content, 769c6524dcSGreg Roach ]); 77e2a378d3SGreg Roach } 78b2ce94c6SRico Sonntag 79b2ce94c6SRico Sonntag return $content; 80e2a378d3SGreg Roach } 81e2a378d3SGreg Roach 82e2a378d3SGreg Roach /** {@inheritdoc} */ 83c1010edaSGreg Roach public function loadAjax(): bool 84c1010edaSGreg Roach { 85e2a378d3SGreg Roach return false; 86e2a378d3SGreg Roach } 87e2a378d3SGreg Roach 88e2a378d3SGreg Roach /** {@inheritdoc} */ 89c1010edaSGreg Roach public function isUserBlock(): bool 90c1010edaSGreg Roach { 91e2a378d3SGreg Roach return true; 92e2a378d3SGreg Roach } 93e2a378d3SGreg Roach 94e2a378d3SGreg Roach /** {@inheritdoc} */ 95c1010edaSGreg Roach public function isGedcomBlock(): bool 96c1010edaSGreg Roach { 97e2a378d3SGreg Roach return true; 98e2a378d3SGreg Roach } 99e2a378d3SGreg Roach 10076692c8bSGreg Roach /** 101a45f9889SGreg Roach * Update the configuration for a block. 102a45f9889SGreg Roach * 103a45f9889SGreg Roach * @param Request $request 104a45f9889SGreg Roach * @param int $block_id 105a45f9889SGreg Roach * 106a45f9889SGreg Roach * @return void 107a45f9889SGreg Roach */ 108a45f9889SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id) 109a45f9889SGreg Roach { 110a45f9889SGreg Roach } 111a45f9889SGreg Roach 112a45f9889SGreg Roach /** 11376692c8bSGreg Roach * An HTML form to edit block settings 11476692c8bSGreg Roach * 115e490cd80SGreg Roach * @param Tree $tree 11676692c8bSGreg Roach * @param int $block_id 117a9430be8SGreg Roach * 118a9430be8SGreg Roach * @return void 11976692c8bSGreg Roach */ 120a45f9889SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id) 121c1010edaSGreg Roach { 122e2a378d3SGreg Roach } 123e2a378d3SGreg Roach} 124