xref: /webtrees/app/Module/LoginBlockModule.php (revision 552fa1fb475f138699c21e1e8883a931f5d9efd9)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
4369c0ce6SGreg Roach * Copyright (C) 2016 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	 */
4676692c8bSGreg Roach	public function getBlock($block_id, $template = true, $cfg = array()) {
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() {
53e2a378d3SGreg Roach				jQuery("#new_passwd").slideToggle(100, function() {
54e2a378d3SGreg Roach					jQuery("#new_passwd_username").focus();
55e2a378d3SGreg Roach				});
56e2a378d3SGreg Roach				return false;
57e2a378d3SGreg Roach			});
58e2a378d3SGreg Roach		');
59e2a378d3SGreg Roach
60e2a378d3SGreg Roach		if (Auth::check()) {
61cdc90107SGreg Roach			$title   = I18N::translate('Sign out');
623d7dce6aSGreg Roach			$content = '<div class="center"><form method="post" action="logout.php" name="logoutform" onsubmit="return true;">';
63390c61f3SGreg Roach			$content .= '<br>' . I18N::translate('You are signed in as %s.', '<a href="edituser.php" class="name2">' . Auth::user()->getRealNameHtml() . '</a>') . '<br><br>';
64*552fa1fbSGreg Roach			$content .= '<input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign out') . '">';
65e2a378d3SGreg Roach
66e2a378d3SGreg Roach			$content .= '<br><br></form></div>';
67e2a378d3SGreg Roach		} else {
68cdc90107SGreg Roach			$title   = I18N::translate('Sign in');
69e2a378d3SGreg Roach			$content = '<div id="login-box">
7067536fc1SGreg Roach				<form id="login-form" name="login-form" method="post" action="' . WT_LOGIN_URL . '">
7167536fc1SGreg Roach				<input type="hidden" name="action" value="login">';
72e2a378d3SGreg Roach			$content .= '<div>
73e2a378d3SGreg Roach				<label for="username">' . I18N::translate('Username') .
74e2a378d3SGreg Roach					'<input type="text" id="username" name="username" class="formField">
75e2a378d3SGreg Roach				</label>
76e2a378d3SGreg Roach				</div>
77e2a378d3SGreg Roach				<div>
78e2a378d3SGreg Roach					<label for="password">' . I18N::translate('Password') .
79e2a378d3SGreg Roach						'<input type="password" id="password" name="password" class="formField">
80e2a378d3SGreg Roach					</label>
81e2a378d3SGreg Roach				</div>
82e2a378d3SGreg Roach				<div>
83*552fa1fbSGreg Roach					<input type="submit" value="' . /* I18N: A button label. */ I18N::translate('sign in') . '">
84e2a378d3SGreg Roach				</div>
85e2a378d3SGreg Roach				<div>
868d7a7b2dSGreg Roach					<a href="#" id="passwd_click">' . I18N::translate('Forgot password?') . '</a>
87e2a378d3SGreg Roach				</div>';
88e2a378d3SGreg Roach			if (Site::getPreference('USE_REGISTRATION_MODULE')) {
89cdc90107SGreg Roach				$content .= '<div><a href="' . WT_LOGIN_URL . '?action=register">' . I18N::translate('Request a new user account') . '</a></div>';
90e2a378d3SGreg Roach			}
91e2a378d3SGreg Roach		$content .= '</form>'; // close "login-form"
92e2a378d3SGreg Roach
93e2a378d3SGreg Roach		// hidden New Password block
94e2a378d3SGreg Roach		$content .= '<div id="new_passwd">
95e2a378d3SGreg Roach			<form id="new_passwd_form" name="new_passwd_form" action="' . WT_LOGIN_URL . '" method="post">
96e2a378d3SGreg Roach			<input type="hidden" name="time" value="">
97e2a378d3SGreg Roach			<input type="hidden" name="action" value="requestpw">
987555da9cSGreg Roach			<h4>' . I18N::translate('Request a new password') . '</h4>
99e2a378d3SGreg Roach			<div>
100e2a378d3SGreg Roach				<label for="new_passwd_username">' . I18N::translate('Username or email address') .
101e2a378d3SGreg Roach					'<input type="text" id="new_passwd_username" name="new_passwd_username" value="">
102e2a378d3SGreg Roach				</label>
103e2a378d3SGreg Roach			</div>
104e2a378d3SGreg Roach			<div><input type="submit" value="' . I18N::translate('continue') . '"></div>
105e2a378d3SGreg Roach			</form>
106e2a378d3SGreg Roach		</div>'; //"new_passwd"
107e2a378d3SGreg Roach		$content .= '</div>'; //"login-box"
108e2a378d3SGreg Roach		}
109e2a378d3SGreg Roach
110e2a378d3SGreg Roach		if ($template) {
111e2a378d3SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
112e2a378d3SGreg Roach		} else {
113e2a378d3SGreg Roach			return $content;
114e2a378d3SGreg Roach		}
115e2a378d3SGreg Roach	}
116e2a378d3SGreg Roach
117e2a378d3SGreg Roach	/** {@inheritdoc} */
118e2a378d3SGreg Roach	public function loadAjax() {
119e2a378d3SGreg Roach		return false;
120e2a378d3SGreg Roach	}
121e2a378d3SGreg Roach
122e2a378d3SGreg Roach	/** {@inheritdoc} */
123e2a378d3SGreg Roach	public function isUserBlock() {
124e2a378d3SGreg Roach		return true;
125e2a378d3SGreg Roach	}
126e2a378d3SGreg Roach
127e2a378d3SGreg Roach	/** {@inheritdoc} */
128e2a378d3SGreg Roach	public function isGedcomBlock() {
129e2a378d3SGreg Roach		return true;
130e2a378d3SGreg Roach	}
131e2a378d3SGreg Roach
13276692c8bSGreg Roach	/**
13376692c8bSGreg Roach	 * An HTML form to edit block settings
13476692c8bSGreg Roach	 *
13576692c8bSGreg Roach	 * @param int $block_id
13676692c8bSGreg Roach	 */
137e2a378d3SGreg Roach	public function configureBlock($block_id) {
138e2a378d3SGreg Roach	}
139e2a378d3SGreg Roach}
140