Browse Source

Make logout a post

master
Dylan Baker 3 years ago
parent
commit
775438598c
3 changed files with 19 additions and 13 deletions
  1. 1
    1
      src/main.rs
  2. 1
    1
      templates/index.html
  3. 17
    11
      templates/layout.html

+ 1
- 1
src/main.rs View File

@@ -176,7 +176,7 @@ async fn main() -> std::io::Result<()> {
176 176
         });
177 177
 
178 178
     app.at("/logout")
179
-        .get(|mut req: tide::Request<()>| async move {
179
+        .post(|mut req: tide::Request<()>| async move {
180 180
             req.session_mut().remove("logged_in");
181 181
             req.session_mut().insert("logged_in", false)?;
182 182
             Ok(tide::Redirect::new("/"))

+ 1
- 1
templates/index.html View File

@@ -12,7 +12,7 @@
12 12
     <textarea class="form__textarea" name="body" required></textarea>
13 13
   </div>
14 14
   <div class="form__field">
15
-    <input class="form__button" type="submit" value="Post" />
15
+    <input class="btn" type="submit" value="Post" />
16 16
   </div>
17 17
 </form>
18 18
 {% endif %}

+ 17
- 11
templates/layout.html View File

@@ -27,13 +27,21 @@
27 27
         text-decoration: none;
28 28
       }
29 29
 
30
-      .header,
30
+      .btn {
31
+        cursor: pointer;
32
+        padding: 0.15em 0.3em;
33
+      }
34
+
31 35
       .container {
32 36
         margin: auto;
33 37
         max-width: 800px;
34 38
         padding: 1em;
35 39
       }
36 40
 
41
+      .header {
42
+        margin: 1em 0;
43
+      }
44
+
37 45
       .form__field {
38 46
         margin: 1em 0;
39 47
       }
@@ -56,11 +64,7 @@
56 64
         resize: vertical;
57 65
       }
58 66
 
59
-      .form__button {
60
-        padding: 0.25em 1em;
61
-      }
62
-
63
-      .post {
67
+      .post:not(:last-child) {
64 68
         margin: 3em 0;
65 69
       }
66 70
 
@@ -111,12 +115,14 @@
111 115
     </style>
112 116
   </head>
113 117
   <body>
114
-    <header class="header">
115
-      {% if logged_in %}
116
-      <a href="/logout">logout</a>
117
-      {% endif %}
118
-    </header>
119 118
     <div class="container">
119
+      <header class="header">
120
+        {% if logged_in %}
121
+        <form action="/logout" method="POST">
122
+          <input class="btn" type="submit" value="Log out" />
123
+        </form>
124
+        {% endif %}
125
+      </header>
120 126
       {% block content %} {% endblock %}
121 127
     </div>
122 128
   </body>

Loading…
Cancel
Save