3 // PukiWiki - Yet another WikiWikiWeb clone
4 // Copyright (C) 2015 PukiWiki Development Team
5 // License: GPL v2 or (at your option) any later version
9 function plugin_loginform_inline()
11 $logout_param = '?plugin=basicauthlogout';
12 return '<a href="' . htmlsc(get_script_uri() . $logout_param) . '">Log out</a>';
15 function plugin_loginform_convert()
17 return '<div>' . plugin_basicauthlogout_inline() . '</div>';
20 function plugin_loginform_action()
22 global $auth_user, $auth_type, $_loginform_messages;
23 $page = $_GET['page'];
24 $pcmd = $_GET['pcmd'];
25 $url_after_login = $_GET['url_after_login'];
26 $page_after_login = $page;
27 if (!$url_after_login) {
28 $page_after_login = $page;
30 $action_url = get_script_uri() . '?plugin=loginform'
31 . '&page=' . rawurlencode($page)
32 . ($url_after_login ? '&url_after_login=' . rawurlencode($url_after_login) : '')
33 . ($page_after_login ? '&page_after_login=' . rawurlencode($page_after_login) : '');
34 $username = $_POST['username'];
35 $password = $_POST['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:
57 'body' => 'Logged out completely<br>'
58 . '<a href="'. get_script_uri() . '?' . pagename_urlencode($page) . '">'
63 $action_url_html = htmlsc($action_url);
64 $username_html = htmlsc($username);
65 $username_label_html = htmlsc($_loginform_messages['username']);
66 $password_label_html = htmlsc($_loginform_messages['password']);
67 $login_label_html = htmlsc($_loginform_messages['login']);
84 .loginform .login-button-container {
87 .loginform .loginbutton {
91 <div class="loginformcontainer">
92 <form name="loginform" class="loginform" action="$action_url_html" method="post">
94 <table style="border:0">
97 <td class="label"><label for="_plugin_loginform_username">$username_label_html</label></td>
98 <td><input type="text" name="username" value="$username_html" id="_plugin_loginform_username"></td>
101 <td class="label"><label for="_plugin_loginform_password">$password_label_html</label></td>
102 <td><input type="password" name="password" id="_plugin_loginform_password"></td>
106 <td class="login-button-container"><input type="submit" value="$login_label_html" class="loginbutton"></td>
116 window.addEventListener && window.addEventListener("DOMContentLoaded", function() {
117 var f = window.document.forms.loginform;
119 console.log(f.username);
120 console.log(f.password);
121 if (f && f.username && f.password) {
122 if (f.username.value) {
123 f.password.focus && f.password.focus();
125 f.username.focus && f.username.focus();
133 'msg' => $_loginform_messages['login'],