features/bootstrapping #1
23
internal/handlers/debug.go
Normal file
23
internal/handlers/debug.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
||||||
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
|
||||||
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/debug"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *Handler) DebugCookies(c echo.Context) error {
|
||||||
|
user, _ := c.Cookie(domain.CookieUser)
|
||||||
|
token, _ := c.Cookie(domain.CookieToken)
|
||||||
|
refresh, _ := c.Cookie(domain.CookieRefreshToken)
|
||||||
|
|
||||||
|
model := models.DebugCookiesViewModel{
|
||||||
|
Username: user.Value,
|
||||||
|
Token: token.Value,
|
||||||
|
RefreshToken: refresh.Value,
|
||||||
|
}
|
||||||
|
return Render(c, http.StatusOK, debug.Cookies(model))
|
||||||
|
}
|
@ -60,6 +60,12 @@ func NewServer(ctx context.Context, configs config.Configs, apiClient apiclient.
|
|||||||
router.GET("/", s.HomeIndex)
|
router.GET("/", s.HomeIndex)
|
||||||
router.GET("/about", s.HomeAbout)
|
router.GET("/about", s.HomeAbout)
|
||||||
|
|
||||||
|
debug := router.Group("/debug")
|
||||||
|
debug.GET("/cookies", s.DebugCookies)
|
||||||
|
|
||||||
|
articles := router.Group("/articles")
|
||||||
|
articles.GET("", s.ArticlesList)
|
||||||
|
|
||||||
users := router.Group("/users")
|
users := router.Group("/users")
|
||||||
users.GET("/login", s.UserLogin)
|
users.GET("/login", s.UserLogin)
|
||||||
users.POST("/login", s.UserAfterLogin)
|
users.POST("/login", s.UserAfterLogin)
|
||||||
|
14
internal/handlers/util.go
Normal file
14
internal/handlers/util.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetCookie(c echo.Context, key string, value string) {
|
||||||
|
cookie := new(http.Cookie)
|
||||||
|
cookie.Name = key
|
||||||
|
cookie.Value = value
|
||||||
|
c.SetCookie(cookie)
|
||||||
|
}
|
7
internal/models/debug.go
Normal file
7
internal/models/debug.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type DebugCookiesViewModel struct {
|
||||||
|
Username string
|
||||||
|
Token string
|
||||||
|
RefreshToken string
|
||||||
|
}
|
12
internal/views/debug/cookies.templ
Normal file
12
internal/views/debug/cookies.templ
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
|
||||||
|
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
|
||||||
|
|
||||||
|
templ Cookies(vm models.DebugCookiesViewModel) {
|
||||||
|
@layout.WithTemplate() {
|
||||||
|
Token: { vm.Token }
|
||||||
|
RefreshToken: { vm.RefreshToken }
|
||||||
|
UserName: { vm.Username }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user