mirror of
https://github.com/hazemKrimi/crimson-vault.git
synced 2026-05-02 02:30:28 +00:00
wip: debugging session authentication
This commit is contained in:
@@ -11,8 +11,18 @@ func SessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
return func(context echo.Context) error {
|
return func(context echo.Context) error {
|
||||||
sess, err := session.Get("session", context)
|
sess, err := session.Get("session", context)
|
||||||
|
|
||||||
if sess == nil || err != nil {
|
if err != nil {
|
||||||
return context.String(http.StatusBadRequest, "User not authenticated!")
|
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||||
|
}
|
||||||
|
|
||||||
|
cookie, err := context.Cookie("session")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sess.IsNew || cookie.Value == "" || sess.Values["id"] == "" {
|
||||||
|
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Set("id", sess.Values["id"])
|
context.Set("id", sess.Values["id"])
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func (api *API) UserRoutes() {
|
|||||||
users.GET("/", api.GetAllUsersHandler)
|
users.GET("/", api.GetAllUsersHandler)
|
||||||
users.POST("/", api.CreateUserHandler)
|
users.POST("/", api.CreateUserHandler)
|
||||||
users.GET("/:id", api.GetUserHandler)
|
users.GET("/:id", api.GetUserHandler)
|
||||||
users.PUT("/:id", api.UpdateUserHandler)
|
users.PUT("/:id", api.UpdateUserHandler, SessionMiddleware)
|
||||||
users.PUT("/:id/security", api.UpdateUserSecurityDetailsHandler)
|
users.PUT("/:id/security", api.UpdateUserSecurityDetailsHandler)
|
||||||
users.PUT("/:id/logo", api.UpdateUserLogoHandler, middleware.BodyLimit("2M"))
|
users.PUT("/:id/logo", api.UpdateUserLogoHandler, middleware.BodyLimit("2M"))
|
||||||
users.DELETE("/:id", api.DeleteUserHandler)
|
users.DELETE("/:id", api.DeleteUserHandler)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func GetConfigDirectory() (string, error) {
|
|||||||
func ConstructSession(session *sessions.Session, user types.User) {
|
func ConstructSession(session *sessions.Session, user types.User) {
|
||||||
session.Options = &sessions.Options{
|
session.Options = &sessions.Options{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: 86400 * 7,
|
MaxAge: 3600,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
}
|
}
|
||||||
session.Values["id"] = user.ID
|
session.Values["id"] = user.ID
|
||||||
|
|||||||
Reference in New Issue
Block a user