mirror of
https://github.com/jesperh1/csgo-hub-backend.git
synced 2025-06-07 03:48:50 +01:00
Checks if user already has open token
This commit is contained in:
parent
d19c802027
commit
4a292e3fd5
BIN
csgo-hub-backend
Executable file
BIN
csgo-hub-backend
Executable file
Binary file not shown.
21
main.go
21
main.go
@ -151,13 +151,22 @@ func CreateToken(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Bad request")
|
||||
return
|
||||
}
|
||||
var dbToken string
|
||||
query := `SELECT token FROM tokens where discord_id = ?`
|
||||
_ = db.QueryRow(query, discord).Scan(&dbToken)
|
||||
|
||||
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprintf(w, "Bad request")
|
||||
return
|
||||
if dbToken != "" {
|
||||
token = dbToken
|
||||
}
|
||||
|
||||
if token != dbToken {
|
||||
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprintf(w, "Bad request")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(token)
|
||||
|
Loading…
Reference in New Issue
Block a user