feat: admin interface modify user, create user
This commit is contained in:
parent
52fcdbd576
commit
f6889725ba
@ -30,7 +30,7 @@ export default {
|
||||
this.$emit('edit', player)
|
||||
},
|
||||
newPlayer() {
|
||||
this.$emit('edit', {})
|
||||
this.$emit('edit', { id: null, name: '', score: 0, authcode: '' })
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ func (app *Application) GetGameInfo(usr *user.User, w http.ResponseWriter, r *ht
|
||||
gameInfo := gm.GetGameInfo()
|
||||
for i, _ := range gameInfo.Players {
|
||||
if playerUser, err := app.GetUserById(gameInfo.Players[i].Id); err != nil {
|
||||
fmt.Printf("GetUserById() failed: couldn't find player %s\n", gameInfo.Players[i].Id)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "internal server error")
|
||||
return
|
||||
|
@ -2,7 +2,9 @@ package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
"path"
|
||||
"sirlab.de/go/knyt/game"
|
||||
"sirlab.de/go/knyt/user"
|
||||
)
|
||||
@ -64,6 +66,17 @@ func (app *Application) modifyUser(id string, gm *game.Game, name, authcode stri
|
||||
}
|
||||
|
||||
func (app *Application) createUser(gm *game.Game, name, authcode string) error {
|
||||
return fmt.Errorf("Application.createUser() not yet implemented.")
|
||||
|
||||
dirName := path.Join(app.config.DataDir, "users")
|
||||
userNewUuid := uuid.NewString()
|
||||
fileName := path.Join(dirName, userNewUuid+".json")
|
||||
newUser := user.CreateUser(fileName, gm.GetId())
|
||||
newUser.SetRole(user.ROLE_PLAYER)
|
||||
newUser.SetName(name)
|
||||
newUser.SetAuthcode(authcode)
|
||||
if err := newUser.SaveUser(); err != nil {
|
||||
return err
|
||||
}
|
||||
app.users[newUser.GetId()] = newUser
|
||||
gm.AddPlayer(newUser)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package game
|
||||
|
||||
import ()
|
||||
|
||||
func (gm *Game) GetGameInfo() *GameInfoJson {
|
||||
gameInfo := gm.initGameInfoJson()
|
||||
|
||||
|
@ -32,6 +32,16 @@ func NewUserFromFile(fileName string) (*User, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func CreateUser(fileName, gameId string) *User {
|
||||
_, fileNameShort := path.Split(fileName)
|
||||
id := strings.TrimSuffix(fileNameShort, ".json")
|
||||
return &User{
|
||||
id: id,
|
||||
filename: fileName,
|
||||
gameId: gameId,
|
||||
}
|
||||
}
|
||||
|
||||
func (usr *User) SaveUser() error {
|
||||
usr.mu.Lock()
|
||||
defer usr.mu.Unlock()
|
||||
@ -94,6 +104,13 @@ func (usr *User) GetRole() string {
|
||||
return usr.role
|
||||
}
|
||||
|
||||
func (usr *User) SetRole(role string) {
|
||||
usr.mu.Lock()
|
||||
defer usr.mu.Unlock()
|
||||
|
||||
usr.role = role
|
||||
}
|
||||
|
||||
func (usr *User) GetGameId() string {
|
||||
usr.mu.Lock()
|
||||
defer usr.mu.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user