2020-05-20 13:06:04 +02:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-12-06 16:02:40 +01:00
|
|
|
oidc "forge.cadoles.com/cadoles/goweb-oidc"
|
|
|
|
"forge.cadoles.com/cadoles/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)
|
2022-08-02 11:48:42 +02:00
|
|
|
conf := config.Must(ctn)
|
2020-05-20 13:06:04 +02:00
|
|
|
|
|
|
|
idToken, _ := oidc.IDToken(w, r)
|
|
|
|
|
|
|
|
if idToken != nil {
|
2022-08-02 11:48:42 +02:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|