bugfix: set cameo flag only for admin user (clone user object)
This commit is contained in:
parent
2f3c34f5d9
commit
4827ff10b7
@ -3,8 +3,9 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sirlab.de/go/knowyt/user"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"sirlab.de/go/knowyt/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (authMux *AuthMux) PrivateHandleFunc(pattern string, handlerFunc PrivateHandlerFunc) {
|
func (authMux *AuthMux) PrivateHandleFunc(pattern string, handlerFunc PrivateHandlerFunc) {
|
||||||
@ -43,7 +44,8 @@ func (authMux *AuthMux) getUserFromSession(r *http.Request) (*user.User, error)
|
|||||||
|
|
||||||
if usr.IsAdmin() {
|
if usr.IsAdmin() {
|
||||||
if cookieCameo, err := r.Cookie("knowyt-auth-cameo"); err == nil {
|
if cookieCameo, err := r.Cookie("knowyt-auth-cameo"); err == nil {
|
||||||
if usrNew, err := authMux.app.GetUserById(cookieCameo.Value); err == nil {
|
if usrCameo, err := authMux.app.GetUserById(cookieCameo.Value); err == nil {
|
||||||
|
usrNew := usrCameo.DeepCloneUserObj()
|
||||||
usrNew.SetCameo(usr)
|
usrNew.SetCameo(usr)
|
||||||
return usrNew, nil
|
return usrNew, nil
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sirlab.de/go/knowyt/fileutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"sirlab.de/go/knowyt/fileutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewUserFromFile(fileName string) (*User, error) {
|
func NewUserFromFile(fileName string) (*User, error) {
|
||||||
@ -48,6 +49,24 @@ func CreateUser(fileName, gameId string) *User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (usr *User) DeepCloneUserObj() *User {
|
||||||
|
usr.mu.Lock()
|
||||||
|
defer usr.mu.Unlock()
|
||||||
|
|
||||||
|
usrNew := User{
|
||||||
|
id: usr.id,
|
||||||
|
filename: usr.filename,
|
||||||
|
authcode: usr.authcode,
|
||||||
|
name: usr.name,
|
||||||
|
role: usr.role,
|
||||||
|
gameId: usr.gameId,
|
||||||
|
created: usr.created,
|
||||||
|
lastLoggedIn: usr.lastLoggedIn,
|
||||||
|
cameo: usr.cameo,
|
||||||
|
}
|
||||||
|
return &usrNew
|
||||||
|
}
|
||||||
|
|
||||||
func (usr *User) SaveUser() error {
|
func (usr *User) SaveUser() error {
|
||||||
usr.mu.Lock()
|
usr.mu.Lock()
|
||||||
defer usr.mu.Unlock()
|
defer usr.mu.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user