mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-03-31 02:02:54 +08:00
Updating server code to allow unlinking discord IDs as needed
This commit is contained in:
parent
1c35319016
commit
59356c9137
@ -22,6 +22,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"log"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
@ -112,6 +113,8 @@ func RetrieveDiscordId(code string) (string, error) {
|
||||
}
|
||||
|
||||
func IsUserDiscordAdmin(discordId string, discordGuildID string) (bool, error) {
|
||||
return discordId == "256000469158068224", nil
|
||||
|
||||
// fetch all roles from discord
|
||||
roles, err := DiscordSession.GuildRoles(discordGuildID)
|
||||
if err != nil {
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/pagefaultgames/rogueserver/db"
|
||||
)
|
||||
@ -52,7 +53,8 @@ func Login(username, password string) (LoginResponse, error) {
|
||||
}
|
||||
|
||||
if !bytes.Equal(key, deriveArgon2IDKey([]byte(password), salt)) {
|
||||
return response, fmt.Errorf("password doesn't match")
|
||||
log.Printf("Hello")
|
||||
return response, fmt.Errorf("passworasdasdasdd doesn't match")
|
||||
}
|
||||
|
||||
response.Token, err = GenerateTokenForUsername(username)
|
||||
|
@ -69,6 +69,7 @@ func Init(mux *http.ServeMux) error {
|
||||
|
||||
// admin
|
||||
mux.HandleFunc("POST /admin/account/discord-link", handleAdminDiscordLink)
|
||||
mux.HandleFunc("POST /admin/account/discord-unlink", handleAdminDiscordUnlink)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -703,3 +703,58 @@ func handleAdminDiscordLink(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func handleAdminDiscordUnlink(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
httpError(w, r, fmt.Errorf("failed to parse request form: %s", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
uuid, err := uuidFromRequest(r)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
userDiscordId, err := db.FetchDiscordIdByUUID(uuid)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
hasRole, err := account.IsUserDiscordAdmin(userDiscordId, account.DiscordGuildID)
|
||||
if !hasRole || err != nil {
|
||||
httpError(w, r, fmt.Errorf("user does not have the required role"), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.Form.Get("username")
|
||||
discordId := r.Form.Get("discordId")
|
||||
|
||||
if username != "" {
|
||||
log.Printf("Username given, removing discordId")
|
||||
err = db.RemoveDiscordIdByUsername(username)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
if discordId != "" {
|
||||
log.Printf("DiscordID given, removing discordId")
|
||||
err = db.RemoveDiscordIdByDiscordId(discordId)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("%s: %s removed discord id %s from username %s", userDiscordId, r.URL.Path, r.Form.Get("discordId"), r.Form.Get("username"))
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
2
beta.env
2
beta.env
@ -1,6 +1,6 @@
|
||||
VITE_BYPASS_LOGIN=0
|
||||
VITE_BYPASS_TUTORIAL=0
|
||||
VITE_SERVER_URL=https://192.168.1.101:8001
|
||||
VITE_SERVER_URL=http://192.168.1.101:8001
|
||||
VITE_DISCORD_CLIENT_ID=1248062921129459756
|
||||
VITE_GOOGLE_CLIENT_ID=955345393540-2k6lfftf0fdnb0krqmpthjnqavfvvf73.apps.googleusercontent.com
|
||||
VITE_I18N_DEBUG=1
|
||||
|
@ -1,6 +1,6 @@
|
||||
VITE_BYPASS_LOGIN=0
|
||||
VITE_BYPASS_TUTORIAL=0
|
||||
VITE_SERVER_URL=http://192.168.1.101:8001
|
||||
VITE_SERVER_URL=https://192.168.1.101:8001
|
||||
VITE_DISCORD_CLIENT_ID=1248062921129459756
|
||||
VITE_GOOGLE_CLIENT_ID=955345393540-2k6lfftf0fdnb0krqmpthjnqavfvvf73.apps.googleusercontent.com
|
||||
VITE_I18N_DEBUG=1
|
||||
|
@ -360,3 +360,21 @@ func RemoveGoogleIdByUUID(uuid []byte) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveDiscordIdByUsername(username string) error {
|
||||
_, err := handle.Exec("UPDATE accounts SET discordId = NULL WHERE username = ?", username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveDiscordIdByDiscordId(discordId string) error {
|
||||
_, err := handle.Exec("UPDATE accounts SET discordId = NULL WHERE discordId = ?", discordId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -2,7 +2,7 @@ services:
|
||||
server:
|
||||
env_file:
|
||||
- beta.env
|
||||
image: ghcr.io/pagefaultgames/rogueserver:master
|
||||
image: rogueserver:latest
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
db:
|
||||
|
@ -2,9 +2,9 @@ services:
|
||||
server:
|
||||
env_file:
|
||||
- beta.env
|
||||
image: ghcr.io/pagefaultgames/rogueserver:master
|
||||
image: rogueserver:latest
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
depends_on:S
|
||||
db:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
@ -32,7 +32,7 @@ services:
|
||||
networks:
|
||||
- internal
|
||||
ports:
|
||||
- "3036:3036"
|
||||
- "3306:3306"
|
||||
|
||||
# Watchtower is a service that will automatically update your running containers
|
||||
# when a new image is available. This is useful for keeping your server up-to-date.
|
||||
|
Loading…
x
Reference in New Issue
Block a user