code processing, TODOs
parent
5c2142f6e7
commit
6fa11aba8e
|
@ -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(cs.Header("redeem an auth code and add a new public key"))
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
c, err := p.String("paste your auth code:")
|
c, err := p.String("paste your auth code:")
|
||||||
|
// TODO add Error to cs
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO log
|
// TODO log
|
||||||
|
// TODO print an error, return nil
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
parts, err := codes.Decode(c)
|
parts, err := codes.Decode(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO log
|
// TODO log
|
||||||
|
// TODO print an error, return nil
|
||||||
return err
|
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 verify code
|
||||||
// TODO accept key
|
// TODO accept key
|
||||||
|
|
|
@ -210,15 +210,15 @@ func (c *AuthCode) Insert(db *sql.DB) error {
|
||||||
|
|
||||||
func (c *AuthCode) Hydrate(db *sql.DB) error {
|
func (c *AuthCode) Hydrate(db *sql.DB) error {
|
||||||
stmt, err := db.Prepare(`
|
stmt, err := db.Prepare(`
|
||||||
SELECT id, email, used, created
|
SELECT id, used, created
|
||||||
FROM auth_codes
|
FROM auth_codes
|
||||||
WHERE code = ?`)
|
WHERE code = ? AND email = ?`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
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
|
// TODO other auth code as needed
|
||||||
|
|
Loading…
Reference in New Issue