mark invites as used

pull/1/head
vilmibm 2023-03-06 20:44:19 +00:00
parent 57115b1c11
commit d407e26917
2 changed files with 26 additions and 4 deletions

View File

@ -135,6 +135,10 @@ if you end up very stuck, you can email root@tilde.town .`, data.Username))
fmt.Println(s) fmt.Println(s)
if err = invite.MarkUsed(inviteDB); err != nil {
return fmt.Errorf("could not mark invite as used: %w", err)
}
// TODO burn invite // TODO burn invite
return nil return nil

View File

@ -3,6 +3,7 @@ package invites
import ( import (
"database/sql" "database/sql"
"encoding/base64" "encoding/base64"
"errors"
"math/rand" "math/rand"
"strings" "strings"
"time" "time"
@ -121,8 +122,25 @@ func Get(db *sql.DB, code string) (*Invite, error) {
return inv, nil return inv, nil
} }
func IsCodeValid(db *sql.DB, code string) (bool, error) { func (i *Invite) MarkUsed(db *sql.DB) (err error) {
return false, nil var stmt *sql.Stmt
} var result sql.Result
var rowsAffected int64
if stmt, err = db.Prepare(`UPDATE invites SET used = 1 WHERE id = ?`); err != nil {
return
}
// TODO decide on rest of API (eg Validate, Use, Get, etc) if result, err = stmt.Exec(i.ID); err != nil {
return
}
if rowsAffected, err = result.RowsAffected(); err != nil {
return
}
if rowsAffected == 0 {
err = errors.New("no rows affected")
}
return
}