feat: admin interface remove user
This commit is contained in:
parent
f6889725ba
commit
a89f197fdd
@ -6,6 +6,9 @@
|
||||
<tr>
|
||||
<td>Name: </td>
|
||||
<td><input v-model="name" /></td>
|
||||
<td v-if="id" class="admin-edit-player__table-cell-delete" rowspan="5">
|
||||
<span class="admin-edit-player__button-delete" @click="deletePlayer">delete player</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Score: </td>
|
||||
@ -20,7 +23,9 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><button @click="save">Submit</button></td>
|
||||
<td>
|
||||
<button class="admin-edit-player__button-save" @click="save">{{id ? 'save' : 'create'}}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</Infobox>
|
||||
@ -45,6 +50,10 @@ export default {
|
||||
})
|
||||
this.$emit('close')
|
||||
},
|
||||
async deletePlayer() {
|
||||
await this.$engine.deletePlayer({ id: this.id })
|
||||
this.$emit('close')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@ -53,6 +62,7 @@ export default {
|
||||
@import '~/assets/css/components';
|
||||
|
||||
.admin-edit-player {
|
||||
font-family: Dosis;
|
||||
&__close {
|
||||
float: right;
|
||||
margin: 16px -16px 16px 16px;
|
||||
@ -75,5 +85,21 @@ export default {
|
||||
&__table {
|
||||
margin: 64px;
|
||||
}
|
||||
&__button-save {
|
||||
padding: 0.3em 2em;
|
||||
}
|
||||
&__table-cell-delete {
|
||||
vertical-align: top;
|
||||
}
|
||||
&__button-delete {
|
||||
margin-left: 3em;
|
||||
font-size: 16px;
|
||||
font-family: Dosis;
|
||||
color: #e06060;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
8
client/src/plugins/engine/deletePlayer.js
Normal file
8
client/src/plugins/engine/deletePlayer.js
Normal file
@ -0,0 +1,8 @@
|
||||
export default async function(player) {
|
||||
const { store } = this.context
|
||||
|
||||
await this.callApi('/api/deletePlayer', {
|
||||
g: store.state.engine.user?.game,
|
||||
id: player.id,
|
||||
})
|
||||
}
|
@ -6,6 +6,7 @@ import fetchUserInfo from './fetchUserInfo'
|
||||
import fetchGameInfo from './fetchGameInfo'
|
||||
import setGameName from './setGameName'
|
||||
import savePlayer from './savePlayer'
|
||||
import deletePlayer from './deletePlayer'
|
||||
import collectQuotes from './collectQuotes'
|
||||
import startGame from './startGame'
|
||||
import resetGame from './resetGame'
|
||||
@ -33,6 +34,7 @@ export default (context, inject) => {
|
||||
fetchGameInfo,
|
||||
setGameName,
|
||||
savePlayer,
|
||||
deletePlayer,
|
||||
collectQuotes,
|
||||
getMyQuotes,
|
||||
saveQuote,
|
||||
|
42
server/src/application/deletePlayer.go
Normal file
42
server/src/application/deletePlayer.go
Normal file
@ -0,0 +1,42 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sirlab.de/go/knyt/user"
|
||||
)
|
||||
|
||||
func (app *Application) DeletePlayer(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
||||
gameRef := r.URL.Query().Get("g")
|
||||
gm, err := app.GetGameById(gameRef)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
fmt.Fprintf(w, "game not found")
|
||||
return
|
||||
}
|
||||
|
||||
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
|
||||
id := r.URL.Query().Get("id")
|
||||
deleteUser := app.users[id]
|
||||
if deleteUser.GetId() != id || deleteUser.GetGameId() != gm.GetId() {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Printf("couldn't find player %s in game %s\n", id, gm.GetId())
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
if err := deleteUser.DeleteUser(); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Printf("%v\n", err)
|
||||
fmt.Fprintf(w, "internal server error")
|
||||
return
|
||||
}
|
||||
gm.DeletePlayer(deleteUser)
|
||||
delete(app.users, id)
|
||||
|
||||
fmt.Fprintf(w, "ok")
|
||||
}
|
@ -83,3 +83,11 @@ func (gm *Game) UpdatePlayer(usr *user.User) {
|
||||
player.name = usr.GetName()
|
||||
gm.players[usrId] = player
|
||||
}
|
||||
|
||||
func (gm *Game) DeletePlayer(usr *user.User) {
|
||||
usrId := usr.GetId()
|
||||
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
delete(gm.players, usrId)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ func main() {
|
||||
mux.PrivateHandleFunc("/api/gameinfo", app.GetGameInfo)
|
||||
mux.PrivateHandleFunc("/api/setGameName", app.SetGameName)
|
||||
mux.PrivateHandleFunc("/api/savePlayer", app.SavePlayer)
|
||||
mux.PrivateHandleFunc("/api/deletePlayer", app.DeletePlayer)
|
||||
mux.PrivateHandleFunc("/api/sync", app.SyncHandler)
|
||||
mux.PrivateHandleFunc("/api/collectQuotes", app.CollectQuotes)
|
||||
mux.PrivateHandleFunc("/api/startGame", app.StartGame)
|
||||
|
@ -62,6 +62,10 @@ func (usr *User) SaveUser() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (usr *User) DeleteUser() error {
|
||||
return os.Remove(usr.filename)
|
||||
}
|
||||
|
||||
func (usr *User) GetId() string {
|
||||
usr.mu.Lock()
|
||||
defer usr.mu.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user