fix panic

This commit is contained in:
Dot-Rar 2020-04-14 17:11:21 +01:00
parent 66add26714
commit a004352933
15 changed files with 16 additions and 73 deletions

View File

@ -18,11 +18,7 @@ func BlacklistHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -19,11 +19,7 @@ func BlacklistRemoveHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -18,11 +18,7 @@ func LogsHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -22,11 +22,7 @@ func PanelCreateHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -19,11 +19,7 @@ func PanelDeleteHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -26,11 +26,7 @@ func PanelHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -21,11 +21,7 @@ func SendMessage(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -20,11 +20,7 @@ func SettingsHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -20,11 +20,7 @@ func TicketCloseHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -19,11 +19,7 @@ func TicketListHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -25,11 +25,7 @@ func TicketViewHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -20,11 +20,7 @@ func UpdateSettingsHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -22,11 +22,7 @@ func LogViewHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
// Verify the guild exists
guildIdStr := ctx.Param("id")

View File

@ -19,11 +19,7 @@ func IndexHandler(ctx *gin.Context) {
defer store.Save()
if utils.IsLoggedIn(store) {
userId, err := utils.GetUserId(store)
if err != nil {
ctx.String(500, err.Error())
return
}
userId := utils.GetUserId(store)
userGuilds := table.GetGuilds(userId)
adminGuilds := make([]objects.Guild, 0)

View File

@ -2,7 +2,6 @@ package utils
import (
"github.com/gin-gonic/contrib/sessions"
"strconv"
)
func IsLoggedIn(store sessions.Session) bool {
@ -15,6 +14,6 @@ func IsLoggedIn(store sessions.Session) bool {
store.Get("csrf") != nil
}
func GetUserId(store sessions.Session) (uint64, error) {
return strconv.ParseUint(store.Get("userid").(string), 10, 64)
func GetUserId(store sessions.Session) uint64 {
return store.Get("userid").(uint64)
}