Commit 04b7d7b02fb2ac33adf1a47d93e99da7dfea3f2b

Authored by Neil Blakey-Milner
1 parent 301cb919

Detect if cookies are enabled at login-time. If not, print a message

explaining what is wrong.

Submitted by:	zkrih
SF Tracker:	1202501


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3313 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 11 additions and 1 deletions
presentation/login.php
@@ -37,6 +37,8 @@ $errorMessage = $_REQUEST['errorMessage']; @@ -37,6 +37,8 @@ $errorMessage = $_REQUEST['errorMessage'];
37 37
38 if ($_REQUEST['loginAction'] == "loginForm") { 38 if ($_REQUEST['loginAction'] == "loginForm") {
39 // TODO: build login form using PatternMainPage 39 // TODO: build login form using PatternMainPage
  40 + $cookietest = KTUtil::randomString();
  41 + setcookie("CookieTestCookie", $cookietest, false);
40 print "<html> 42 print "<html>
41 <head> 43 <head>
42 <link rel=\"stylesheet\" href=\"$default->uiUrl/stylesheet.php\"> 44 <link rel=\"stylesheet\" href=\"$default->uiUrl/stylesheet.php\">
@@ -82,6 +84,7 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) { @@ -82,6 +84,7 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) {
82 </td></tr> 84 </td></tr>
83 <input type=\"hidden\" name=\"redirect\" value=\"$redirect\"/> 85 <input type=\"hidden\" name=\"redirect\" value=\"$redirect\"/>
84 <input type=\"hidden\" name=\"loginAction\" value=\"login\">\n 86 <input type=\"hidden\" name=\"loginAction\" value=\"login\">\n
  87 + <input type=\"hidden\" name=\"cookietestinput\" value=\"$cookietest\">\n
85 <tr align=\"right\"><td><input type=\"image\" src=\"" . KTHtml::getLoginButton() . "\" border=\"0\"></td></tr>\n 88 <tr align=\"right\"><td><input type=\"image\" src=\"" . KTHtml::getLoginButton() . "\" border=\"0\"></td></tr>\n
86 <tr><td><font size=\"1\">" . _("System Version") . ": " . $default->systemVersion . "</font></td></tr> 89 <tr><td><font size=\"1\">" . _("System Version") . ": " . $default->systemVersion . "</font></td></tr>
87 </table> 90 </table>
@@ -93,6 +96,12 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) { @@ -93,6 +96,12 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) {
93 // set default url for login failure 96 // set default url for login failure
94 // with redirect appended if set 97 // with redirect appended if set
95 $url = $url . "login.php?loginAction=loginForm" . (isset($redirect) ? "&redirect=" . urlencode($redirect) : ""); 98 $url = $url . "login.php?loginAction=loginForm" . (isset($redirect) ? "&redirect=" . urlencode($redirect) : "");
  99 + $cookieTest = KTUtil::arrayGet($_COOKIE, "CookieTestCookie", null);
  100 + if (is_null($cookieTest) || $cookieTest != KTUtil::arrayGet($_REQUEST, "cookietestinput")) {
  101 + $url .= "&errorMessage=" . urlencode(_("KnowledgeTree requires cookies to work"));
  102 + redirect($url);
  103 + exit(0);
  104 + }
96 105
97 // if requirements are met and we have a username and password to authenticate 106 // if requirements are met and we have a username and password to authenticate
98 if (isset($_REQUEST['fUserName']) && isset($_REQUEST['fPassword']) ) { 107 if (isset($_REQUEST['fUserName']) && isset($_REQUEST['fPassword']) ) {
@@ -164,6 +173,7 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) { @@ -164,6 +173,7 @@ if ($_REQUEST[&#39;loginAction&#39;] == &quot;loginForm&quot;) {
164 redirect($url); 173 redirect($url);
165 } else { 174 } else {
166 // redirect to root 175 // redirect to root
167 - redirect($default->rootUrl); 176 + $url = generateLink("", "");
  177 + redirect($url);
168 } 178 }
169 ?> 179 ?>