mirror of
https://github.com/jesperh1/csgo-hub-backend.git
synced 2025-06-07 11:58:51 +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.
9
main.go
9
main.go
@ -151,7 +151,15 @@ func CreateToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintf(w, "Bad request")
|
fmt.Fprintf(w, "Bad request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var dbToken string
|
||||||
|
query := `SELECT token FROM tokens where discord_id = ?`
|
||||||
|
_ = db.QueryRow(query, discord).Scan(&dbToken)
|
||||||
|
|
||||||
|
if dbToken != "" {
|
||||||
|
token = dbToken
|
||||||
|
}
|
||||||
|
|
||||||
|
if token != dbToken {
|
||||||
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -159,6 +167,7 @@ func CreateToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintf(w, "Bad request")
|
fmt.Fprintf(w, "Bad request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(token)
|
json.NewEncoder(w).Encode(token)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user