diff --git a/server/src/handler/login.go b/server/src/handler/login.go index d1aecb4..2c59d36 100644 --- a/server/src/handler/login.go +++ b/server/src/handler/login.go @@ -3,6 +3,8 @@ package handler import ( "fmt" "net/http" + + "sirlab.de/go/knowyt/log" "sirlab.de/go/knowyt/user" ) @@ -25,17 +27,21 @@ func (authMux *AuthMux) Logout(w http.ResponseWriter, r *http.Request) { func (authMux *AuthMux) Login(w http.ResponseWriter, r *http.Request) { usr, err := authMux.checkCode(r) if err != nil { + log.ErrorLog(err) http.SetCookie(w, authMux.createCookie()) authMux.accessDenied(w, r) return } + log.Info("%s logged into game %s\n", usr.GetName(), usr.GetGameId()) + cookie := authMux.createCookie() cookie.Value = usr.GetId() + ":" + usr.GetAuthCode() cookie.MaxAge = 0 http.SetCookie(w, cookie) w.Header().Add("Content-Type", "text/plain") fmt.Fprintf(w, "ok") + } func (authMux *AuthMux) checkCode(r *http.Request) (*user.User, error) { @@ -44,12 +50,12 @@ func (authMux *AuthMux) checkCode(r *http.Request) (*user.User, error) { code := form.Get("code") if len(code) != 6 { - return nil, fmt.Errorf("invalid code") + return nil, fmt.Errorf("invalid code \"%s\"", code) } usr, err := authMux.app.GetUserByAuthcode(code) if err != nil { - return nil, fmt.Errorf("invalid code") + return nil, fmt.Errorf("invalid code: \"%s\"", code) } return usr, nil diff --git a/server/src/log/main.go b/server/src/log/log.go similarity index 95% rename from server/src/log/main.go rename to server/src/log/log.go index 1a832b1..9594cb1 100644 --- a/server/src/log/main.go +++ b/server/src/log/log.go @@ -52,8 +52,5 @@ func Error(format string, v ...any) { } func ErrorLog(err error) { - lock.Lock() - defer lock.Unlock() - Error("%v\n", err) }