1d403609dSGreg Roach<?php 2d403609dSGreg Roach 3d403609dSGreg Roach/** 4d403609dSGreg Roach * webtrees: online genealogy 5d403609dSGreg Roach * Copyright (C) 2019 webtrees development team 6d403609dSGreg Roach * This program is free software: you can redistribute it and/or modify 7d403609dSGreg Roach * it under the terms of the GNU General Public License as published by 8d403609dSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9d403609dSGreg Roach * (at your option) any later version. 10d403609dSGreg Roach * This program is distributed in the hope that it will be useful, 11d403609dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12d403609dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13d403609dSGreg Roach * GNU General Public License for more details. 14d403609dSGreg Roach * You should have received a copy of the GNU General Public License 15d403609dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16d403609dSGreg Roach */ 17fcfa147eSGreg Roach 18d403609dSGreg Roachdeclare(strict_types=1); 19d403609dSGreg Roach 20d403609dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21d403609dSGreg Roach 22*90a2f718SGreg Roachuse Fisharebest\Localization\Locale\LocaleInterface; 23d403609dSGreg Roachuse Fisharebest\Webtrees\Http\Controllers\AbstractBaseController; 24d403609dSGreg Roachuse Fisharebest\Webtrees\I18N; 25d403609dSGreg Roachuse Fisharebest\Webtrees\Site; 26a91af26aSGreg Roachuse Fisharebest\Webtrees\Tree; 27d403609dSGreg Roachuse Fisharebest\Webtrees\User; 28d403609dSGreg Roachuse Psr\Http\Message\ResponseInterface; 29d403609dSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 30d403609dSGreg Roach 31*90a2f718SGreg Roachuse function assert; 32*90a2f718SGreg Roach 33d403609dSGreg Roach/** 34d403609dSGreg Roach * Show a login form. 35d403609dSGreg Roach */ 36d403609dSGreg Roachclass LoginPage extends AbstractBaseController 37d403609dSGreg Roach{ 38d403609dSGreg Roach /** 39d403609dSGreg Roach * @param ServerRequestInterface $request 40d403609dSGreg Roach * 41d403609dSGreg Roach * @return ResponseInterface 42d403609dSGreg Roach */ 43d403609dSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 44d403609dSGreg Roach { 45*90a2f718SGreg Roach $locale = $request->getAttribute('locale'); 46*90a2f718SGreg Roach assert($locale instanceof LocaleInterface); 47*90a2f718SGreg Roach 48d403609dSGreg Roach $tree = $request->getAttribute('tree'); 49d403609dSGreg Roach $user = $request->getAttribute('user'); 50d403609dSGreg Roach 51d403609dSGreg Roach // Already logged in? 52d403609dSGreg Roach if ($user instanceof User) { 53a91af26aSGreg Roach return redirect(route('user-page', ['tree' => $tree instanceof Tree ? $tree->name() : ''])); 54d403609dSGreg Roach } 55d403609dSGreg Roach 56d403609dSGreg Roach $error = $request->getQueryParams()['error'] ?? ''; 57d403609dSGreg Roach $url = $request->getQueryParams()['url'] ?? ''; 58d403609dSGreg Roach $username = $request->getQueryParams()['username'] ?? ''; 59d403609dSGreg Roach 60d403609dSGreg Roach $title = I18N::translate('Sign in'); 61d403609dSGreg Roach 62d403609dSGreg Roach switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) { 63320f6a24SGreg Roach case '1': 64d403609dSGreg Roach default: 65d403609dSGreg Roach $welcome = I18N::translate('Anyone with a user account can access this website.'); 66d403609dSGreg Roach break; 67320f6a24SGreg Roach case '2': 68d403609dSGreg Roach $welcome = I18N::translate('You need to be an authorized user to access this website.'); 69d403609dSGreg Roach break; 70320f6a24SGreg Roach case '3': 71d403609dSGreg Roach $welcome = I18N::translate('You need to be a family member to access this website.'); 72d403609dSGreg Roach break; 73320f6a24SGreg Roach case '4': 74*90a2f718SGreg Roach $welcome = Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . $locale->languageTag()); 75d403609dSGreg Roach break; 76d403609dSGreg Roach } 77d403609dSGreg Roach 78d403609dSGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') === '1') { 79d403609dSGreg Roach $welcome .= ' ' . I18N::translate('You can apply for an account using the link below.'); 80d403609dSGreg Roach } 81d403609dSGreg Roach 82d403609dSGreg Roach $can_register = Site::getPreference('USE_REGISTRATION_MODULE') === '1'; 83d403609dSGreg Roach 84d403609dSGreg Roach return $this->viewResponse('login-page', [ 85d403609dSGreg Roach 'can_register' => $can_register, 86d403609dSGreg Roach 'error' => $error, 87d403609dSGreg Roach 'title' => $title, 88d403609dSGreg Roach 'url' => $url, 890c0910bfSGreg Roach 'tree' => $tree, 90d403609dSGreg Roach 'username' => $username, 91d403609dSGreg Roach 'welcome' => $welcome, 92d403609dSGreg Roach ]); 93d403609dSGreg Roach } 94d403609dSGreg Roach} 95