WIP retooling bc of permission issue

vilmibm 2023-10-25 04:39:13 +00:00
parent 9bea4257c1
commit be5020ad28
4 changed files with 39 additions and 9 deletions

View File

@ -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")
}

View File

@ -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)

View File

@ -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
);

View File

@ -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
);