code processing, TODOs

trunk
vilmibm 2023-10-24 19:23:35 +00:00
parent 5c2142f6e7
commit 6fa11aba8e
2 changed files with 22 additions and 6 deletions

View File

@ -205,20 +205,36 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error {
fmt.Println(cs.Header("redeem an auth code and add a new public key"))
fmt.Println()
c, err := p.String("paste your auth code:")
// TODO add Error to cs
if err != nil {
// TODO log
// TODO print an error, return nil
return err
}
parts, err := codes.Decode(c)
if err != nil {
// TODO log
// TODO print an error, return nil
return err
}
code := parts[0]
email := parts[1]
fmt.Println(code, email)
code := &towndb.AuthCode{
Code: parts[0],
Email: parts[1],
}
err = code.Hydrate(db)
if err != nil {
// TODO log
// TODO print an error, return an opaque error about db
return err
}
if code.Used {
fmt.Println("That code has already been redeemed. You'll have to request a new one.")
return nil
}
// TODO verify code
// TODO accept key

View File

@ -210,15 +210,15 @@ func (c *AuthCode) Insert(db *sql.DB) error {
func (c *AuthCode) Hydrate(db *sql.DB) error {
stmt, err := db.Prepare(`
SELECT id, email, used, created
SELECT id, used, created
FROM auth_codes
WHERE code = ?`)
WHERE code = ? AND email = ?`)
if err != nil {
return err
}
defer stmt.Close()
return stmt.QueryRow(c.Code).Scan(&c.ID, &c.Email, &c.Used, &c.Created)
return stmt.QueryRow(c.Code).Scan(&c.ID, &c.Used, &c.Created)
}
// TODO other auth code as needed