1e2a378d3SGreg Roach<?php 2e2a378d3SGreg Roach/** 3e2a378d3SGreg Roach * webtrees: online genealogy 46bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team 5e2a378d3SGreg Roach * This program is free software: you can redistribute it and/or modify 6e2a378d3SGreg Roach * it under the terms of the GNU General Public License as published by 7e2a378d3SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8e2a378d3SGreg Roach * (at your option) any later version. 9e2a378d3SGreg Roach * This program is distributed in the hope that it will be useful, 10e2a378d3SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11e2a378d3SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12e2a378d3SGreg Roach * GNU General Public License for more details. 13e2a378d3SGreg Roach * You should have received a copy of the GNU General Public License 14e2a378d3SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15e2a378d3SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme; 22*9c6524dcSGreg Roachuse Fisharebest\Webtrees\View; 23e2a378d3SGreg Roach 24e2a378d3SGreg Roach/** 25e2a378d3SGreg Roach * Class LoginBlockModule 26e2a378d3SGreg Roach */ 27e2a378d3SGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface { 28e2a378d3SGreg Roach /** {@inheritdoc} */ 29e2a378d3SGreg Roach public function getTitle() { 30cdc90107SGreg Roach return /* I18N: Name of a module */ I18N::translate('Sign in'); 31e2a378d3SGreg Roach } 32e2a378d3SGreg Roach 33e2a378d3SGreg Roach /** {@inheritdoc} */ 34e2a378d3SGreg Roach public function getDescription() { 35cdc90107SGreg Roach return /* I18N: Description of the “Sign in” module */ I18N::translate('An alternative way to sign in and sign out.'); 36e2a378d3SGreg Roach } 37e2a378d3SGreg Roach 3876692c8bSGreg Roach /** 3976692c8bSGreg Roach * Generate the HTML content of this block. 4076692c8bSGreg Roach * 4176692c8bSGreg Roach * @param int $block_id 4276692c8bSGreg Roach * @param bool $template 43727f238cSGreg Roach * @param string[] $cfg 4476692c8bSGreg Roach * 4576692c8bSGreg Roach * @return string 4676692c8bSGreg Roach */ 4713abd6f3SGreg Roach public function getBlock($block_id, $template = true, $cfg = []) { 48e2a378d3SGreg Roach global $controller; 49e2a378d3SGreg Roach $id = $this->getName() . $block_id; 50e2a378d3SGreg Roach $class = $this->getName() . '_block'; 51e2a378d3SGreg Roach $controller->addInlineJavascript(' 5215d603e7SGreg Roach $("#new_passwd").hide(); 5315d603e7SGreg Roach $("#passwd_click").click(function() { 5415d603e7SGreg Roach $("#new_passwd").slideToggle(200); 5515d603e7SGreg Roach $("#register-link").slideToggle(200); 5615d603e7SGreg Roach $("#new_passwd_username").focus(); 57762f8fb2SGreg Roach 58e2a378d3SGreg Roach return false; 59e2a378d3SGreg Roach }); 60e2a378d3SGreg Roach '); 61e2a378d3SGreg Roach 62e2a378d3SGreg Roach if (Auth::check()) { 63cdc90107SGreg Roach $title = I18N::translate('Sign out'); 643d7dce6aSGreg Roach $content = '<div class="center"><form method="post" action="logout.php" name="logoutform" onsubmit="return true;">'; 65390c61f3SGreg Roach $content .= '<br>' . I18N::translate('You are signed in as %s.', '<a href="edituser.php" class="name2">' . Auth::user()->getRealNameHtml() . '</a>') . '<br><br>'; 66552fa1fbSGreg Roach $content .= '<input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign out') . '">'; 67e2a378d3SGreg Roach 68e2a378d3SGreg Roach $content .= '<br><br></form></div>'; 69e2a378d3SGreg Roach } else { 70cdc90107SGreg Roach $title = I18N::translate('Sign in'); 71e2a378d3SGreg Roach $content = '<div id="login-box"> 7267536fc1SGreg Roach <form id="login-form" name="login-form" method="post" action="' . WT_LOGIN_URL . '"> 7367536fc1SGreg Roach <input type="hidden" name="action" value="login">'; 74e2a378d3SGreg Roach $content .= '<div> 75e2a378d3SGreg Roach <label for="username">' . I18N::translate('Username') . 76e2a378d3SGreg Roach '<input type="text" id="username" name="username" class="formField"> 77e2a378d3SGreg Roach </label> 78e2a378d3SGreg Roach </div> 79e2a378d3SGreg Roach <div> 80e2a378d3SGreg Roach <label for="password">' . I18N::translate('Password') . 81e2a378d3SGreg Roach '<input type="password" id="password" name="password" class="formField"> 82e2a378d3SGreg Roach </label> 83e2a378d3SGreg Roach </div> 84e2a378d3SGreg Roach <div> 85552fa1fbSGreg Roach <input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign in') . '"> 86e2a378d3SGreg Roach </div> 87e2a378d3SGreg Roach <div> 888d7a7b2dSGreg Roach <a href="#" id="passwd_click">' . I18N::translate('Forgot password?') . '</a> 89e2a378d3SGreg Roach </div>'; 9015d603e7SGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') === '1') { 91762f8fb2SGreg Roach $content .= '<div id="register-link"><a href="' . WT_LOGIN_URL . '?action=register">' . I18N::translate('Request a new user account') . '</a></div>'; 92e2a378d3SGreg Roach } 93e2a378d3SGreg Roach $content .= '</form>'; // close "login-form" 94e2a378d3SGreg Roach 95e2a378d3SGreg Roach // hidden New Password block 96e2a378d3SGreg Roach $content .= '<div id="new_passwd"> 97e2a378d3SGreg Roach <form id="new_passwd_form" name="new_passwd_form" action="' . WT_LOGIN_URL . '" method="post"> 98e2a378d3SGreg Roach <input type="hidden" name="time" value=""> 99e2a378d3SGreg Roach <input type="hidden" name="action" value="requestpw"> 1007555da9cSGreg Roach <h4>' . I18N::translate('Request a new password') . '</h4> 101e2a378d3SGreg Roach <div> 102e2a378d3SGreg Roach <label for="new_passwd_username">' . I18N::translate('Username or email address') . 103e2a378d3SGreg Roach '<input type="text" id="new_passwd_username" name="new_passwd_username" value=""> 104e2a378d3SGreg Roach </label> 105e2a378d3SGreg Roach </div> 106e2a378d3SGreg Roach <div><input type="submit" value="' . I18N::translate('continue') . '"></div> 107e2a378d3SGreg Roach </form> 108e2a378d3SGreg Roach </div>'; //"new_passwd" 109e2a378d3SGreg Roach $content .= '</div>'; //"login-box" 110e2a378d3SGreg Roach } 111e2a378d3SGreg Roach 112e2a378d3SGreg Roach if ($template) { 113*9c6524dcSGreg Roach return View::make('blocks/template', [ 114*9c6524dcSGreg Roach 'block' => str_replace('_', '-', $this->getName()), 115*9c6524dcSGreg Roach 'id' => $block_id, 116*9c6524dcSGreg Roach 'config_url' => '', 117*9c6524dcSGreg Roach 'title' => $this->getTitle(), 118*9c6524dcSGreg Roach 'content' => $content, 119*9c6524dcSGreg Roach ]); 120e2a378d3SGreg Roach } else { 121e2a378d3SGreg Roach return $content; 122e2a378d3SGreg Roach } 123e2a378d3SGreg Roach } 124e2a378d3SGreg Roach 125e2a378d3SGreg Roach /** {@inheritdoc} */ 126e2a378d3SGreg Roach public function loadAjax() { 127e2a378d3SGreg Roach return false; 128e2a378d3SGreg Roach } 129e2a378d3SGreg Roach 130e2a378d3SGreg Roach /** {@inheritdoc} */ 131e2a378d3SGreg Roach public function isUserBlock() { 132e2a378d3SGreg Roach return true; 133e2a378d3SGreg Roach } 134e2a378d3SGreg Roach 135e2a378d3SGreg Roach /** {@inheritdoc} */ 136e2a378d3SGreg Roach public function isGedcomBlock() { 137e2a378d3SGreg Roach return true; 138e2a378d3SGreg Roach } 139e2a378d3SGreg Roach 14076692c8bSGreg Roach /** 14176692c8bSGreg Roach * An HTML form to edit block settings 14276692c8bSGreg Roach * 14376692c8bSGreg Roach * @param int $block_id 14476692c8bSGreg Roach */ 145e2a378d3SGreg Roach public function configureBlock($block_id) { 146e2a378d3SGreg Roach } 147e2a378d3SGreg Roach} 148