goweb-oidc/internal/route/home.go

31 lines
750 B
Go
Raw Permalink Normal View History

2020-05-20 13:06:04 +02:00
package route
import (
"net/http"
oidc "forge.cadoles.com/wpetit/goweb-oidc"
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
2020-05-20 13:06:04 +02:00
"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)
2020-05-20 13:06:04 +02:00
idToken, _ := oidc.IDToken(w, r)
if idToken != nil {
http.Redirect(w, r, conf.HTTP.PublicBaseURL+"/profile", http.StatusSeeOther)
2020-05-20 13:06:04 +02:00
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))
}
}