xref: /webtrees/app/Module/LoginBlockModule.php (revision 6bdf767435631ad1dc27ec1ffd855d43dbdce907)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
4*6bdf7674SGreg 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;
22e2a378d3SGreg Roach
23e2a378d3SGreg Roach/**
24e2a378d3SGreg Roach * Class LoginBlockModule
25e2a378d3SGreg Roach */
26e2a378d3SGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface {
27e2a378d3SGreg Roach	/** {@inheritdoc} */
28e2a378d3SGreg Roach	public function getTitle() {
29cdc90107SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Sign in');
30e2a378d3SGreg Roach	}
31e2a378d3SGreg Roach
32e2a378d3SGreg Roach	/** {@inheritdoc} */
33e2a378d3SGreg Roach	public function getDescription() {
34cdc90107SGreg Roach		return /* I18N: Description of the “Sign in” module */ I18N::translate('An alternative way to sign in and sign out.');
35e2a378d3SGreg Roach	}
36e2a378d3SGreg Roach
3776692c8bSGreg Roach	/**
3876692c8bSGreg Roach	 * Generate the HTML content of this block.
3976692c8bSGreg Roach	 *
4076692c8bSGreg Roach	 * @param int      $block_id
4176692c8bSGreg Roach	 * @param bool     $template
42727f238cSGreg Roach	 * @param string[] $cfg
4376692c8bSGreg Roach	 *
4476692c8bSGreg Roach	 * @return string
4576692c8bSGreg Roach	 */
4613abd6f3SGreg Roach	public function getBlock($block_id, $template = true, $cfg = []) {
47e2a378d3SGreg Roach		global $controller;
48e2a378d3SGreg Roach		$id    = $this->getName() . $block_id;
49e2a378d3SGreg Roach		$class = $this->getName() . '_block';
50e2a378d3SGreg Roach		$controller->addInlineJavascript('
51e2a378d3SGreg Roach			jQuery("#new_passwd").hide();
52e2a378d3SGreg Roach			jQuery("#passwd_click").click(function() {
53762f8fb2SGreg Roach				jQuery("#new_passwd").slideToggle(200);
54762f8fb2SGreg Roach				jQuery("#register-link").slideToggle(200);
55e2a378d3SGreg Roach				jQuery("#new_passwd_username").focus();
56762f8fb2SGreg Roach
57e2a378d3SGreg Roach				return false;
58e2a378d3SGreg Roach			});
59e2a378d3SGreg Roach		');
60e2a378d3SGreg Roach
61e2a378d3SGreg Roach		if (Auth::check()) {
62cdc90107SGreg Roach			$title   = I18N::translate('Sign out');
633d7dce6aSGreg Roach			$content = '<div class="center"><form method="post" action="logout.php" name="logoutform" onsubmit="return true;">';
64390c61f3SGreg Roach			$content .= '<br>' . I18N::translate('You are signed in as %s.', '<a href="edituser.php" class="name2">' . Auth::user()->getRealNameHtml() . '</a>') . '<br><br>';
65552fa1fbSGreg Roach			$content .= '<input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign out') . '">';
66e2a378d3SGreg Roach
67e2a378d3SGreg Roach			$content .= '<br><br></form></div>';
68e2a378d3SGreg Roach		} else {
69cdc90107SGreg Roach			$title   = I18N::translate('Sign in');
70e2a378d3SGreg Roach			$content = '<div id="login-box">
7167536fc1SGreg Roach				<form id="login-form" name="login-form" method="post" action="' . WT_LOGIN_URL . '">
7267536fc1SGreg Roach				<input type="hidden" name="action" value="login">';
73e2a378d3SGreg Roach			$content .= '<div>
74e2a378d3SGreg Roach				<label for="username">' . I18N::translate('Username') .
75e2a378d3SGreg Roach					'<input type="text" id="username" name="username" class="formField">
76e2a378d3SGreg Roach				</label>
77e2a378d3SGreg Roach				</div>
78e2a378d3SGreg Roach				<div>
79e2a378d3SGreg Roach					<label for="password">' . I18N::translate('Password') .
80e2a378d3SGreg Roach						'<input type="password" id="password" name="password" class="formField">
81e2a378d3SGreg Roach					</label>
82e2a378d3SGreg Roach				</div>
83e2a378d3SGreg Roach				<div>
84552fa1fbSGreg Roach					<input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign in') . '">
85e2a378d3SGreg Roach				</div>
86e2a378d3SGreg Roach				<div>
878d7a7b2dSGreg Roach					<a href="#" id="passwd_click">' . I18N::translate('Forgot password?') . '</a>
88e2a378d3SGreg Roach				</div>';
89e2a378d3SGreg Roach			if (Site::getPreference('USE_REGISTRATION_MODULE')) {
90762f8fb2SGreg Roach				$content .= '<div id="register-link"><a href="' . WT_LOGIN_URL . '?action=register">' . I18N::translate('Request a new user account') . '</a></div>';
91e2a378d3SGreg Roach			}
92e2a378d3SGreg Roach		$content .= '</form>'; // close "login-form"
93e2a378d3SGreg Roach
94e2a378d3SGreg Roach		// hidden New Password block
95e2a378d3SGreg Roach		$content .= '<div id="new_passwd">
96e2a378d3SGreg Roach			<form id="new_passwd_form" name="new_passwd_form" action="' . WT_LOGIN_URL . '" method="post">
97e2a378d3SGreg Roach			<input type="hidden" name="time" value="">
98e2a378d3SGreg Roach			<input type="hidden" name="action" value="requestpw">
997555da9cSGreg Roach			<h4>' . I18N::translate('Request a new password') . '</h4>
100e2a378d3SGreg Roach			<div>
101e2a378d3SGreg Roach				<label for="new_passwd_username">' . I18N::translate('Username or email address') .
102e2a378d3SGreg Roach					'<input type="text" id="new_passwd_username" name="new_passwd_username" value="">
103e2a378d3SGreg Roach				</label>
104e2a378d3SGreg Roach			</div>
105e2a378d3SGreg Roach			<div><input type="submit" value="' . I18N::translate('continue') . '"></div>
106e2a378d3SGreg Roach			</form>
107e2a378d3SGreg Roach		</div>'; //"new_passwd"
108e2a378d3SGreg Roach		$content .= '</div>'; //"login-box"
109e2a378d3SGreg Roach		}
110e2a378d3SGreg Roach
111e2a378d3SGreg Roach		if ($template) {
112e2a378d3SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
113e2a378d3SGreg Roach		} else {
114e2a378d3SGreg Roach			return $content;
115e2a378d3SGreg Roach		}
116e2a378d3SGreg Roach	}
117e2a378d3SGreg Roach
118e2a378d3SGreg Roach	/** {@inheritdoc} */
119e2a378d3SGreg Roach	public function loadAjax() {
120e2a378d3SGreg Roach		return false;
121e2a378d3SGreg Roach	}
122e2a378d3SGreg Roach
123e2a378d3SGreg Roach	/** {@inheritdoc} */
124e2a378d3SGreg Roach	public function isUserBlock() {
125e2a378d3SGreg Roach		return true;
126e2a378d3SGreg Roach	}
127e2a378d3SGreg Roach
128e2a378d3SGreg Roach	/** {@inheritdoc} */
129e2a378d3SGreg Roach	public function isGedcomBlock() {
130e2a378d3SGreg Roach		return true;
131e2a378d3SGreg Roach	}
132e2a378d3SGreg Roach
13376692c8bSGreg Roach	/**
13476692c8bSGreg Roach	 * An HTML form to edit block settings
13576692c8bSGreg Roach	 *
13676692c8bSGreg Roach	 * @param int $block_id
13776692c8bSGreg Roach	 */
138e2a378d3SGreg Roach	public function configureBlock($block_id) {
139e2a378d3SGreg Roach	}
140e2a378d3SGreg Roach}
141