mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Log errors returned from graphql (#3562)
* Add func methods to logger * Log errors returned from the graphql interface * Log authentication * Log when credentials changed
This commit is contained in:
@@ -34,7 +34,15 @@ const (
|
||||
passwordFormKey = "password"
|
||||
)
|
||||
|
||||
var ErrInvalidCredentials = errors.New("invalid username or password")
|
||||
type InvalidCredentialsError struct {
|
||||
Username string
|
||||
}
|
||||
|
||||
func (e InvalidCredentialsError) Error() string {
|
||||
// don't leak the username
|
||||
return "invalid credentials"
|
||||
}
|
||||
|
||||
var ErrUnauthorized = errors.New("unauthorized")
|
||||
|
||||
type Store struct {
|
||||
@@ -63,9 +71,12 @@ func (s *Store) Login(w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
// authenticate the user
|
||||
if !s.config.ValidateCredentials(username, password) {
|
||||
return ErrInvalidCredentials
|
||||
return &InvalidCredentialsError{Username: username}
|
||||
}
|
||||
|
||||
// since we only have one user, don't leak the name
|
||||
logger.Info("User logged in")
|
||||
|
||||
newSession.Values[userIDKey] = username
|
||||
|
||||
err := newSession.Save(r, w)
|
||||
@@ -90,6 +101,9 @@ func (s *Store) Logout(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// since we only have one user, don't leak the name
|
||||
logger.Infof("User logged out")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user