66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package handlers_admin
|
|
|
|
import (
|
|
"CatsOfMastodonBotGo/internal"
|
|
"net/http"
|
|
|
|
requestmodels "CatsOfMastodonBotGo/internal/models/requestModels"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AdminDashboardHandler struct {
|
|
AppContext *internal.AppContext
|
|
}
|
|
|
|
func NewAdminDashboardHandler(appContext *internal.AppContext) *AdminDashboardHandler {
|
|
return &AdminDashboardHandler{
|
|
AppContext: appContext,
|
|
}
|
|
}
|
|
|
|
func (appContext *AdminDashboardHandler) AdminHomePage(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"YouAreOn": "AdminDashboardHomePage",
|
|
})
|
|
}
|
|
|
|
func (appContext *AdminDashboardHandler) ApproveMedia(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"YouAreOn": "ApproveMedia",
|
|
})
|
|
}
|
|
|
|
func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"YouAreOn": "RejectMedia",
|
|
})
|
|
}
|
|
|
|
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
|
|
|
var input requestmodels.LoginInput
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if input.Password == appContext.AppContext.AdminPassword {
|
|
token, err := appContext.AppContext.Jwt.GenerateToken(map[string]interface{}{"role": "admin"})
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token generation failed"})
|
|
return
|
|
}
|
|
|
|
c.SetCookie("token", token, 3600, "/", "", false, true)
|
|
c.JSON(http.StatusOK, gin.H{"message": "Login successful"})
|
|
|
|
} else {
|
|
c.JSON(401, gin.H{
|
|
"YouAreOn": "Unauthorized",
|
|
})
|
|
}
|
|
|
|
}
|