Skip to content

Commit

Permalink
Change to html output for jwt-login
Browse files Browse the repository at this point in the history
  • Loading branch information
moebiusband73 committed Aug 18, 2023
1 parent c87db1d commit 9fec8a4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions cmd/cc-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ var (
version string
)

// ErrorResponse model
type ErrorResponse struct {
// Statustext of Errorcode
Status string `json:"status"`
Error string `json:"error"` // Error Message
}

func initEnv() {
if util.CheckFileExists("var") {
fmt.Print("Directory ./var already exists. Exiting!\n")
Expand Down Expand Up @@ -370,11 +363,13 @@ func main() {

// On failure:
func(rw http.ResponseWriter, r *http.Request, err error) {
rw.Header().Add("Content-Type", "application/json")
rw.WriteHeader(http.StatusForbidden)
json.NewEncoder(rw).Encode(ErrorResponse{
Status: http.StatusText(http.StatusForbidden),
Error: err.Error(),
rw.Header().Add("Content-Type", "text/html; charset=utf-8")
rw.WriteHeader(http.StatusUnauthorized)
web.RenderTemplate(rw, "login.tmpl", &web.Page{
Title: "Login failed - ClusterCockpit",
MsgType: "alert-warning",
Message: err.Error(),
Build: buildInfo,
})
}))

Expand Down

0 comments on commit 9fec8a4

Please sign in to comment.