2023-06-22 22:12:33 +00:00
|
|
|
// Copyright 2022-2023 the Pinniped contributors. All Rights Reserved.
|
2022-04-26 22:30:39 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package login
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-06-22 22:12:33 +00:00
|
|
|
"go.pinniped.dev/internal/federationdomain/endpoints/login/loginhtml"
|
|
|
|
"go.pinniped.dev/internal/federationdomain/oidc"
|
2022-04-26 22:30:39 +00:00
|
|
|
)
|
|
|
|
|
2022-05-05 20:12:06 +00:00
|
|
|
const (
|
|
|
|
internalErrorMessage = "An internal error occurred. Please contact your administrator for help."
|
|
|
|
incorrectUsernameOrPasswordErrorMessage = "Incorrect username or password."
|
2022-04-28 16:11:51 +00:00
|
|
|
)
|
|
|
|
|
2022-05-19 23:02:08 +00:00
|
|
|
func NewGetHandler(loginPath string) HandlerFunc {
|
2022-04-26 22:30:39 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request, encodedState string, decodedState *oidc.UpstreamStateParamData) error {
|
2022-05-05 20:12:06 +00:00
|
|
|
alertMessage, hasAlert := getAlert(r)
|
|
|
|
|
|
|
|
pageInputs := &loginhtml.PageData{
|
2022-05-19 23:02:08 +00:00
|
|
|
PostPath: loginPath,
|
2022-04-29 17:36:13 +00:00
|
|
|
State: encodedState,
|
|
|
|
IDPName: decodedState.UpstreamName,
|
2022-05-05 20:12:06 +00:00
|
|
|
HasAlertError: hasAlert,
|
|
|
|
AlertMessage: alertMessage,
|
2022-04-28 16:11:51 +00:00
|
|
|
}
|
2022-05-05 20:12:06 +00:00
|
|
|
return loginhtml.Template().Execute(w, pageInputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAlert(r *http.Request) (string, bool) {
|
|
|
|
errorParamValue := r.URL.Query().Get(errParamName)
|
2022-04-28 16:11:51 +00:00
|
|
|
|
2022-05-05 20:12:06 +00:00
|
|
|
message := internalErrorMessage
|
|
|
|
if errorParamValue == string(ShowBadUserPassErr) {
|
|
|
|
message = incorrectUsernameOrPasswordErrorMessage
|
2022-04-26 22:30:39 +00:00
|
|
|
}
|
2022-05-05 20:12:06 +00:00
|
|
|
|
|
|
|
return message, errorParamValue != ""
|
2022-04-26 22:30:39 +00:00
|
|
|
}
|