Access http session in protected routes
This commit is contained in:
parent
55e6be7239
commit
1980e33d0f
|
|
@ -3,6 +3,7 @@ package routing
|
||||||
import (
|
import (
|
||||||
lishwist "lishwist/core"
|
lishwist "lishwist/core"
|
||||||
"lishwist/http/env"
|
"lishwist/http/env"
|
||||||
|
"lishwist/http/response"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/Teajey/rsvp"
|
"github.com/Teajey/rsvp"
|
||||||
|
|
@ -13,7 +14,7 @@ type HealthProps struct {
|
||||||
Config env.Config
|
Config env.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func Health(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func Health(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
if app.Admin() == nil {
|
if app.Admin() == nil {
|
||||||
return rsvp.Ok()
|
return rsvp.Ok()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/Teajey/rsvp"
|
"github.com/Teajey/rsvp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExpectAppSession(next func(*lishwist.Session, http.Header, *http.Request) rsvp.Response) response.HandlerFunc {
|
func ExpectAppSession(next func(*lishwist.Session, *response.Session, http.Header, *http.Request) rsvp.Response) response.HandlerFunc {
|
||||||
return func(session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
return func(session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
sessionKey, ok := session.GetValue("sessionKey").(string)
|
sessionKey, ok := session.GetValue("sessionKey").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -29,6 +29,6 @@ func ExpectAppSession(next func(*lishwist.Session, http.Header, *http.Request) r
|
||||||
return response.Error(http.StatusInternalServerError, "Something went wrong.")
|
return response.Error(http.StatusInternalServerError, "Something went wrong.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(appSession, h, r)
|
return next(appSession, session, h, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ type foreignWishlistProps struct {
|
||||||
Gifts []lishwist.Wish
|
Gifts []lishwist.Wish
|
||||||
}
|
}
|
||||||
|
|
||||||
func ForeignWishlist(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func ForeignWishlist(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
userReference := r.PathValue("userReference")
|
userReference := r.PathValue("userReference")
|
||||||
user := app.User()
|
user := app.User()
|
||||||
if user.Reference == userReference {
|
if user.Reference == userReference {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func AdminGroup(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Resp
|
||||||
return response.Data("group_page.gotmpl", p)
|
return response.Data("group_page.gotmpl", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Group(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func Group(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
user := app.User()
|
user := app.User()
|
||||||
if user.IsAdmin {
|
if user.IsAdmin {
|
||||||
return AdminGroup(app, h, r)
|
return AdminGroup(app, h, r)
|
||||||
|
|
@ -73,7 +73,7 @@ func PublicGroup(s *response.Session, h http.Header, r *http.Request) rsvp.Respo
|
||||||
return response.Data("public_group_page.gotmpl", p)
|
return response.Data("public_group_page.gotmpl", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GroupPost(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func GroupPost(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
admin := app.Admin()
|
admin := app.Admin()
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
return response.NotFound()
|
return response.NotFound()
|
||||||
|
|
@ -138,7 +138,7 @@ func GroupPost(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Respo
|
||||||
return response.Data("", group)
|
return response.Data("", group)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Groups(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func Groups(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
admin := app.Admin()
|
admin := app.Admin()
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
return response.NotFound()
|
return response.NotFound()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ type HomeProps struct {
|
||||||
Groups []lishwist.Group
|
Groups []lishwist.Group
|
||||||
}
|
}
|
||||||
|
|
||||||
func Home(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func Home(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
gifts, err := app.GetWishes()
|
gifts, err := app.GetWishes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get gifts: %s\n", err)
|
log.Printf("Failed to get gifts: %s\n", err)
|
||||||
|
|
@ -41,7 +41,7 @@ func Home(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
return response.Data("home.gotmpl", p)
|
return response.Data("home.gotmpl", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HomePost(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func HomePost(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(http.StatusBadRequest, "Failed to parse form")
|
return response.Error(http.StatusBadRequest, "Failed to parse form")
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/Teajey/rsvp"
|
"github.com/Teajey/rsvp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Users(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func Users(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
admin := app.Admin()
|
admin := app.Admin()
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
return response.NotFound()
|
return response.NotFound()
|
||||||
|
|
@ -22,7 +22,7 @@ func Users(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response
|
||||||
return response.Data("", users)
|
return response.Data("", users)
|
||||||
}
|
}
|
||||||
|
|
||||||
func User(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func User(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
admin := app.Admin()
|
admin := app.Admin()
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
return response.NotFound()
|
return response.NotFound()
|
||||||
|
|
@ -41,7 +41,7 @@ func User(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
return response.Data("", user)
|
return response.Data("", user)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserPost(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func UserPost(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
admin := app.Admin()
|
admin := app.Admin()
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
return response.NotFound()
|
return response.NotFound()
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func WishlistDelete(app *lishwist.Session, h http.Header, r *http.Request) rsvp.
|
||||||
return rsvp.SeeOther("/", "Wish deleted")
|
return rsvp.SeeOther("/", "Wish deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ForeignWishlistPost(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
func ForeignWishlistPost(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(http.StatusBadRequest, "Failed to parse form")
|
return response.Error(http.StatusBadRequest, "Failed to parse form")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue