🐛 Fix get user crashes

This commit is contained in:
LittleSheep 2024-06-22 20:15:01 +08:00
parent 86d302d01e
commit 35d296b501
6 changed files with 21 additions and 21 deletions

View File

@ -46,10 +46,10 @@ func getOngoingCall(c *fiber.Ctx) error {
} }
func startCall(c *fiber.Ctx) error { func startCall(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel var channel models.Channel
@ -76,10 +76,10 @@ func startCall(c *fiber.Ctx) error {
} }
func endCall(c *fiber.Ctx) error { func endCall(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel var channel models.Channel
@ -112,10 +112,10 @@ func endCall(c *fiber.Ctx) error {
} }
func exchangeCallToken(c *fiber.Ctx) error { func exchangeCallToken(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel var channel models.Channel

View File

@ -34,10 +34,10 @@ func listChannelMembers(c *fiber.Ctx) error {
func getMyChannelMembership(c *fiber.Ctx) error { func getMyChannelMembership(c *fiber.Ctx) error {
alias := c.Params("channel") alias := c.Params("channel")
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var err error var err error
var channel models.Channel var channel models.Channel
@ -58,10 +58,10 @@ func getMyChannelMembership(c *fiber.Ctx) error {
} }
func addChannelMember(c *fiber.Ctx) error { func addChannelMember(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var data struct { var data struct {
@ -102,10 +102,10 @@ func addChannelMember(c *fiber.Ctx) error {
} }
func removeChannelMember(c *fiber.Ctx) error { func removeChannelMember(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var data struct { var data struct {
@ -147,10 +147,10 @@ func removeChannelMember(c *fiber.Ctx) error {
} }
func editMyChannelMembership(c *fiber.Ctx) error { func editMyChannelMembership(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var data struct { var data struct {
@ -196,10 +196,10 @@ func editMyChannelMembership(c *fiber.Ctx) error {
} }
func joinChannel(c *fiber.Ctx) error { func joinChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel var channel models.Channel
@ -227,10 +227,10 @@ func joinChannel(c *fiber.Ctx) error {
} }
func leaveChannel(c *fiber.Ctx) error { func leaveChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel var channel models.Channel

View File

@ -29,10 +29,10 @@ func getChannel(c *fiber.Ctx) error {
} }
func getChannelIdentity(c *fiber.Ctx) error { func getChannelIdentity(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var err error var err error
@ -65,10 +65,10 @@ func listChannel(c *fiber.Ctx) error {
} }
func listOwnedChannel(c *fiber.Ctx) error { func listOwnedChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var err error var err error
var channels []models.Channel var channels []models.Channel
@ -85,10 +85,10 @@ func listOwnedChannel(c *fiber.Ctx) error {
} }
func listAvailableChannel(c *fiber.Ctx) error { func listAvailableChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var err error var err error
var channels []models.Channel var channels []models.Channel
@ -105,10 +105,10 @@ func listAvailableChannel(c *fiber.Ctx) error {
} }
func createChannel(c *fiber.Ctx) error { func createChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var data struct { var data struct {
Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"`
@ -159,10 +159,10 @@ func createChannel(c *fiber.Ctx) error {
} }
func editChannel(c *fiber.Ctx) error { func editChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
id, _ := c.ParamsInt("channelId", 0) id, _ := c.ParamsInt("channelId", 0)
var data struct { var data struct {
@ -212,10 +212,10 @@ func editChannel(c *fiber.Ctx) error {
} }
func deleteChannel(c *fiber.Ctx) error { func deleteChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
id, _ := c.ParamsInt("channelId", 0) id, _ := c.ParamsInt("channelId", 0)
tx := database.C.Where(&models.Channel{BaseModel: models.BaseModel{ID: uint(id)}}) tx := database.C.Where(&models.Channel{BaseModel: models.BaseModel{ID: uint(id)}})

View File

@ -12,10 +12,10 @@ import (
) )
func createDirectChannel(c *fiber.Ctx) error { func createDirectChannel(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var data struct { var data struct {
Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"`

View File

@ -12,10 +12,10 @@ import (
) )
func listMessage(c *fiber.Ctx) error { func listMessage(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
take := c.QueryInt("take", 0) take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0) offset := c.QueryInt("offset", 0)
alias := c.Params("channel") alias := c.Params("channel")
@ -46,10 +46,10 @@ func listMessage(c *fiber.Ctx) error {
} }
func newMessage(c *fiber.Ctx) error { func newMessage(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
var data struct { var data struct {
@ -128,10 +128,10 @@ func newMessage(c *fiber.Ctx) error {
} }
func editMessage(c *fiber.Ctx) error { func editMessage(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
messageId, _ := c.ParamsInt("messageId", 0) messageId, _ := c.ParamsInt("messageId", 0)
@ -185,10 +185,10 @@ func editMessage(c *fiber.Ctx) error {
} }
func deleteMessage(c *fiber.Ctx) error { func deleteMessage(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
messageId, _ := c.ParamsInt("messageId", 0) messageId, _ := c.ParamsInt("messageId", 0)

View File

@ -8,10 +8,10 @@ import (
) )
func getUserinfo(c *fiber.Ctx) error { func getUserinfo(c *fiber.Ctx) error {
user := c.Locals("user").(models.Account)
if err := gap.H.EnsureAuthenticated(c); err != nil { if err := gap.H.EnsureAuthenticated(c); err != nil {
return err return err
} }
user := c.Locals("user").(models.Account)
var data models.Account var data models.Account
if err := database.C. if err := database.C.