check for double subscription

This commit is contained in:
Ted Unangst 2019-10-06 21:43:35 -04:00
parent d5b99e2b9a
commit 9ad6418c16
2 changed files with 18 additions and 4 deletions

View File

@ -42,7 +42,7 @@ function expandstuff() {
{{ if eq .Flavor "sub" }} {{ if eq .Flavor "sub" }}
<p>unsub: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off> <p>unsub: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off>
{{ else }} {{ else }}
<p>resub: <input type="text" name="goodbye" placeholder="press X" value="" autocomplete=off> <p>(re)sub: <input type="text" name="goodbye" placeholder="press X" value="" autocomplete=off>
{{ end }} {{ end }}
<p><button name="save" value="save">save</button> <p><button name="save" value="save">save</button>
</form> </form>

20
web.go
View File

@ -17,6 +17,7 @@ package main
import ( import (
"bytes" "bytes"
"database/sql"
"fmt" "fmt"
"html" "html"
"html/template" "html/template"
@ -1181,7 +1182,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
goodbye := r.FormValue("goodbye") goodbye := r.FormValue("goodbye")
if goodbye == "F" { if goodbye == "F" {
db := opendatabase() db := opendatabase()
row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('dub')",
honkerid, u.UserID) honkerid, u.UserID)
err := row.Scan(&url) err := row.Scan(&url)
if err != nil { if err != nil {
@ -1202,7 +1203,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
} }
if goodbye == "X" { if goodbye == "X" {
db := opendatabase() db := opendatabase()
row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')",
honkerid, u.UserID) honkerid, u.UserID)
err := row.Scan(&url) err := row.Scan(&url)
if err != nil { if err != nil {
@ -1241,10 +1242,23 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
p, err := investigate(url) p, err := investigate(url)
if err != nil { if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError) http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
log.Printf("failed to investigate honker") log.Printf("failed to investigate honker: %s", err)
return return
} }
url = p.XID url = p.XID
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)
var x string
err = row.Scan(&x)
if err != sql.ErrNoRows {
http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError)
if err != nil {
log.Printf("honker scan err: %s", err)
}
return
}
if name == "" { if name == "" {
name = p.Handle name = p.Handle
} }