Passport/pkg/server/security_api.go

37 lines
892 B
Go
Raw Normal View History

2024-02-01 07:08:40 +00:00
package server
import (
2024-04-13 05:48:19 +00:00
"git.solsynth.dev/hydrogen/passport/pkg/database"
"git.solsynth.dev/hydrogen/passport/pkg/models"
2024-02-01 07:08:40 +00:00
"github.com/gofiber/fiber/v2"
)
2024-04-20 11:04:33 +00:00
func getTickets(c *fiber.Ctx) error {
2024-02-01 07:08:40 +00:00
user := c.Locals("principal").(models.Account)
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
var count int64
2024-04-20 11:04:33 +00:00
var sessions []models.AuthTicket
2024-02-01 07:08:40 +00:00
if err := database.C.
2024-04-20 11:04:33 +00:00
Where(&models.AuthTicket{AccountID: user.ID}).
Model(&models.AuthTicket{}).
2024-02-01 07:08:40 +00:00
Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
if err := database.C.
2024-02-12 04:31:18 +00:00
Order("created_at desc").
2024-04-20 11:04:33 +00:00
Where(&models.AuthTicket{AccountID: user.ID}).
2024-02-01 07:08:40 +00:00
Limit(take).
Offset(offset).
Find(&sessions).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(fiber.Map{
"count": count,
"data": sessions,
})
}