2 // PukiWiki - Yet another WikiWikiWeb clone
3 // Copyright 2015-2017 PukiWiki Development Team
4 // License: GPL v2 or (at your option) any later version
8 function plugin_loginform_inline()
10 $logout_param = '?plugin=basicauthlogout';
11 return '<a href="' . htmlsc(get_base_uri() . $logout_param) . '">Log out</a>';
14 function plugin_loginform_convert()
16 return '<div>' . plugin_basicauthlogout_inline() . '</div>';
19 function plugin_loginform_action()
21 global $auth_user, $auth_type, $_loginform_messages;
22 $page = isset($_GET['page']) ? $_GET['page'] : '';
23 $pcmd = isset($_GET['pcmd']) ? $_GET['pcmd'] : '';
24 $url_after_login = isset($_GET['url_after_login']) ? $_GET['url_after_login'] : '';
25 $page_after_login = $page;
26 if (!$url_after_login) {
27 $page_after_login = $page;
29 $action_url = get_base_uri() . '?plugin=loginform'
30 . '&page=' . rawurlencode($page)
31 . ($url_after_login ? '&url_after_login=' . rawurlencode($url_after_login) : '')
32 . ($page_after_login ? '&page_after_login=' . rawurlencode($page_after_login) : '');
33 $username = isset($_POST['username']) ? $_POST['username'] : '';
34 $password = isset($_POST['password']) ? $_POST['password'] : '';
35 $isset_user_credential = $username || $password ;
36 if ($username && $password && form_auth($username, $password)) {
37 // Sign in successfully completed
38 form_auth_redirect($url_after_login, $page_after_login);
41 if ($pcmd === 'logout') {
45 header('WWW-Authenticate: Basic realm="Please cancel to log out"');
46 header('HTTP/1.0 401 Unauthorized');
49 case AUTH_TYPE_EXTERNAL:
53 session_regenerate_id(true); // require: PHP5.1+
60 'body' => 'Logged out completely<br>'
61 . '<a href="'. get_page_uri($page) . '">'
83 .loginform .login-button-container {
86 .loginform .loginbutton {
89 .loginform .errormessage {
93 <div class="loginformcontainer">
94 <form name="loginform" class="loginform" action="<?php echo htmlsc($action_url) ?>" method="post">
96 <table style="border:0">
99 <td class="label"><label for="_plugin_loginform_username"><?php echo htmlsc($_loginform_messages['username']) ?></label></td>
100 <td><input type="text" name="username" value="<?php echo htmlsc($username) ?>" id="_plugin_loginform_username"></td>
103 <td class="label"><label for="_plugin_loginform_password"><?php echo htmlsc($_loginform_messages['password']) ?></label></td>
104 <td><input type="password" name="password" id="_plugin_loginform_password"></td>
106 <?php if ($isset_user_credential): ?>
109 <td class="errormessage"><?php echo $_loginform_messages['invalid_username_or_password'] ?></td>
114 <td class="login-button-container"><input type="submit" value="<?php echo htmlsc($_loginform_messages['login']) ?>" class="loginbutton"></td>
124 window.addEventListener && window.addEventListener("DOMContentLoaded", function() {
125 var f = window.document.forms.loginform;
127 console.log(f.username);
128 console.log(f.password);
129 if (f && f.username && f.password) {
130 if (f.username.value) {
131 f.password.focus && f.password.focus();
133 f.username.focus && f.username.focus();
140 $body = ob_get_contents();
143 'msg' => $_loginform_messages['login'],