diff --git a/assets/js/admin.js b/assets/js/admin.js index 861e0e4..b2be7d3 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -30,7 +30,7 @@ function updateCoins(id) { $('#coins_container_' + id).addClass('disabled'); $.ajax({ - url: '/update', + url: '/admin/update', method: 'POST', data: 'id=' + id + '&addcoins=' + addcoins, success: function (msg) { @@ -64,7 +64,7 @@ function deleteKonfi(id) { }, onApprove : function() { $.ajax({ - url: '/delete', + url: '/admin/delete', method: 'POST', data: 'id=' + id, success: function (msg) { @@ -97,7 +97,7 @@ function deleteGemeinde(id) { }, onApprove : function() { $.ajax({ - url: '/delete', + url: '/admin/delete', method: 'POST', data: 'id=' + id, success: function (msg) { @@ -124,7 +124,7 @@ $('.ui.kofiadd.modal') onApprove : function() { $('.loader').addClass('active'); $.ajax({ - url: '/add', + url: '/admin/add', method: 'POST', data: 'name=' + $('#name').val() + '&gemeinde=' + $('#gemeinde').val(), success: function (msg) { @@ -152,7 +152,7 @@ $('.ui.gemeindeadd.modal') onApprove : function() { $('.loader').addClass('active'); $.ajax({ - url: '/add', + url: '/admin/add', method: 'POST', data: 'name=' + $('#name').val() + '&konfis=' + $('#konfis').val(), success: function (msg) { diff --git a/assets/js/load.js b/assets/js/load.js index b2f593c..30e76c4 100644 --- a/assets/js/load.js +++ b/assets/js/load.js @@ -1,3 +1,9 @@ +const source = new EventSource('/events'); +source.onmessage = function(e) { + console.log(e) +}; + +/* setInterval(function() { $.getJSON('/list', function (data) { $( "#konfis" ).html(''); @@ -17,4 +23,5 @@ setInterval(function() { } }); }); -}, 1000); \ No newline at end of file +}, 1000); + */ diff --git a/pkg/router/router.go b/pkg/router/router.go index 1b79345..67946bf 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -39,7 +39,6 @@ func RegisterRoutes(e *echo.Echo) { e.Static("/assets", "assets") //Routes - e.GET("/admin", adminHandler) e.GET("/", showList) e.POST("/login", login) @@ -72,15 +71,17 @@ func RegisterRoutes(e *echo.Echo) { e.GET("/list", handler.ReadAll) // Routes with auth - a := e.Group("") + a := e.Group("/admin") a.Use(func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { - if !isLoggedIn(c) { + // Only check if the user is logged in if the path is not /admin, to still be able to show the login page + if c.Path() != "/admin" && !isLoggedIn(c) { return echo.NewHTTPError(http.StatusForbidden, "Login first.") } return next(c) } }) + a.GET("", adminHandler) a.POST("/update", handler.Update) a.POST("/delete", handler.Delete) a.POST("/add", handler.Create)