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) { // {{{
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
} // }}}
func (service *Service) defaultErrorHandler(err error, w http.ResponseWriter) { // {{{

View File

@ -20,6 +20,7 @@ type AuthenticationRequest struct {
}
type AuthenticationResponse struct {
OK bool
Authenticated bool
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.
if service.Db != nil {
var userID int
if service.Db != nil {
authenticated, userID, err = service.Db.Authenticate(authRequest.Username, authRequest.Password)
if err != nil {
service.errorHandler(err, w)
@ -113,7 +114,8 @@ func (service *Service) sessionAuthenticate(w http.ResponseWriter, r *http.Reque
service.errorHandler(err, w)
return
}
authResponse.UserID = sess.UserID
authResponse.UserID = userID
authResponse.OK = true
sess.Authenticated = authResponse.Authenticated