fill in emailtouser

vilmibm 2023-10-25 08:24:23 +00:00
parent be5020ad28
commit b1ff57ba58
2 changed files with 35 additions and 3 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ cmd/registeruser/registeruser
cmd/stats/stats
cmd/appendkeyfile/appendkeyfile
cmd/help/help
cmd/emailtouser/emailtouser

View File

@ -1,9 +1,40 @@
package main
import "fmt"
import (
"errors"
"fmt"
"os"
// TODO accept an email as an argument, write out a username associated with it or throw an error
"git.tilde.town/tildetown/town/towndb"
)
func _main(args []string) error {
if len(args) < 2 {
return errors.New("need email")
}
email := args[1]
db, err := towndb.ConnectDB()
if err != nil {
return err
}
user, err := towndb.UserForEmail(db, email)
if err != nil {
return err
}
if user == nil {
return errors.New("email does not correspond to user")
}
fmt.Println(user.Username)
return nil
}
func main() {
fmt.Println("TODO")
if err := _main(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
}