Convert subscription requests to POST

This commit is contained in:
spikecodes 2021-01-30 21:21:46 -08:00
parent 7933d840b3
commit 269bb0bfb6
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
5 changed files with 64 additions and 63 deletions

16
Cargo.lock generated
View File

@ -480,9 +480,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.5.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"
checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9"
[[package]]
name = "byteorder"
@ -531,9 +531,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chunked_transfer"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7477065d45a8fe57167bf3cf8bcd3729b54cfcb81cca49bda2d038ea89ae82ca"
checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]]
name = "const_fn"
@ -628,9 +628,9 @@ dependencies = [
[[package]]
name = "flate2"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129"
checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0"
dependencies = [
"cfg-if 1.0.0",
"crc32fast",
@ -988,9 +988,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.83"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0c4e9c72ee9d69b767adebc5f4788462a3b45624acd919475c92597bcaf4f"
checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
[[package]]
name = "libreddit"

View File

@ -105,7 +105,7 @@ async fn main() -> std::io::Result<()> {
.route("/", web::get().to(subreddit::page))
.route("/{sort:hot|new|top|rising|controversial}/", web::get().to(subreddit::page))
// Handle subscribe/unsubscribe
.route("/{action:subscribe|unsubscribe}/", web::get().to(subreddit::subscriptions))
.route("/{action:subscribe|unsubscribe}/", web::post().to(subreddit::subscriptions))
// View post on subreddit
.service(
web::scope("/comments/{id}/{title}")

View File

@ -250,18 +250,18 @@ aside {
margin-top: 20px;
}
#sub_subscription button {
.subscribe, .unsubscribe {
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
#subscribe {
.subscribe {
color: var(--foreground);
background-color: var(--accent);
}
#unsubscribe {
.unsubscribe {
color: var(--text);
background-color: var(--highlighted);
}
@ -862,7 +862,7 @@ a.search_subreddit:hover {
/* Settings */
#settings {
#settings, #settings > form {
display: flex;
flex-direction: column;
align-items: center;
@ -937,11 +937,8 @@ input[type="submit"] {
margin-right: auto;
}
#settings_subs > li > a {
#settings_subs .unsubscribe {
margin-left: 30px;
padding: 10px 20px;
border-radius: 5px;
background-color: var(--highlighted);
}
/* Markdown */
@ -1018,7 +1015,7 @@ td, th {
@media screen and (max-width: 480px) {
#version { display: none; }
.post {
grid-template: "post_header post_header post_thumbnail" auto
"post_title post_title post_thumbnail" 1fr

View File

@ -8,46 +8,48 @@
{% endblock %}
{% block content %}
<form id="settings" action="/settings" method="POST">
<div class="prefs">
<p>Appearance</p>
<div id="theme">
<label for="theme">Theme:</label>
<select name="theme">
{% call utils::options(prefs.theme, ["system", "light", "dark"], "system") %}
</select>
<div id="settings">
<form action="/settings" method="POST">
<div class="prefs">
<p>Appearance</p>
<div id="theme">
<label for="theme">Theme:</label>
<select name="theme">
{% call utils::options(prefs.theme, ["system", "light", "dark"], "system") %}
</select>
</div>
<p>Interface</p>
<div id="front_page">
<label for="front_page">Front page:</label>
<select name="front_page">
{% call utils::options(prefs.front_page, ["default", "popular", "all"], "default") %}
</select>
</div>
<div id="layout">
<label for="layout">Layout:</label>
<select name="layout">
{% call utils::options(prefs.layout, ["card", "clean", "compact"], "card") %}
</select>
</div>
<div id="wide">
<label for="wide">Wide UI:</label>
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
</div>
<p>Content</p>
<div id="comment_sort">
<label for="comment_sort">Default comment sort:</label>
<select name="comment_sort">
{% call utils::options(prefs.comment_sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %}
</select>
</div>
<div id="hide_nsfw">
<label for="hide_nsfw">Hide NSFW posts:</label>
<input type="checkbox" name="hide_nsfw" {% if prefs.hide_nsfw == "on" %}checked{% endif %}>
</div>
</div>
<p>Interface</p>
<div id="front_page">
<label for="front_page">Front page:</label>
<select name="front_page">
{% call utils::options(prefs.front_page, ["default", "popular", "all"], "default") %}
</select>
</div>
<div id="layout">
<label for="layout">Layout:</label>
<select name="layout">
{% call utils::options(prefs.layout, ["card", "clean", "compact"], "card") %}
</select>
</div>
<div id="wide">
<label for="wide">Wide UI:</label>
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
</div>
<p>Content</p>
<div id="comment_sort">
<label for="comment_sort">Default comment sort:</label>
<select name="comment_sort">
{% call utils::options(prefs.comment_sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %}
</select>
</div>
<div id="hide_nsfw">
<label for="hide_nsfw">Hide NSFW posts:</label>
<input type="checkbox" name="hide_nsfw" {% if prefs.hide_nsfw == "on" %}checked{% endif %}>
</div>
</div>
<p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
<input id="save" type="submit" value="Save">
<p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
<input id="save" type="submit" value="Save">
</form>
{% if prefs.subs.len() > 0 %}
<aside class="prefs">
<p>Subscribed Subreddits</p>
@ -55,12 +57,14 @@
{% for sub in prefs.subs %}
<li>
<span>{{ sub }}</span>
<a href="/r/{{ sub }}/unsubscribe/?redirect=/settings">Unsubscribe</a>
<form action="/r/{{ sub }}/unsubscribe/?redirect=/settings" method="POST">
<button class="unsubscribe">Unsubscribe</button>
</form>
</li>
{% endfor %}
</ul>
</aside>
{% endif %}
</form>
</div>
{% endblock %}

View File

@ -127,12 +127,12 @@
</div>
<div id="sub_subscription">
{% if prefs.subs.contains(sub.name) %}
<form action="/r/{{ sub.name }}/unsubscribe">
<button id="unsubscribe">Unsubscribe</button>
<form action="/r/{{ sub.name }}/unsubscribe" method="POST">
<button class="unsubscribe">Unsubscribe</button>
</form>
{% else %}
<form action="/r/{{ sub.name }}/subscribe">
<button id="subscribe">Subscribe</button>
<form action="/r/{{ sub.name }}/subscribe" method="POST">
<button class="subscribe">Subscribe</button>
</form>
{% endif %}
</div>