Skip to content

Commit

Permalink
chore: alert invalid login (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 authored May 13, 2024
1 parent a28a6e9 commit 0bf2703
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion controller/login.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"errors"
"net/http"

"github.com/Gornak40/crosspawn/internal/alerts"
Expand Down Expand Up @@ -51,7 +52,16 @@ func (s *Server) LoginPOST(c *gin.Context) {
Password: form.Password,
ContestID: form.ContestID,
}); err != nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
if errors.Is(err, ejudge.ErrInvalidCredentials) {
_ = alerts.Add(session, alerts.Alert{
Message: "Invalid credentials",
Type: alerts.TypeDanger,
})
c.Redirect(http.StatusFound, "/login")
c.Abort()
} else {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
}

return
}
Expand Down

0 comments on commit 0bf2703

Please sign in to comment.