shopitems instead rooms
This commit is contained in:
@@ -4,47 +4,47 @@ import(
|
||||
"os"
|
||||
"fmt"
|
||||
"time"
|
||||
"strconv"
|
||||
//"strconv"
|
||||
"net/http"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
|
||||
"example.com/gin/test/models"
|
||||
//"example.com/gin/test/models"
|
||||
"example.com/gin/test/repositories"
|
||||
)
|
||||
|
||||
type AuthValidator struct {
|
||||
}
|
||||
|
||||
func (av *AuthValidator) RequireRoomAdmin(c *gin.Context) {
|
||||
user, exists := c.Get("user")
|
||||
if !exists {
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
roomId, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{ "message": fmt.Sprintf("Room with Id '%s' does not exist", c.Param("id"))})
|
||||
return
|
||||
}
|
||||
|
||||
rooms, err := repositories.Users.GetOwnedRooms(user.(models.User))
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{ "message": "Could not querie owend rooms"})
|
||||
return
|
||||
}
|
||||
|
||||
for _, room := range rooms {
|
||||
if room.ID == uint(roomId) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
}
|
||||
//func (av *AuthValidator) RequireRoomAdmin(c *gin.Context) {
|
||||
// user, exists := c.Get("user")
|
||||
// if !exists {
|
||||
// c.AbortWithStatus(http.StatusUnauthorized)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// roomId, err := strconv.Atoi(c.Param("id"))
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{ "message": fmt.Sprintf("Room with Id '%s' does not exist", c.Param("id"))})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// rooms, err := repositories.Users.GetOwnedRooms(user.(models.User))
|
||||
//
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{ "message": "Could not querie owend rooms"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// for _, room := range rooms {
|
||||
// if room.ID == uint(roomId) {
|
||||
// c.Next()
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// c.AbortWithStatus(http.StatusUnauthorized)
|
||||
//}
|
||||
|
||||
func (av *AuthValidator) RequireAuth(c *gin.Context) {
|
||||
// Get Cookie
|
||||
|
||||
Reference in New Issue
Block a user