From be5020ad28b6ef0811d2c318f1bdf66c3c90ac67 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 25 Oct 2023 04:39:13 +0000 Subject: [PATCH] WIP retooling bc of permission issue --- cmd/emailtouser/main.go | 9 +++++++++ cmd/help/main.go | 24 +++++++++++++++++++++++- sql/create_codes_db.sql | 7 +++++++ sql/create_town_db.sql | 8 -------- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 cmd/emailtouser/main.go create mode 100644 sql/create_codes_db.sql diff --git a/cmd/emailtouser/main.go b/cmd/emailtouser/main.go new file mode 100644 index 0000000..26c18ea --- /dev/null +++ b/cmd/emailtouser/main.go @@ -0,0 +1,9 @@ +package main + +import "fmt" + +// TODO accept an email as an argument, write out a username associated with it or throw an error + +func main() { + fmt.Println("TODO") +} diff --git a/cmd/help/main.go b/cmd/help/main.go index 6ec7294..f10af2f 100644 --- a/cmd/help/main.go +++ b/cmd/help/main.go @@ -22,6 +22,15 @@ import ( // TODO put colorscheme, prompting stuff into own packages for use in the other commands. would be good to get off of survey. +func connectDB() (*sql.DB, error) { + db, err := sql.Open("sqlite3", "/town/var/codes/codes.db?mode=rw") + if err != nil { + return nil, err + } + + return db, nil +} + type colorScheme struct { Header func(string) string Subtitle func(string) string @@ -108,7 +117,7 @@ func (p *Prompter) Select(prompt string, opts []string) (int, error) { } func _main(cs colorScheme) error { - db, err := towndb.ConnectDB() + db, err := connectDB() if err != nil { return fmt.Errorf("could not connect to database. please let root@tilde.town know about this.") } @@ -149,6 +158,12 @@ func _main(cs colorScheme) error { return nil } +func userToEmail(email string) (string, error) { + // TODO shell out to /town/src/town/cmd/usertoemail + // TODO add to sudoers + return "", nil +} + func collectEmail(db *sql.DB, cs colorScheme, p *Prompter) error { fmt.Println(cs.Header("We can send a authorization code to an email associated with your town account.")) email, err := p.String("email to send reset code to?") @@ -283,6 +298,13 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error { return nil } +// TODO db plan: + +// add new db, codes (modeled after invites) +// add new helper, emailtouser, that can access town.db and report on what user matches a given email +// drop table from town.db +// update sshapps.md + func main() { cs := newColorScheme() err := _main(cs) diff --git a/sql/create_codes_db.sql b/sql/create_codes_db.sql new file mode 100644 index 0000000..ff9c649 --- /dev/null +++ b/sql/create_codes_db.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS auth_codes ( + id INTEGER PRIMARY KEY, + created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')), + code TEXT, + email TEXT, + used INTEGER DEFAULT 0 +); diff --git a/sql/create_town_db.sql b/sql/create_town_db.sql index 3da22d2..169674a 100644 --- a/sql/create_town_db.sql +++ b/sql/create_town_db.sql @@ -32,11 +32,3 @@ CREATE TABLE IF NOT EXISTS notes ( FOREIGN KEY (author) REFERENCES users(author) ); - -CREATE TABLE IF NOT EXISTS auth_codes ( - id INTEGER PRIMARY KEY, - created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')), - code TEXT, - email TEXT, - used INTEGER DEFAULT 0 -);