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