Fixed user ID bug, added auth OK resonse

This commit is contained in:
Magnus Åhall 2024-01-05 22:24:04 +01:00
parent 447aec742c
commit 865aab95a9
2 changed files with 5 additions and 3 deletions

2
pkg.go
View File

@ -112,7 +112,7 @@ func (service *Service) defaultAuthenticationHandler(req AuthenticationRequest,
} // }}} } // }}}
func (service *Service) defaultAuthorizationHandler(sess *session.T, r *http.Request) (resp bool, err error) { // {{{ func (service *Service) defaultAuthorizationHandler(sess *session.T, r *http.Request) (resp bool, err error) { // {{{
resp = true resp = true
service.logger.Error("webservice", "op", "authorization", "session", sess.UUID, "request", r, "authorized", resp) service.logger.Debug("webservice", "op", "authorization", "session", sess.UUID, "request", r.URL.String(), "authorized", resp)
return return
} // }}} } // }}}
func (service *Service) defaultErrorHandler(err error, w http.ResponseWriter) { // {{{ func (service *Service) defaultErrorHandler(err error, w http.ResponseWriter) { // {{{

View File

@ -20,6 +20,7 @@ type AuthenticationRequest struct {
} }
type AuthenticationResponse struct { type AuthenticationResponse struct {
OK bool
Authenticated bool Authenticated bool
UserID int UserID int
} }
@ -88,8 +89,8 @@ func (service *Service) sessionAuthenticate(w http.ResponseWriter, r *http.Reque
} }
// Authenticate against webservice user table if using a database. // Authenticate against webservice user table if using a database.
var userID int
if service.Db != nil { if service.Db != nil {
var userID int
authenticated, userID, err = service.Db.Authenticate(authRequest.Username, authRequest.Password) authenticated, userID, err = service.Db.Authenticate(authRequest.Username, authRequest.Password)
if err != nil { if err != nil {
service.errorHandler(err, w) service.errorHandler(err, w)
@ -113,7 +114,8 @@ func (service *Service) sessionAuthenticate(w http.ResponseWriter, r *http.Reque
service.errorHandler(err, w) service.errorHandler(err, w)
return return
} }
authResponse.UserID = sess.UserID authResponse.UserID = userID
authResponse.OK = true
sess.Authenticated = authResponse.Authenticated sess.Authenticated = authResponse.Authenticated