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\Http\Controllers\AbstractBaseController; 22*d403609dSGreg Roachuse Fisharebest\Webtrees\I18N; 23*d403609dSGreg Roachuse Fisharebest\Webtrees\Site; 24*d403609dSGreg Roachuse Psr\Http\Message\ResponseInterface; 25*d403609dSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 26*d403609dSGreg Roachuse Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 27*d403609dSGreg Roach 28*d403609dSGreg Roach/** 29*d403609dSGreg Roach * Show a registration page. 30*d403609dSGreg Roach */ 31*d403609dSGreg Roachclass RegisterPage extends AbstractBaseController 32*d403609dSGreg Roach{ 33*d403609dSGreg Roach /** 34*d403609dSGreg Roach * @param ServerRequestInterface $request 35*d403609dSGreg Roach * 36*d403609dSGreg Roach * @return ResponseInterface 37*d403609dSGreg Roach */ 38*d403609dSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 39*d403609dSGreg Roach { 40*d403609dSGreg Roach $this->checkRegistrationAllowed(); 41*d403609dSGreg Roach 42*d403609dSGreg Roach $comments = $request->getQueryParams()['comments'] ?? ''; 43*d403609dSGreg Roach $email = $request->getQueryParams()['email'] ?? ''; 44*d403609dSGreg Roach $realname = $request->getQueryParams()['realname'] ?? ''; 45*d403609dSGreg Roach $username = $request->getQueryParams()['username'] ?? ''; 46*d403609dSGreg Roach 47*d403609dSGreg Roach $show_caution = Site::getPreference('SHOW_REGISTER_CAUTION') === '1'; 48*d403609dSGreg Roach 49*d403609dSGreg Roach $title = I18N::translate('Request a new user account'); 50*d403609dSGreg Roach 51*d403609dSGreg Roach return $this->viewResponse('register-page', [ 52*d403609dSGreg Roach 'comments' => $comments, 53*d403609dSGreg Roach 'email' => $email, 54*d403609dSGreg Roach 'realname' => $realname, 55*d403609dSGreg Roach 'show_caution' => $show_caution, 56*d403609dSGreg Roach 'title' => $title, 57*d403609dSGreg Roach 'username' => $username, 58*d403609dSGreg Roach ]); 59*d403609dSGreg Roach } 60*d403609dSGreg Roach 61*d403609dSGreg Roach /** 62*d403609dSGreg Roach * Check that visitors are allowed to register on this site. 63*d403609dSGreg Roach * 64*d403609dSGreg Roach * @return void 65*d403609dSGreg Roach * @throws NotFoundHttpException 66*d403609dSGreg Roach */ 67*d403609dSGreg Roach private function checkRegistrationAllowed(): void 68*d403609dSGreg Roach { 69*d403609dSGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') !== '1') { 70*d403609dSGreg Roach throw new NotFoundHttpException(); 71*d403609dSGreg Roach } 72*d403609dSGreg Roach } 73*d403609dSGreg Roach} 74