1d403609dSGreg Roach<?php 2d403609dSGreg Roach 3d403609dSGreg Roach/** 4d403609dSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16d403609dSGreg Roach */ 17fcfa147eSGreg Roach 18d403609dSGreg Roachdeclare(strict_types=1); 19d403609dSGreg Roach 20d403609dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21d403609dSGreg Roach 2281b729d3SGreg Roachuse Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException; 2370ca9c90SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 24d403609dSGreg Roachuse Fisharebest\Webtrees\I18N; 2570ca9c90SGreg Roachuse Fisharebest\Webtrees\Services\CaptchaService; 26f91b88bbSGreg Roachuse Fisharebest\Webtrees\Session; 27d403609dSGreg Roachuse Fisharebest\Webtrees\Site; 28b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 29d403609dSGreg Roachuse Psr\Http\Message\ResponseInterface; 30d403609dSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3170ca9c90SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 32d403609dSGreg Roach 33d8809d62SGreg Roachuse function is_string; 34d8809d62SGreg Roach 35d403609dSGreg Roach/** 36d403609dSGreg Roach * Show a registration page. 37d403609dSGreg Roach */ 3870ca9c90SGreg Roachclass RegisterPage implements RequestHandlerInterface 39d403609dSGreg Roach{ 4070ca9c90SGreg Roach use ViewResponseTrait; 4170ca9c90SGreg Roach 42c4943cffSGreg Roach private CaptchaService $captcha_service; 4370ca9c90SGreg Roach 4470ca9c90SGreg Roach /** 4570ca9c90SGreg Roach * @param CaptchaService $captcha_service 4670ca9c90SGreg Roach */ 4770ca9c90SGreg Roach public function __construct(CaptchaService $captcha_service) 4870ca9c90SGreg Roach { 4970ca9c90SGreg Roach $this->captcha_service = $captcha_service; 5070ca9c90SGreg Roach } 5170ca9c90SGreg Roach 52d403609dSGreg Roach /** 53d403609dSGreg Roach * @param ServerRequestInterface $request 54d403609dSGreg Roach * 55d403609dSGreg Roach * @return ResponseInterface 56d403609dSGreg Roach */ 57d403609dSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 58d403609dSGreg Roach { 59d403609dSGreg Roach $this->checkRegistrationAllowed(); 60d403609dSGreg Roach 61b55cbc6bSGreg Roach $tree = Validator::attributes($request)->treeOptional(); 62d8809d62SGreg Roach 63d8809d62SGreg Roach $comments = Session::get('register_comments'); 64d8809d62SGreg Roach $comments = is_string($comments) ? $comments : ''; 65d8809d62SGreg Roach 66d8809d62SGreg Roach $email = Session::get('register_email'); 67d8809d62SGreg Roach $email = is_string($email) ? $email : ''; 68d8809d62SGreg Roach 69d8809d62SGreg Roach $realname = Session::get('register_realname'); 70d8809d62SGreg Roach $realname = is_string($realname) ? $realname : ''; 71d8809d62SGreg Roach 72d8809d62SGreg Roach $username = Session::get('register_username'); 73d8809d62SGreg Roach $username = is_string($username) ? $username : ''; 74d403609dSGreg Roach 75d403609dSGreg Roach $show_caution = Site::getPreference('SHOW_REGISTER_CAUTION') === '1'; 76d403609dSGreg Roach 77d403609dSGreg Roach $title = I18N::translate('Request a new user account'); 78d403609dSGreg Roach 79d403609dSGreg Roach return $this->viewResponse('register-page', [ 8070ca9c90SGreg Roach 'captcha' => $this->captcha_service->createCaptcha(), 81d403609dSGreg Roach 'comments' => $comments, 82d403609dSGreg Roach 'email' => $email, 83d403609dSGreg Roach 'realname' => $realname, 84d403609dSGreg Roach 'show_caution' => $show_caution, 85d403609dSGreg Roach 'title' => $title, 86a49d0e3fSGreg Roach 'tree' => $tree, 87d403609dSGreg Roach 'username' => $username, 88d403609dSGreg Roach ]); 89d403609dSGreg Roach } 90d403609dSGreg Roach 91d403609dSGreg Roach /** 92d403609dSGreg Roach * Check that visitors are allowed to register on this site. 93d403609dSGreg Roach * 94d403609dSGreg Roach * @return void 95d501c45dSGreg Roach * @throws HttpNotFoundException 96d403609dSGreg Roach */ 97d403609dSGreg Roach private function checkRegistrationAllowed(): void 98d403609dSGreg Roach { 99d403609dSGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') !== '1') { 100d501c45dSGreg Roach throw new HttpNotFoundException(); 101d403609dSGreg Roach } 102d403609dSGreg Roach } 103d403609dSGreg Roach} 104