mirror of https://github.com/JustKato/FreePad.git
parent
d949b3decb
commit
c3c9aacac3
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/JustKato/FreePad/lib/controllers"
|
"github.com/JustKato/FreePad/lib/controllers"
|
||||||
"github.com/JustKato/FreePad/lib/helper"
|
"github.com/JustKato/FreePad/lib/helper"
|
||||||
|
"github.com/JustKato/FreePad/lib/objects"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
|
@ -44,37 +45,40 @@ func AdminRoutes(router *gin.RouterGroup) {
|
||||||
hashHexToken := sha512Hasher.Sum(nil)
|
hashHexToken := sha512Hasher.Sum(nil)
|
||||||
hashToken := hex.EncodeToString(hashHexToken)
|
hashToken := hex.EncodeToString(hashHexToken)
|
||||||
|
|
||||||
fmt.Println(hashToken)
|
|
||||||
|
|
||||||
// Set the cookie
|
// Set the cookie
|
||||||
ctx.SetCookie("admin_token", hashToken, 60*60, "/", helper.GetDomainBase(), true, true)
|
ctx.SetCookie("admin_token", hashToken, 60*60, "/", helper.GetDomainBase(), true, true)
|
||||||
|
|
||||||
ctx.Request.Method = "GET"
|
ctx.Request.Method = "GET"
|
||||||
|
|
||||||
// Redirect the user to the admin page
|
// Redirect the user to the admin page
|
||||||
ctx.Redirect(http.StatusTemporaryRedirect, "/admin")
|
ctx.Redirect(http.StatusFound, "/admin/view")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
ctx.Request.Method = "GET"
|
ctx.Request.Method = "GET"
|
||||||
|
|
||||||
// Redirect the user to the admin page
|
// Redirect the user to the admin page
|
||||||
ctx.Redirect(http.StatusTemporaryRedirect, "/admin/login?fail")
|
ctx.Redirect(http.StatusFound, "/admin/login?fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Admin view route
|
// Admin view route
|
||||||
router.GET("/", func(ctx *gin.Context) {
|
router.GET("/view", func(ctx *gin.Context) {
|
||||||
|
|
||||||
adminToken, err := ctx.Cookie("admin_token")
|
// Get all of the pads as a listing
|
||||||
if err != nil {
|
padList := objects.GetAllPosts()
|
||||||
adminToken = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.JSON(200, gin.H{
|
fmt.Println(padList)
|
||||||
`adminToken`: adminToken,
|
|
||||||
|
padList[0].LastModified
|
||||||
|
|
||||||
|
ctx.HTML(200, "admin_view.html", gin.H{
|
||||||
|
"title": "Admin",
|
||||||
|
"padList": padList,
|
||||||
|
"domain_base": helper.GetDomainBase(),
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue