From de04ec6e834608561ac03aac1aa4bb7d204cc1bd Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 10 Dec 2019 14:03:44 -0500 Subject: [PATCH] deluser command --- docs/changelog.txt | 2 ++ docs/honk.8 | 4 ++++ honk.go | 6 ++++++ util.go | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index f894e6f..1afcf8d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ deluser command. + + @media print styles. + Disable overscroll (pull down) refresh. diff --git a/docs/honk.8 b/docs/honk.8 index 0d1b432..f5a85c6 100644 --- a/docs/honk.8 +++ b/docs/honk.8 @@ -111,6 +111,10 @@ This is discouraged. Passwords may be reset with the .Ic chpass Ar username command. +.Pp +Users may be deleted with the +.Ic deluser Ar username +command. .Ss Maintenance The database may grow large over time. The diff --git a/honk.go b/honk.go index 7b46f6c..2c15ea5 100644 --- a/honk.go +++ b/honk.go @@ -252,6 +252,12 @@ func main() { } case "adduser": adduser() + case "deluser": + if len(args) < 2 { + fmt.Printf("usage: honk deluser username\n") + return + } + deluser(args[1]) case "chpass": chpass() case "cleanup": diff --git a/util.go b/util.go index cf9b407..b57b75a 100644 --- a/util.go +++ b/util.go @@ -210,6 +210,29 @@ func adduser() { os.Exit(0) } +func deluser(username string) { + user, _ := butwhatabout(username) + if user == nil { + log.Printf("no userfound") + return + } + userid := user.ID + db := opendatabase() + + where := " where honkid in (select honkid from honks where userid = ?)" + doordie(db, "delete from donks"+where, userid) + doordie(db, "delete from onts"+where, userid) + doordie(db, "delete from honkmeta"+where, userid) + + doordie(db, "delete from honks where userid = ?", userid) + doordie(db, "delete from honkers where userid = ?", userid) + doordie(db, "delete from zonkers where userid = ?", userid) + doordie(db, "delete from doovers where userid = ?", userid) + doordie(db, "delete from hfcs where userid = ?", userid) + doordie(db, "delete from auth where userid = ?", userid) + doordie(db, "delete from users where userid = ?", userid) +} + func chpass() { if len(os.Args) < 3 { fmt.Printf("need a username\n")