Moved admin to own sub route
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2019-09-03 22:26:01 +02:00
parent c3f683b030
commit 980d0ce019
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 17 additions and 9 deletions

View File

@ -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) {

View File

@ -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);
}, 1000);
*/

View File

@ -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)