summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-07-05 15:56:35 -0400
committerJune McEnroe <june@causal.agency>2021-07-05 15:56:52 -0400
commit75775ded84f8e70243eea0dd42ddf55f9d13fb82 (patch)
tree3b7f881560332bdf5c8aec17072446b57192db14 /bin
parentDon't run sctd (diff)
downloadsrc-75775ded84f8e70243eea0dd42ddf55f9d13fb82.tar.gz
src-75775ded84f8e70243eea0dd42ddf55f9d13fb82.zip
Add patreon to sup
Diffstat (limited to '')
-rw-r--r--bin/man1/sup.13
-rw-r--r--bin/sup.sh47
2 files changed, 49 insertions, 1 deletions
diff --git a/bin/man1/sup.1 b/bin/man1/sup.1
index 4b266e06..b413a468 100644
--- a/bin/man1/sup.1
+++ b/bin/man1/sup.1
@@ -1,4 +1,4 @@
-.Dd February 21, 2021
+.Dd July  5, 2021
 .Dt SUP 1
 .Os
 .
@@ -34,6 +34,7 @@ The following services are supported:
 .Cm freebsdbugzilla ,
 .Cm liberapay ,
 .Cm lobsters ,
+.Cm patreon ,
 .Cm tildenews .
 .
 .Pp
diff --git a/bin/sup.sh b/bin/sup.sh
index b7f28bc7..1772f312 100644
--- a/bin/sup.sh
+++ b/bin/sup.sh
@@ -10,6 +10,16 @@ generate() {
 copy() {
 	printf '%s' "$1" | pbcopy
 }
+unwrap() {
+	sed '
+		:x
+		/=$/ {
+			N
+			s/=\n//g
+			bx
+		}
+	'
+}
 
 asciinema() {
 	echo 'Fetching CSRF token...'
@@ -160,6 +170,43 @@ lobsters() {
 	open "${lobstersBase}/login"
 }
 
+patreon() {
+	readonly patreonAPI='https://www.patreon.com/api'
+	echo 'Submitting form...'
+	curl -Ss -X POST -d @- \
+		-H 'Content-Type: application/vnd.api+json' \
+		"${patreonAPI}/auth/forgot-password?json-api-version=1.0" <<-EOF
+		{"data":{"email":"${email}"}}
+		EOF
+	echo 'Waiting for email...'
+	url=$(
+		git fetch-email -i -M Trash \
+			-F 'password@patreon.com' -T "${email}" \
+			-S 'Patreon Password Reset' |
+		unwrap |
+		grep -o -m 1 'https://email[.]mailgun[.]patreon[.]com/.*'
+	)
+	echo 'Fetching token...'
+	location=$(curl -ISs --url "${url}" | grep -i '^Location: ' | tr -d '\r')
+	u=$(echo "${location}" | sed 's/.*[?&]u=\([^&]*\).*/\1/')
+	sec=$(echo "${location}" | sed 's/.*[?&]sec=\([^&]*\).*/\1/')
+	password=$(generate)
+	echo 'Setting password...'
+	curl -Ss -X POST -d @- \
+		-H 'Content-Type: application/vnd.api+json' \
+		"${patreonAPI}/auth/forgot-password/change?json-api-version=1.0" <<-EOF
+		{
+			"data":{
+				"user_id":"${u}",
+				"security_token":"${sec}",
+				"password":"${password}"
+			}
+		}
+		EOF
+	copy "${password}"
+	open 'https://www.patreon.com/login'
+}
+
 tildenews() {
 	lobstersBase='https://tilde.news'
 	lobstersFrom='nobody@tilde.news'