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; 24a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 25e2a378d3SGreg Roach 26e2a378d3SGreg Roach/** 27e2a378d3SGreg Roach * Class LoginBlockModule 28e2a378d3SGreg Roach */ 29*49a243cbSGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleInterface, ModuleBlockInterface 30c1010edaSGreg Roach{ 31*49a243cbSGreg Roach use ModuleBlockTrait; 32*49a243cbSGreg Roach 33e2a378d3SGreg Roach /** {@inheritdoc} */ 34*49a243cbSGreg Roach public function title(): string 35c1010edaSGreg Roach { 36bbb76c12SGreg Roach /* I18N: Name of a module */ 37bbb76c12SGreg Roach return I18N::translate('Sign in'); 38e2a378d3SGreg Roach } 39e2a378d3SGreg Roach 40e2a378d3SGreg Roach /** {@inheritdoc} */ 41*49a243cbSGreg Roach public function description(): string 42c1010edaSGreg Roach { 43bbb76c12SGreg Roach /* I18N: Description of the “Sign in” module */ 44bbb76c12SGreg Roach return I18N::translate('An alternative way to sign in and sign out.'); 45e2a378d3SGreg Roach } 46e2a378d3SGreg Roach 4776692c8bSGreg Roach /** 4876692c8bSGreg Roach * Generate the HTML content of this block. 4976692c8bSGreg Roach * 50e490cd80SGreg Roach * @param Tree $tree 5176692c8bSGreg Roach * @param int $block_id 525f2ae573SGreg Roach * @param string $ctype 53727f238cSGreg Roach * @param string[] $cfg 5476692c8bSGreg Roach * 5576692c8bSGreg Roach * @return string 5676692c8bSGreg Roach */ 575f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 58c1010edaSGreg Roach { 59e2a378d3SGreg Roach if (Auth::check()) { 60cdc90107SGreg Roach $title = I18N::translate('Sign out'); 61147e99aaSGreg Roach $content = view('modules/login_block/sign-out', [ 62cf30a8edSGreg Roach 'user' => Auth::user(), 63cf30a8edSGreg Roach ]); 64e2a378d3SGreg Roach } else { 65cdc90107SGreg Roach $title = I18N::translate('Sign in'); 66147e99aaSGreg Roach $content = view('modules/login_block/sign-in', [ 67c1010edaSGreg Roach 'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'), 68cf30a8edSGreg Roach ]); 69e2a378d3SGreg Roach } 70e2a378d3SGreg Roach 716a8879feSGreg Roach if ($ctype !== '') { 72147e99aaSGreg Roach return view('modules/block-template', [ 739c6524dcSGreg Roach 'block' => str_replace('_', '-', $this->getName()), 749c6524dcSGreg Roach 'id' => $block_id, 759c6524dcSGreg Roach 'config_url' => '', 76cf30a8edSGreg Roach 'title' => $title, 779c6524dcSGreg Roach 'content' => $content, 789c6524dcSGreg Roach ]); 79e2a378d3SGreg Roach } 80b2ce94c6SRico Sonntag 81b2ce94c6SRico Sonntag return $content; 82e2a378d3SGreg Roach } 83e2a378d3SGreg Roach 84e2a378d3SGreg Roach /** {@inheritdoc} */ 85c1010edaSGreg Roach public function loadAjax(): bool 86c1010edaSGreg Roach { 87e2a378d3SGreg Roach return false; 88e2a378d3SGreg Roach } 89e2a378d3SGreg Roach 90e2a378d3SGreg Roach /** {@inheritdoc} */ 91c1010edaSGreg Roach public function isUserBlock(): bool 92c1010edaSGreg Roach { 93e2a378d3SGreg Roach return true; 94e2a378d3SGreg Roach } 95e2a378d3SGreg Roach 96e2a378d3SGreg Roach /** {@inheritdoc} */ 97c1010edaSGreg Roach public function isGedcomBlock(): bool 98c1010edaSGreg Roach { 99e2a378d3SGreg Roach return true; 100e2a378d3SGreg Roach } 101e2a378d3SGreg Roach 10276692c8bSGreg Roach /** 103a45f9889SGreg Roach * Update the configuration for a block. 104a45f9889SGreg Roach * 105a45f9889SGreg Roach * @param Request $request 106a45f9889SGreg Roach * @param int $block_id 107a45f9889SGreg Roach * 108a45f9889SGreg Roach * @return void 109a45f9889SGreg Roach */ 110a45f9889SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id) 111a45f9889SGreg Roach { 112a45f9889SGreg Roach } 113a45f9889SGreg Roach 114a45f9889SGreg Roach /** 11576692c8bSGreg Roach * An HTML form to edit block settings 11676692c8bSGreg Roach * 117e490cd80SGreg Roach * @param Tree $tree 11876692c8bSGreg Roach * @param int $block_id 119a9430be8SGreg Roach * 120a9430be8SGreg Roach * @return void 12176692c8bSGreg Roach */ 122a45f9889SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id) 123c1010edaSGreg Roach { 124e2a378d3SGreg Roach } 125e2a378d3SGreg Roach} 126