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; 256ccdf4f0SGreg 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'), 77*d8d70c25SGreg Roach 'url' => route('tree-page', ['ged' => $tree->name()]), 78cf30a8edSGreg Roach ]); 79e2a378d3SGreg Roach } 80e2a378d3SGreg Roach 816a8879feSGreg Roach if ($ctype !== '') { 82147e99aaSGreg Roach return view('modules/block-template', [ 831e7a7a28SGreg Roach 'block' => Str::kebab($this->name()), 849c6524dcSGreg Roach 'id' => $block_id, 859c6524dcSGreg Roach 'config_url' => '', 86cf30a8edSGreg Roach 'title' => $title, 879c6524dcSGreg Roach 'content' => $content, 889c6524dcSGreg Roach ]); 89e2a378d3SGreg Roach } 90b2ce94c6SRico Sonntag 91b2ce94c6SRico Sonntag return $content; 92e2a378d3SGreg Roach } 93e2a378d3SGreg Roach 94e2a378d3SGreg Roach /** {@inheritdoc} */ 95c1010edaSGreg Roach public function loadAjax(): bool 96c1010edaSGreg Roach { 97e2a378d3SGreg Roach return false; 98e2a378d3SGreg Roach } 99e2a378d3SGreg Roach 100e2a378d3SGreg Roach /** {@inheritdoc} */ 101c1010edaSGreg Roach public function isUserBlock(): bool 102c1010edaSGreg Roach { 103e2a378d3SGreg Roach return true; 104e2a378d3SGreg Roach } 105e2a378d3SGreg Roach 106e2a378d3SGreg Roach /** {@inheritdoc} */ 10763276d8fSGreg Roach public function isTreeBlock(): bool 108c1010edaSGreg Roach { 109e2a378d3SGreg Roach return true; 110e2a378d3SGreg Roach } 111e2a378d3SGreg Roach 11276692c8bSGreg Roach /** 113a45f9889SGreg Roach * Update the configuration for a block. 114a45f9889SGreg Roach * 1156ccdf4f0SGreg Roach * @param ServerRequestInterface $request 116a45f9889SGreg Roach * @param int $block_id 117a45f9889SGreg Roach * 118a45f9889SGreg Roach * @return void 119a45f9889SGreg Roach */ 1206ccdf4f0SGreg Roach public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void 121a45f9889SGreg Roach { 122a45f9889SGreg Roach } 123a45f9889SGreg Roach 124a45f9889SGreg Roach /** 12576692c8bSGreg Roach * An HTML form to edit block settings 12676692c8bSGreg Roach * 127e490cd80SGreg Roach * @param Tree $tree 12876692c8bSGreg Roach * @param int $block_id 129a9430be8SGreg Roach * 130a9430be8SGreg Roach * @return void 13176692c8bSGreg Roach */ 132e364afe4SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id): void 133c1010edaSGreg Roach { 134e2a378d3SGreg Roach } 135e2a378d3SGreg Roach} 136