mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-03 19:47:14 +08:00
Updates from Pancake's comments
This commit is contained in:
parent
2e7c596f7f
commit
73a87d6b90
@ -68,11 +68,11 @@ func Init(mux *http.ServeMux) error {
|
|||||||
mux.HandleFunc("/auth/{provider}/logout", handleProviderLogout)
|
mux.HandleFunc("/auth/{provider}/logout", handleProviderLogout)
|
||||||
|
|
||||||
// admin
|
// admin
|
||||||
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
mux.HandleFunc("POST /admin/account/discordLink", handleAdminDiscordLink)
|
||||||
mux.HandleFunc("POST /admin/account/discord-unlink", handleAdminDiscordUnlink)
|
mux.HandleFunc("POST /admin/account/discordUnlink", handleAdminDiscordUnlink)
|
||||||
mux.HandleFunc("POST /admin/account/google-link", handleAdminGoogleLink)
|
mux.HandleFunc("POST /admin/account/googleLink", handleAdminGoogleLink)
|
||||||
mux.HandleFunc("POST /admin/account/google-unlink", handleAdminGoogleUnlink)
|
mux.HandleFunc("POST /admin/account/googleUnlink", handleAdminGoogleUnlink)
|
||||||
mux.HandleFunc("GET /admin/account/admin-search", handleAdminSearch)
|
mux.HandleFunc("GET /admin/account/adminSearch", handleAdminSearch)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,13 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AddDiscordIdByUsername(discordId, username)
|
userUuid, err := db.FetchUUIDFromUsername(username)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.AddDiscordIdByUUID(discordId, userUuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -754,12 +760,17 @@ func handleAdminDiscordUnlink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.RemoveDiscordIdByUsername(username)
|
userUuid, err := db.FetchUUIDFromUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = db.RemoveDiscordIdByUUID(userUuid)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
case discordId != "":
|
case discordId != "":
|
||||||
log.Printf("DiscordID given, removing discordId")
|
log.Printf("DiscordID given, removing discordId")
|
||||||
err = db.RemoveDiscordIdByDiscordId(discordId)
|
err = db.RemoveDiscordIdByDiscordId(discordId)
|
||||||
@ -767,7 +778,6 @@ func handleAdminDiscordUnlink(w http.ResponseWriter, r *http.Request) {
|
|||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s: %s removed discord id %s from username %s", userDiscordId, r.URL.Path, r.Form.Get("discordId"), r.Form.Get("username"))
|
log.Printf("%s: %s removed discord id %s from username %s", userDiscordId, r.URL.Path, r.Form.Get("discordId"), r.Form.Get("username"))
|
||||||
@ -811,7 +821,13 @@ func handleAdminGoogleLink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AddGoogleIdByUsername(googleId, username)
|
userUuid, err := db.FetchUUIDFromUsername(username)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.AddGoogleIdByUUID(googleId, userUuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -861,12 +877,17 @@ func handleAdminGoogleUnlink(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.RemoveGoogleIdByUsername(username)
|
userUuid, err := db.FetchUUIDFromUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = db.RemoveGoogleIdByUUID(userUuid)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
case googleId != "":
|
case googleId != "":
|
||||||
log.Printf("DiscordID given, removing googleId")
|
log.Printf("DiscordID given, removing googleId")
|
||||||
err = db.RemoveGoogleIdByDiscordId(googleId)
|
err = db.RemoveGoogleIdByDiscordId(googleId)
|
||||||
@ -874,7 +895,6 @@ func handleAdminGoogleUnlink(w http.ResponseWriter, r *http.Request) {
|
|||||||
httpError(w, r, err, http.StatusInternalServerError)
|
httpError(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s: %s removed google id %s from username %s", userDiscordId, r.URL.Path, r.Form.Get("googleId"), r.Form.Get("username"))
|
log.Printf("%s: %s removed google id %s from username %s", userDiscordId, r.URL.Path, r.Form.Get("googleId"), r.Form.Get("username"))
|
||||||
|
@ -68,6 +68,25 @@ func AddGoogleIdByUsername(googleId string, username string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddGoogleIdByUUID(googleId string, uuid []byte) error {
|
||||||
|
_, err := handle.Exec("UPDATE accounts SET googleId = ? WHERE uuid = ?", googleId, uuid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddDiscordIdByUUID(discordId string, uuid []byte) error {
|
||||||
|
_, err := handle.Exec("UPDATE accounts SET discordId = ? WHERE uuid = ?", discordId, uuid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func FetchUsernameByDiscordId(discordId string) (string, error) {
|
func FetchUsernameByDiscordId(discordId string) (string, error) {
|
||||||
var username string
|
var username string
|
||||||
err := handle.QueryRow("SELECT username FROM accounts WHERE discordId = ?", discordId).Scan(&username)
|
err := handle.QueryRow("SELECT username FROM accounts WHERE discordId = ?", discordId).Scan(&username)
|
||||||
@ -163,6 +182,7 @@ func CheckUsernameExists(username string) (string, error) {
|
|||||||
if !dbUsername.Valid {
|
if !dbUsername.Valid {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbUsername.String, nil
|
return dbUsername.String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +195,7 @@ func FetchLastLoggedInDateByUsername(username string) (string, error) {
|
|||||||
if !lastLoggedIn.Valid {
|
if !lastLoggedIn.Valid {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastLoggedIn.String, nil
|
return lastLoggedIn.String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +209,6 @@ type AdminSearchResponse struct {
|
|||||||
|
|
||||||
func FetchAdminDetailsByUsername(dbUsername string) (AdminSearchResponse, error) {
|
func FetchAdminDetailsByUsername(dbUsername string) (AdminSearchResponse, error) {
|
||||||
var resultUsername, resultDiscordId, resultGoogleId, resultLastLoggedIn, resultRegistered sql.NullString
|
var resultUsername, resultDiscordId, resultGoogleId, resultLastLoggedIn, resultRegistered sql.NullString
|
||||||
var username, discordId, googleId, lastLoggedIn, registered string
|
|
||||||
var adminResponse AdminSearchResponse
|
var adminResponse AdminSearchResponse
|
||||||
|
|
||||||
err := handle.QueryRow("SELECT username, discordId, googleId, lastLoggedIn, registered from accounts WHERE username = ?", dbUsername).Scan(&resultUsername, &resultDiscordId, &resultGoogleId, &resultLastLoggedIn, &resultRegistered)
|
err := handle.QueryRow("SELECT username, discordId, googleId, lastLoggedIn, registered from accounts WHERE username = ?", dbUsername).Scan(&resultUsername, &resultDiscordId, &resultGoogleId, &resultLastLoggedIn, &resultRegistered)
|
||||||
@ -196,42 +216,12 @@ func FetchAdminDetailsByUsername(dbUsername string) (AdminSearchResponse, error)
|
|||||||
return adminResponse, err
|
return adminResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resultUsername.Valid {
|
|
||||||
username = resultUsername.String
|
|
||||||
} else {
|
|
||||||
username = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if resultDiscordId.Valid {
|
|
||||||
discordId = resultDiscordId.String
|
|
||||||
} else {
|
|
||||||
discordId = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if resultGoogleId.Valid {
|
|
||||||
googleId = resultGoogleId.String
|
|
||||||
} else {
|
|
||||||
googleId = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if resultLastLoggedIn.Valid {
|
|
||||||
lastLoggedIn = resultLastLoggedIn.String
|
|
||||||
} else {
|
|
||||||
lastLoggedIn = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if resultRegistered.Valid {
|
|
||||||
registered = resultRegistered.String
|
|
||||||
} else {
|
|
||||||
registered = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
adminResponse = AdminSearchResponse{
|
adminResponse = AdminSearchResponse{
|
||||||
Username: username,
|
Username: resultUsername.String,
|
||||||
DiscordId: discordId,
|
DiscordId: resultDiscordId.String,
|
||||||
GoogleId: googleId,
|
GoogleId: resultGoogleId.String,
|
||||||
LastLoggedIn: lastLoggedIn,
|
LastLoggedIn: resultLastLoggedIn.String,
|
||||||
Registered: registered,
|
Registered: resultRegistered.String,
|
||||||
}
|
}
|
||||||
|
|
||||||
return adminResponse, nil
|
return adminResponse, nil
|
||||||
@ -426,6 +416,16 @@ func FetchUsernameFromUUID(uuid []byte) (string, error) {
|
|||||||
return username, nil
|
return username, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FetchUUIDFromUsername(username string) ([]byte, error) {
|
||||||
|
var uuid []byte
|
||||||
|
err := handle.QueryRow("SELECT uuid FROM accounts WHERE username = ?", username).Scan(&uuid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
func RemoveDiscordIdByUUID(uuid []byte) error {
|
func RemoveDiscordIdByUUID(uuid []byte) error {
|
||||||
_, err := handle.Exec("UPDATE accounts SET discordId = NULL WHERE uuid = ?", uuid)
|
_, err := handle.Exec("UPDATE accounts SET discordId = NULL WHERE uuid = ?", uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user