about summary refs log tree commit diff
diff options
context:
space:
mode:
authormaride <maride@darknebu.la>2018-09-08 02:51:39 +0200
committermaride <maride@darknebu.la>2018-09-08 02:51:39 +0200
commit475c5999b57135fefd6129c00e87d7f5aa9a75cc (patch)
tree39143d1517bb7d8fa91e405c749d641f0fc421b4
parent116b1472cf69f920e27da36702a39959bc83b315 (diff)
UI: GET/POST logout fix, avoid 'Wrong credentials' notice when logging out
-rw-r--r--hosted/access.html5
-rw-r--r--hosted/challenges.html5
-rw-r--r--hosted/index.html6
-rw-r--r--hosted/logout.js5
4 files changed, 12 insertions, 9 deletions
diff --git a/hosted/access.html b/hosted/access.html
index 5a25fd0..119ac80 100644
--- a/hosted/access.html
+++ b/hosted/access.html
@@ -5,6 +5,7 @@
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
         <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script>
         <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
+        <script type="text/javascript" src="/files/logout.js"></script>
         <style type="text/css">
             body {
                 overflow-y: scroll;
@@ -29,9 +30,7 @@
                         <a class="nav-link" href="/challenges">Challenges</a>
                     </li>
                 </ul>
-                <form class="form-inline mt-2 mt-md-0" action="/logout" method="post">
-                    <button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Logout</button>
-                </form>
+                <button class="btn btn-outline-danger my-2 my-sm-0" onclick="logoutThenRedirect()">Logout</button>
             </div>
         </nav>
         <main class="container" role="main">
diff --git a/hosted/challenges.html b/hosted/challenges.html
index 165b9a9..e899048 100644
--- a/hosted/challenges.html
+++ b/hosted/challenges.html
@@ -5,6 +5,7 @@
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
         <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script>
         <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
+        <script type="text/javascript" src="/files/logout.js"></script>
         <style type="text/css">
             body {
                 overflow-y: scroll;
@@ -86,9 +87,7 @@
                         <a class="nav-link" href="/challenges">Challenges</a>
                     </li>
                 </ul>
-                <form class="form-inline mt-2 mt-md-0" action="/logout" method="post">
-                    <button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Logout</button>
-                </form>
+                <button class="btn btn-outline-danger my-2 my-sm-0" onclick="logoutThenRedirect()">Logout</button>
             </div>
         </nav>
         <main class="container" role="main">
diff --git a/hosted/index.html b/hosted/index.html
index 70244cc..3b72d95 100644
--- a/hosted/index.html
+++ b/hosted/index.html
@@ -3,6 +3,8 @@
     <head>
         <meta charset="utf-8">
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
+        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
+        <script type="text/javascript" src="/files/logout.js"></script>
     </head>
     <body>
         <nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
@@ -22,9 +24,7 @@
                         <a class="nav-link" href="/challenges">Challenges</a>
                     </li>
                 </ul>
-                <form class="form-inline mt-2 mt-md-0" action="/logout" method="post">
-                    <button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Logout</button>
-                </form>
+                <button class="btn btn-outline-danger my-2 my-sm-0" onclick="logoutThenRedirect()">Logout</button>
             </div>
         </nav>
         <main class="container" role="main">
diff --git a/hosted/logout.js b/hosted/logout.js
new file mode 100644
index 0000000..4dedd4d
--- /dev/null
+++ b/hosted/logout.js
@@ -0,0 +1,5 @@
+function logoutThenRedirect() {
+    $.post("/logout").done(function(data) {
+        window.location.replace("/");
+    });
+}
\ No newline at end of file