Browse Source

Get word from token, and drop token

master
Elis Axelsson 5 years ago
parent
commit
7d94eeb027
  1. 37
      src/WorstCaptcha/Db.go

37
src/WorstCaptcha/Db.go

@ -43,3 +43,40 @@ func (d *Db) InsertToken(word string, token string) {
stmt.Exec(word, token)
}
func (d *Db) GetWordByToken(token string) string {
var returningWord string
rows, _ := d.Client.Query(
"SELECT `id`, `word` FROM tokens WHERE `token` = ?",
token,
)
// Make map with rows to delete from database
toDelete := make(map[int]bool)
for rows.Next() {
var id int
var word string
// Fill vars with data
_ = rows.Scan(&id, &word)
// Append to map to delete
toDelete[id] = true
returningWord = word
}
rows.Close()
// Loop trough the map with ids to remove
for id, _ := range toDelete {
stmt, _ := d.Client.Prepare("DELETE FROM tokens WHERE id = ?")
stmt.Exec(id)
stmt.Close()
}
return returningWord
}

Loading…
Cancel
Save