goweb-oidc/internal/route/home.go

31 lines
752 B
Go

package route
import (
"net/http"
oidc "forge.cadoles.com/cadoles/goweb-oidc"
"forge.cadoles.com/cadoles/goweb-oidc/internal/config"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/middleware/container"
"gitlab.com/wpetit/goweb/service/template"
)
func serveHomePage(w http.ResponseWriter, r *http.Request) {
ctn := container.Must(r.Context())
tmpl := template.Must(ctn)
conf := config.Must(ctn)
idToken, _ := oidc.IDToken(w, r)
if idToken != nil {
http.Redirect(w, r, conf.HTTP.PublicBaseURL+"/profile", http.StatusSeeOther)
return
}
data := extendTemplateData(w, r, template.Data{})
if err := tmpl.RenderPage(w, "home.html.tmpl", data); err != nil {
panic(errors.Wrapf(err, "could not render '%s' page", r.URL.Path))
}
}