mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-02 02:57:15 +08:00
Added logic to check server to make sure usename exists for discord linking and unlinking
This commit is contained in:
parent
ff5d057716
commit
759a748010
@ -693,13 +693,24 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AddDiscordIdByUsername(r.Form.Get("discordId"), r.Form.Get("username"))
|
username := r.Form.Get("username")
|
||||||
|
discordId := r.Form.Get("discordId")
|
||||||
|
|
||||||
|
// this does a quick call to make sure the username exists on the server before allowing the rest of the code to run
|
||||||
|
// this calls error value 204 (StatusNoContent) if there's no data; this means the username does not exist in the server
|
||||||
|
_, err = db.CheckUsernameExists(username)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, fmt.Errorf("username does not exist on the server"), http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.AddDiscordIdByUsername(discordId, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s: %s added discord id %s to username %s", r.URL.Path, userDiscordId, r.Form.Get("discordId"), r.Form.Get("username"))
|
log.Printf("%s: %s added discord id %s to username %s", r.URL.Path, userDiscordId, discordId, username)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
@ -739,6 +750,13 @@ func handleAdminDiscordUnlink(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if username != "" {
|
if username != "" {
|
||||||
log.Printf("Username given, removing discordId")
|
log.Printf("Username given, removing discordId")
|
||||||
|
// this does a quick call to make sure the username exists on the server before allowing the rest of the code to run
|
||||||
|
// this calls error value 204 (StatusNoContent) if there's no data; this means the username does not exist in the server
|
||||||
|
_, err = db.CheckUsernameExists(username)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, fmt.Errorf("username does not exist on the server"), http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
err = db.RemoveDiscordIdByUsername(username)
|
err = db.RemoveDiscordIdByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user