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