all repos — honk @ 56da28ed8e2d4a1847eb873d7e146de806ce1e86

my fork of honk

check for double subscription
Ted Unangst tedu@tedunangst.com
Sun, 06 Oct 2019 21:43:35 -0400
commit

56da28ed8e2d4a1847eb873d7e146de806ce1e86

parent

454608c14f29a74b2835ce657e08524581247ca6

2 files changed, 18 insertions(+), 4 deletions(-)

jump to
M views/honkers.htmlviews/honkers.html

@@ -42,7 +42,7 @@ <p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}">

{{ if eq .Flavor "sub" }} <p>unsub: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off> {{ 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 }} <p><button name="save" value="save">save</button> </form>
M web.goweb.go

@@ -17,6 +17,7 @@ package main

import ( "bytes" + "database/sql" "fmt" "html" "html/template"

@@ -1181,7 +1182,7 @@ if honkerid > 0 {

goodbye := r.FormValue("goodbye") if goodbye == "F" { 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) err := row.Scan(&url) if err != nil {

@@ -1202,7 +1203,7 @@ return

} if goodbye == "X" { 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) err := row.Scan(&url) if err != nil {

@@ -1241,10 +1242,23 @@ }

p, err := investigate(url) if err != nil { http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError) - log.Printf("failed to investigate honker") + log.Printf("failed to investigate honker: %s", err) return } 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 == "" { name = p.Handle }