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

View File

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

View File

@ -250,18 +250,18 @@ aside {
margin-top: 20px; margin-top: 20px;
} }
#sub_subscription button { .subscribe, .unsubscribe {
padding: 10px 20px; padding: 10px 20px;
border-radius: 5px; border-radius: 5px;
cursor: pointer; cursor: pointer;
} }
#subscribe { .subscribe {
color: var(--foreground); color: var(--foreground);
background-color: var(--accent); background-color: var(--accent);
} }
#unsubscribe { .unsubscribe {
color: var(--text); color: var(--text);
background-color: var(--highlighted); background-color: var(--highlighted);
} }
@ -862,7 +862,7 @@ a.search_subreddit:hover {
/* Settings */ /* Settings */
#settings { #settings, #settings > form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
@ -937,11 +937,8 @@ input[type="submit"] {
margin-right: auto; margin-right: auto;
} }
#settings_subs > li > a { #settings_subs .unsubscribe {
margin-left: 30px; margin-left: 30px;
padding: 10px 20px;
border-radius: 5px;
background-color: var(--highlighted);
} }
/* Markdown */ /* Markdown */

View File

@ -8,46 +8,48 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<form id="settings" action="/settings" method="POST"> <div id="settings">
<div class="prefs"> <form action="/settings" method="POST">
<p>Appearance</p> <div class="prefs">
<div id="theme"> <p>Appearance</p>
<label for="theme">Theme:</label> <div id="theme">
<select name="theme"> <label for="theme">Theme:</label>
{% call utils::options(prefs.theme, ["system", "light", "dark"], "system") %} <select name="theme">
</select> {% 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> </div>
<p>Interface</p> <p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
<div id="front_page"> <input id="save" type="submit" value="Save">
<label for="front_page">Front page:</label> </form>
<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">
{% if prefs.subs.len() > 0 %} {% if prefs.subs.len() > 0 %}
<aside class="prefs"> <aside class="prefs">
<p>Subscribed Subreddits</p> <p>Subscribed Subreddits</p>
@ -55,12 +57,14 @@
{% for sub in prefs.subs %} {% for sub in prefs.subs %}
<li> <li>
<span>{{ sub }}</span> <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> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</aside> </aside>
{% endif %} {% endif %}
</form> </div>
{% endblock %} {% endblock %}

View File

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