mirror of https://gitlab.com/ngerakines/tavern.git
49 lines
911 B
Go
49 lines
911 B
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-contrib/sessions"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ngerakines/tavern/errors"
|
|
)
|
|
|
|
func (h handler) configure(c *gin.Context) {
|
|
session := sessions.Default(c)
|
|
ctx := c.Request.Context()
|
|
trans, transOK := c.Get("trans")
|
|
if !transOK {
|
|
panic("trans not found in context")
|
|
}
|
|
data := gin.H{
|
|
"flashes": getFlashes(session),
|
|
"Trans": trans,
|
|
}
|
|
|
|
user, err := h.storage.GetUserBySession(ctx, session)
|
|
if err != nil {
|
|
if errors.Is(err, errors.UserSessionNotFoundError{}) {
|
|
|
|
if err = appendFlashError(session, "Not Authenticated"); err != nil {
|
|
h.hardFail(c, errors.NewCannotSaveSessionError(err))
|
|
return
|
|
}
|
|
|
|
c.Redirect(http.StatusFound, "/")
|
|
return
|
|
}
|
|
h.hardFail(c, err)
|
|
return
|
|
}
|
|
|
|
data["user"] = user
|
|
|
|
if err = session.Save(); err != nil {
|
|
h.hardFail(c, err)
|
|
return
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "configure", data)
|
|
}
|