⏪ Revert "♻️ Move models.Account to sec.UserInfo" for a better solution
This reverts commit 8fbb7960
This commit is contained in:
parent
69c6ac6581
commit
2fcc784bc4
10
go.sum
10
go.sum
@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
|
|||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
git.solsynth.dev/hypernet/nexus v0.0.0-20241024155238-421834ae5c4a h1:yl2cnfFvvgOGwr9qoWu4QQHVpVPCI9f1idyaKt2gXxo=
|
||||||
|
git.solsynth.dev/hypernet/nexus v0.0.0-20241024155238-421834ae5c4a/go.mod h1:68l4+CkuG3sz9aiUhbN5tq3YHrt6KUNK9FIWaGuWCdc=
|
||||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241026162044-3d487fa48baf h1:Fil1ASTvxmqFySD3OoptC7uRXEYpWLwLfjlkWZNNwVQ=
|
git.solsynth.dev/hypernet/nexus v0.0.0-20241026162044-3d487fa48baf h1:Fil1ASTvxmqFySD3OoptC7uRXEYpWLwLfjlkWZNNwVQ=
|
||||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241026162044-3d487fa48baf/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
|
git.solsynth.dev/hypernet/nexus v0.0.0-20241026162044-3d487fa48baf/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
|
||||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241030153633-427c83e38fe4 h1:UTptbxd2b6RFKu0tr2RmQjNnqde/M0JVO4nZk7ntUYo=
|
git.solsynth.dev/hypernet/nexus v0.0.0-20241030153633-427c83e38fe4 h1:UTptbxd2b6RFKu0tr2RmQjNnqde/M0JVO4nZk7ntUYo=
|
||||||
@ -258,10 +260,16 @@ github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfE
|
|||||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
|
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
|
||||||
|
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
|
||||||
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
|
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
|
||||||
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
|
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
@ -793,6 +801,8 @@ gorm.io/datatypes v1.2.4 h1:uZmGAcK/QZ0uyfCuVg0VQY1ZmV9h1fuG0tMwKByO1z4=
|
|||||||
gorm.io/datatypes v1.2.4/go.mod h1:f4BsLcFAX67szSv8svwLRjklArSHAvHLeE3pXAS5DZI=
|
gorm.io/datatypes v1.2.4/go.mod h1:f4BsLcFAX67szSv8svwLRjklArSHAvHLeE3pXAS5DZI=
|
||||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||||
|
gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
|
||||||
|
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
|
||||||
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
|
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
|
||||||
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
||||||
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
|
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
|
||||||
|
@ -2,21 +2,18 @@ package gap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit/pushcon"
|
"git.solsynth.dev/hypernet/pusher/pkg/pushkit/pushcon"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var Nx *nex.Conn
|
||||||
Nx *nex.Conn
|
var Px *pushcon.Conn
|
||||||
Px *pushcon.Conn
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitializeToNexus() error {
|
func InitializeToNexus() error {
|
||||||
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
||||||
@ -33,7 +30,7 @@ func InitializeToNexus() error {
|
|||||||
Type: nex.ServiceTypeAuth,
|
Type: nex.ServiceTypeAuth,
|
||||||
Label: "Passport",
|
Label: "Passport",
|
||||||
GrpcAddr: grpcOutbound,
|
GrpcAddr: grpcOutbound,
|
||||||
HttpAddr: lo.ToPtr("http://" + httpOutbound + "/api"),
|
HttpAddr: lo.ToPtr("http://" + httpOutbound),
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -45,7 +45,7 @@ func (v *App) ListAvailableRealm(ctx context.Context, request *proto.LookupUserR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to find target account: %v", err)
|
return nil, fmt.Errorf("unable to find target account: %v", err)
|
||||||
}
|
}
|
||||||
realms, err := services.ListAvailableRealm(account.ID)
|
realms, err := services.ListAvailableRealm(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (v *App) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRealm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to find target account: %v", err)
|
return nil, fmt.Errorf("unable to find target account: %v", err)
|
||||||
}
|
}
|
||||||
realms, err := services.ListOwnedRealm(account.ID)
|
realms, err := services.ListOwnedRealm(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
@ -28,13 +27,13 @@ func notifyAllUser(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "AdminNotifyAll", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "AdminNotifyAll", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
operator := c.Locals("user").(*sec.UserInfo)
|
operator := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var users []models.Account
|
var users []models.Account
|
||||||
if err := database.C.Find(&users).Error; err != nil {
|
if err := database.C.Find(&users).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddAuditRecord(operator.ID, "notify.all", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
services.AddAuditRecord(operator, "notify.all", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
||||||
"payload": data,
|
"payload": data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -86,13 +85,13 @@ func notifyOneUser(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "AdminNotifyAll", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "AdminNotifyAll", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
operator := c.Locals("user").(*sec.UserInfo)
|
operator := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var user models.Account
|
var user models.Account
|
||||||
if err := database.C.Where("id = ?", data.UserID).First(&user).Error; err != nil {
|
if err := database.C.Where("id = ?", data.UserID).First(&user).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddAuditRecord(operator.ID, "notify.one", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
services.AddAuditRecord(operator, "notify.one", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
||||||
"user_id": user.ID,
|
"user_id": user.ID,
|
||||||
"payload": data,
|
"payload": data,
|
||||||
})
|
})
|
||||||
|
@ -2,11 +2,10 @@ package admin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
@ -17,7 +16,7 @@ func editUserPermission(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "AdminUserPermission", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "AdminUserPermission", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
operator := c.Locals("user").(*sec.UserInfo)
|
operator := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
PermNodes map[string]any `json:"perm_nodes" validate:"required"`
|
PermNodes map[string]any `json:"perm_nodes" validate:"required"`
|
||||||
@ -40,7 +39,7 @@ func editUserPermission(c *fiber.Ctx) error {
|
|||||||
if err := database.C.Save(&user).Error; err != nil {
|
if err := database.C.Save(&user).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddAuditRecord(operator.ID, "user.permissions.edit", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
services.AddAuditRecord(operator, "user.permissions.edit", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
||||||
"user_id": user.ID,
|
"user_id": user.ID,
|
||||||
"previous_permissions": prev,
|
"previous_permissions": prev,
|
||||||
"new_permissions": data.PermNodes,
|
"new_permissions": data.PermNodes,
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ func forceConfirmAccount(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "AdminUserConfirmation", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "AdminUserConfirmation", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
operator := c.Locals("user").(*sec.UserInfo)
|
operator := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var user models.Account
|
var user models.Account
|
||||||
if err := database.C.Where("id = ?", userId).First(&user).Error; err != nil {
|
if err := database.C.Where("id = ?", userId).First(&user).Error; err != nil {
|
||||||
@ -64,7 +63,7 @@ func forceConfirmAccount(c *fiber.Ctx) error {
|
|||||||
if err := services.ForceConfirmAccount(user); err != nil {
|
if err := services.ForceConfirmAccount(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddAuditRecord(operator.ID, "user.confirm", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
services.AddAuditRecord(operator, "user.confirm", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
||||||
"user_id": user.ID,
|
"user_id": user.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -11,6 +9,7 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@ -49,7 +48,7 @@ func getUserinfo(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data models.Account
|
var data models.Account
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
@ -60,7 +59,7 @@ func getUserinfo(c *fiber.Ctx) error {
|
|||||||
First(&data).Error; err != nil {
|
First(&data).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
data.PermNodes = user.PermNodes
|
data.PermNodes = c.Locals("permissions").(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp fiber.Map
|
var resp fiber.Map
|
||||||
@ -85,7 +84,7 @@ func getEvents(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
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)
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ func editUserinfo(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Nick string `json:"nick" validate:"required"`
|
Nick string `json:"nick" validate:"required"`
|
||||||
@ -223,16 +222,11 @@ func requestDeleteAccount(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var account models.Account
|
if err := services.CheckAbleToDeleteAccount(user); err != nil {
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := services.CheckAbleToDeleteAccount(account); err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else if err = services.RequestDeleteAccount(account); err != nil {
|
} else if err = services.RequestDeleteAccount(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -15,7 +13,7 @@ func setAvatar(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
AttachmentID string `json:"attachment" validate:"required"`
|
AttachmentID string `json:"attachment" validate:"required"`
|
||||||
@ -25,7 +23,9 @@ func setAvatar(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.C.Where("id = ?", user.ID).Updates(&models.Account{Avatar: &data.AttachmentID}).Error; err != nil {
|
user.Avatar = &data.AttachmentID
|
||||||
|
|
||||||
|
if err := database.C.Save(&user).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "profile.edit.avatar", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "profile.edit.avatar", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
@ -39,7 +39,7 @@ func setBanner(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
AttachmentID string `json:"attachment" validate:"required"`
|
AttachmentID string `json:"attachment" validate:"required"`
|
||||||
@ -49,7 +49,9 @@ func setBanner(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.C.Where("id = ?", user.ID).Updates(&models.Account{Banner: &data.AttachmentID}).Error; err != nil {
|
user.Banner = &data.AttachmentID
|
||||||
|
|
||||||
|
if err := database.C.Save(&user).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "profile.edit.banner", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "profile.edit.banner", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
@ -63,14 +65,9 @@ func getAvatar(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var account models.Account
|
if content := user.GetAvatar(); content == nil {
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if content := account.GetAvatar(); content == nil {
|
|
||||||
return c.SendStatus(fiber.StatusNotFound)
|
return c.SendStatus(fiber.StatusNotFound)
|
||||||
} else {
|
} else {
|
||||||
return c.Redirect(*content, fiber.StatusFound)
|
return c.Redirect(*content, fiber.StatusFound)
|
||||||
@ -81,14 +78,9 @@ func getBanner(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var account models.Account
|
if content := user.GetBanner(); content == nil {
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if content := account.GetBanner(); content == nil {
|
|
||||||
return c.SendStatus(fiber.StatusNotFound)
|
return c.SendStatus(fiber.StatusNotFound)
|
||||||
} else {
|
} else {
|
||||||
return c.Redirect(*content, fiber.StatusFound)
|
return c.Redirect(*content, fiber.StatusFound)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -15,7 +14,7 @@ func listBotKeys(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var tx *gorm.DB
|
var tx *gorm.DB
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ func getBotKey(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
id, _ := c.ParamsInt("id", 0)
|
id, _ := c.ParamsInt("id", 0)
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ func createBotKey(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
@ -83,7 +82,7 @@ func createBotKey(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var target models.Account
|
target := user
|
||||||
|
|
||||||
botId, _ := c.ParamsInt("botId", 0)
|
botId, _ := c.ParamsInt("botId", 0)
|
||||||
if botId > 0 {
|
if botId > 0 {
|
||||||
@ -92,12 +91,6 @@ func createBotKey(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("bot not found: %v", err))
|
return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("bot not found: %v", err))
|
||||||
}
|
}
|
||||||
target = bot
|
target = bot
|
||||||
} else {
|
|
||||||
var account models.Account
|
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("account not found: %v", err))
|
|
||||||
}
|
|
||||||
target = account
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := services.NewApiKey(target, models.ApiKey{
|
key, err := services.NewApiKey(target, models.ApiKey{
|
||||||
@ -116,7 +109,7 @@ func editBotKey(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
@ -163,7 +156,7 @@ func rollBotKey(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
id, _ := c.ParamsInt("id", 0)
|
id, _ := c.ParamsInt("id", 0)
|
||||||
|
|
||||||
@ -196,7 +189,7 @@ func revokeBotKey(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
id, _ := c.ParamsInt("id", 0)
|
id, _ := c.ParamsInt("id", 0)
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
@ -18,7 +16,7 @@ func listBots(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
tx := database.C.Where("automated_id = ?", user.ID)
|
tx := database.C.Where("automated_id = ?", user.ID)
|
||||||
|
|
||||||
@ -43,9 +41,9 @@ func createBot(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
cnt, _ := services.GetBotCount(user.ID)
|
cnt, _ := services.GetBotCount(user)
|
||||||
if err := exts.EnsureGrantedPerm(c, "CreateBots", cnt+1); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "CreateBots", cnt+1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -67,14 +65,7 @@ func createBot(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, "invalid bot nick, length requires 4 to 24")
|
return fiber.NewError(fiber.StatusBadRequest, "invalid bot nick, length requires 4 to 24")
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
bot, err := services.NewBot(user, models.Account{
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
Name: data.Name,
|
|
||||||
}).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
bot, err := services.NewBot(account, models.Account{
|
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Nick: data.Nick,
|
Nick: data.Nick,
|
||||||
Description: data.Description,
|
Description: data.Description,
|
||||||
@ -93,7 +84,7 @@ func deleteBot(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
id, _ := c.ParamsInt("botId", 0)
|
id, _ := c.ParamsInt("botId", 0)
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
|
|
||||||
notify := api.Group("/notifications").Name("Notifications API")
|
notify := api.Group("/notifications").Name("Notifications API")
|
||||||
{
|
{
|
||||||
|
// Deprecated, use /subscription instead, will be removed in the future
|
||||||
|
notify.Post("/subscribe", addNotifySubscriber)
|
||||||
|
|
||||||
notify.Get("/", getNotifications)
|
notify.Get("/", getNotifications)
|
||||||
notify.Get("/subscription", getNotifySubscriber)
|
notify.Get("/subscription", getNotifySubscriber)
|
||||||
notify.Post("/subscription", addNotifySubscriber)
|
notify.Post("/subscription", addNotifySubscriber)
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -20,7 +18,7 @@ func getNotifications(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
tx := database.C.Where(&models.Notification{AccountID: user.ID}).Model(&models.Notification{})
|
tx := database.C.Where(&models.Notification{AccountID: user.ID}).Model(&models.Notification{})
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ func markNotificationRead(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
id, _ := c.ParamsInt("notificationId", 0)
|
id, _ := c.ParamsInt("notificationId", 0)
|
||||||
|
|
||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
@ -78,7 +76,7 @@ func markNotificationReadBatch(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
MessageIDs []uint `json:"messages"`
|
MessageIDs []uint `json:"messages"`
|
||||||
@ -102,7 +100,7 @@ func getNotifySubscriber(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var subscribers []models.NotificationSubscriber
|
var subscribers []models.NotificationSubscriber
|
||||||
if err := database.C.Where(&models.NotificationSubscriber{
|
if err := database.C.Where(&models.NotificationSubscriber{
|
||||||
@ -118,7 +116,7 @@ func addNotifySubscriber(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Provider string `json:"provider" validate:"required"`
|
Provider string `json:"provider" validate:"required"`
|
||||||
@ -139,13 +137,8 @@ func addNotifySubscriber(c *fiber.Ctx) error {
|
|||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
subscriber, err := services.AddNotifySubscriber(
|
subscriber, err := services.AddNotifySubscriber(
|
||||||
account,
|
user,
|
||||||
data.Provider,
|
data.Provider,
|
||||||
data.DeviceID,
|
data.DeviceID,
|
||||||
data.DeviceToken,
|
data.DeviceToken,
|
||||||
@ -163,7 +156,7 @@ func removeNotifySubscriber(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
device := c.Params("deviceId")
|
device := c.Params("deviceId")
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
@ -14,7 +13,7 @@ func notifyUser(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "DevNotifyUser", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "DevNotifyUser", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
ClientID string `json:"client_id" validate:"required"`
|
ClientID string `json:"client_id" validate:"required"`
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@ -33,7 +31,7 @@ func tryAuthorizeThirdClient(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var ticket models.AuthTicket
|
var ticket models.AuthTicket
|
||||||
if err := database.C.Where(&models.AuthTicket{
|
if err := database.C.Where(&models.AuthTicket{
|
||||||
@ -74,23 +72,18 @@ func authorizeThirdClient(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var client models.ThirdClient
|
var client models.ThirdClient
|
||||||
if err := database.C.Where(&models.ThirdClient{Alias: id}).First(&client).Error; err != nil {
|
if err := database.C.Where(&models.ThirdClient{Alias: id}).First(&client).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
|
||||||
if err := database.C.Where("id = ?", user.ID).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
switch response {
|
switch response {
|
||||||
case "code":
|
case "code":
|
||||||
// OAuth Authorization Mode
|
// OAuth Authorization Mode
|
||||||
ticket, err := services.NewOauthTicket(
|
ticket, err := services.NewOauthTicket(
|
||||||
account,
|
user,
|
||||||
client,
|
client,
|
||||||
strings.Split(scope, " "),
|
strings.Split(scope, " "),
|
||||||
[]string{services.InternalTokenAudience, client.Alias},
|
[]string{services.InternalTokenAudience, client.Alias},
|
||||||
@ -111,7 +104,7 @@ func authorizeThirdClient(c *fiber.Ctx) error {
|
|||||||
case "token":
|
case "token":
|
||||||
// OAuth Implicit Mode
|
// OAuth Implicit Mode
|
||||||
ticket, err := services.NewOauthTicket(
|
ticket, err := services.NewOauthTicket(
|
||||||
account,
|
user,
|
||||||
client,
|
client,
|
||||||
strings.Split(scope, " "),
|
strings.Split(scope, " "),
|
||||||
[]string{services.InternalTokenAudience, client.Alias},
|
[]string{services.InternalTokenAudience, client.Alias},
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,9 +11,9 @@ func getAuthPreference(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
cfg, err := services.GetAuthPreference(user.ID)
|
cfg, err := services.GetAuthPreference(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
@ -26,14 +25,14 @@ func updateAuthPreference(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data models.AuthConfig
|
var data models.AuthConfig
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := services.UpdateAuthPreference(user.ID, data)
|
cfg, err := services.UpdateAuthPreference(user, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
@ -47,8 +46,8 @@ func getNotificationPreference(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
notification, err := services.GetNotificationPreference(user.ID)
|
notification, err := services.GetNotificationPreference(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
@ -60,7 +59,7 @@ func updateNotificationPreference(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Config map[string]bool `json:"config"`
|
Config map[string]bool `json:"config"`
|
||||||
@ -70,7 +69,7 @@ func updateNotificationPreference(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
notification, err := services.UpdateNotificationPreference(user.ID, data.Config)
|
notification, err := services.UpdateNotificationPreference(user, data.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ func getMyRealmMember(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
if realm, err := services.GetRealmWithAlias(alias); err != nil {
|
if realm, err := services.GetRealmWithAlias(alias); err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
@ -41,7 +40,7 @@ func addRealmMember(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
alias := c.Params("realm")
|
alias := c.Params("realm")
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -64,7 +63,7 @@ func addRealmMember(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := services.AddRealmMember(user.ID, account, realm); err != nil {
|
if err := services.AddRealmMember(user, account, realm); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
@ -75,7 +74,7 @@ func removeRealmMember(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
alias := c.Params("realm")
|
alias := c.Params("realm")
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -98,7 +97,7 @@ func removeRealmMember(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := services.RemoveRealmMember(user.ID, account, realm); err != nil {
|
if err := services.RemoveRealmMember(user, account, realm); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
@ -109,7 +108,7 @@ func leaveRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
alias := c.Params("realm")
|
alias := c.Params("realm")
|
||||||
|
|
||||||
realm, err := services.GetRealmWithAlias(alias)
|
realm, err := services.GetRealmWithAlias(alias)
|
||||||
@ -126,7 +125,7 @@ func leaveRealm(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := services.RemoveRealmMember(user.ID, account, realm); err != nil {
|
if err := services.RemoveRealmMember(user, account, realm); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -32,8 +31,8 @@ func listOwnedRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
if realms, err := services.ListOwnedRealm(user.ID); err != nil {
|
if realms, err := services.ListOwnedRealm(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.JSON(realms)
|
return c.JSON(realms)
|
||||||
@ -44,8 +43,8 @@ func listAvailableRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
if realms, err := services.ListAvailableRealm(user.ID); err != nil {
|
if realms, err := services.ListAvailableRealm(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.JSON(realms)
|
return c.JSON(realms)
|
||||||
@ -56,7 +55,7 @@ func createRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureGrantedPerm(c, "CreateRealms", true); err != nil {
|
if err := exts.EnsureGrantedPerm(c, "CreateRealms", true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
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"`
|
||||||
@ -83,7 +82,7 @@ func createRealm(c *fiber.Ctx) error {
|
|||||||
IsPublic: data.IsPublic,
|
IsPublic: data.IsPublic,
|
||||||
IsCommunity: data.IsCommunity,
|
IsCommunity: data.IsCommunity,
|
||||||
AccountID: user.ID,
|
AccountID: user.ID,
|
||||||
}, user.ID)
|
}, user)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
@ -98,7 +97,7 @@ func editRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
id, _ := c.ParamsInt("realmId", 0)
|
id, _ := c.ParamsInt("realmId", 0)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -147,7 +146,7 @@ func deleteRealm(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
id, _ := c.ParamsInt("realmId", 0)
|
id, _ := c.ParamsInt("realmId", 0)
|
||||||
|
|
||||||
var realm models.Realm
|
var realm models.Realm
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -14,17 +12,17 @@ func listRelationship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
status := c.QueryInt("status", -1)
|
status := c.QueryInt("status", -1)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var friends []models.AccountRelationship
|
var friends []models.AccountRelationship
|
||||||
if status < 0 {
|
if status < 0 {
|
||||||
if friends, err = services.ListAllRelationship(user.ID); err != nil {
|
if friends, err = services.ListAllRelationship(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if friends, err = services.ListRelationshipWithFilter(user.ID, models.RelationshipStatus(status)); err != nil {
|
if friends, err = services.ListRelationshipWithFilter(user, models.RelationshipStatus(status)); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +34,7 @@ func getRelationship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
related, err := services.GetAccount(uint(relatedId))
|
related, err := services.GetAccount(uint(relatedId))
|
||||||
@ -55,7 +53,7 @@ func editRelationship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -87,7 +85,7 @@ func deleteRelationship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
related, err := services.GetAccount(uint(relatedId))
|
related, err := services.GetAccount(uint(relatedId))
|
||||||
@ -113,7 +111,7 @@ func makeFriendship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedName := c.Query("related")
|
relatedName := c.Query("related")
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
@ -133,14 +131,7 @@ func makeFriendship(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id")
|
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id")
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
friend, err := services.NewFriend(user, related)
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
BaseModel: models.BaseModel{ID: user.ID},
|
|
||||||
}).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
friend, err := services.NewFriend(account, related)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
@ -153,7 +144,7 @@ func makeBlockship(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedName := c.Query("related")
|
relatedName := c.Query("related")
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
@ -173,14 +164,7 @@ func makeBlockship(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id")
|
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id")
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
friend, err := services.NewBlockship(user, related)
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
BaseModel: models.BaseModel{ID: user.ID},
|
|
||||||
}).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
friend, err := services.NewBlockship(account, related)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
@ -193,22 +177,15 @@ func acceptFriend(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
var account models.Account
|
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
BaseModel: models.BaseModel{ID: user.ID},
|
|
||||||
}).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
related, err := services.GetAccount(uint(relatedId))
|
related, err := services.GetAccount(uint(relatedId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := services.HandleFriend(account, related, true); err != nil {
|
if err := services.HandleFriend(user, related, true); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "relationships.friends.accept", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "relationships.friends.accept", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
@ -220,7 +197,7 @@ func declineFriend(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||||
|
|
||||||
related, err := services.GetAccount(uint(relatedId))
|
related, err := services.GetAccount(uint(relatedId))
|
||||||
@ -228,14 +205,7 @@ func declineFriend(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var account models.Account
|
if err := services.HandleFriend(user, related, false); err != nil {
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
BaseModel: models.BaseModel{ID: user.ID},
|
|
||||||
}).First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := services.HandleFriend(account, related, false); err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "relationships.friends.decline", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "relationships.friends.decline", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
|
@ -2,8 +2,8 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,9 +11,9 @@ func listAbuseReports(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
reports, err := services.ListAbuseReport(user.ID)
|
reports, err := services.ListAbuseReport(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func createAbuseReport(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Resource string `json:"resource" validate:"required"`
|
Resource string `json:"resource" validate:"required"`
|
||||||
@ -69,7 +69,7 @@ func createAbuseReport(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := services.NewAbuseReport(data.Resource, data.Reason, user.ID)
|
report, err := services.NewAbuseReport(data.Resource, data.Reason, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ func getTickets(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
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)
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ func killTicket(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
id, _ := c.ParamsInt("ticketId", 0)
|
id, _ := c.ParamsInt("ticketId", 0)
|
||||||
|
|
||||||
if err := database.C.Delete(&models.AuthTicket{}, &models.AuthTicket{
|
if err := database.C.Delete(&models.AuthTicket{}, &models.AuthTicket{
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -17,7 +16,7 @@ func listDailySignRecord(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
@ -82,9 +81,9 @@ func getTodayDailySign(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
if record, err := services.GetTodayDailySign(user.ID); err != nil {
|
if record, err := services.GetTodayDailySign(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.JSON(record)
|
return c.JSON(record)
|
||||||
@ -95,9 +94,9 @@ func doDailySign(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
if record, err := services.DailySign(user.ID); err != nil {
|
if record, err := services.DailySign(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "dailySign", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "dailySign", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
|
@ -2,13 +2,12 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/http/exts"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@ -40,22 +39,15 @@ func getMyselfStatus(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
status, err := services.GetStatus(user.ID)
|
status, err := services.GetStatus(user.ID)
|
||||||
disturbable := services.GetStatusDisturbable(user.ID) == nil
|
disturbable := services.GetStatusDisturbable(user.ID) == nil
|
||||||
online := services.GetStatusOnline(user.ID) == nil
|
online := services.GetStatusOnline(user.ID) == nil
|
||||||
|
|
||||||
var account models.Account
|
|
||||||
if err := database.C.Where(&models.Account{
|
|
||||||
BaseModel: models.BaseModel{ID: user.ID},
|
|
||||||
}).Preload("Profile").First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
"status": lo.Ternary(err == nil, &status, nil),
|
"status": lo.Ternary(err == nil, &status, nil),
|
||||||
"last_seen_at": account.Profile.LastSeenAt,
|
"last_seen_at": user.Profile.LastSeenAt,
|
||||||
"is_disturbable": disturbable,
|
"is_disturbable": disturbable,
|
||||||
"is_online": online,
|
"is_online": online,
|
||||||
})
|
})
|
||||||
@ -65,7 +57,7 @@ func setStatus(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var req struct {
|
var req struct {
|
||||||
Type string `json:"type" validate:"required"`
|
Type string `json:"type" validate:"required"`
|
||||||
@ -96,7 +88,7 @@ func setStatus(c *fiber.Ctx) error {
|
|||||||
AccountID: user.ID,
|
AccountID: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, err := services.NewStatus(user.ID, status); err != nil {
|
if status, err := services.NewStatus(user, status); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "statuses.set", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "statuses.set", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
@ -108,7 +100,7 @@ func editStatus(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
var req struct {
|
var req struct {
|
||||||
Type string `json:"type" validate:"required"`
|
Type string `json:"type" validate:"required"`
|
||||||
@ -135,7 +127,7 @@ func editStatus(c *fiber.Ctx) error {
|
|||||||
status.IsInvisible = req.IsInvisible
|
status.IsInvisible = req.IsInvisible
|
||||||
status.ClearAt = req.ClearAt
|
status.ClearAt = req.ClearAt
|
||||||
|
|
||||||
if status, err := services.EditStatus(user.ID, status); err != nil {
|
if status, err := services.EditStatus(user, status); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "statuses.edit", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "statuses.edit", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
@ -147,9 +139,9 @@ func clearStatus(c *fiber.Ctx) error {
|
|||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := c.Locals("user").(*sec.UserInfo)
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
if err := services.ClearStatus(user.ID); err != nil {
|
if err := services.ClearStatus(user); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
services.AddEvent(user.ID, "statuses.clear", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
services.AddEvent(user.ID, "statuses.clear", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||||
|
@ -2,13 +2,13 @@ package exts
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnsureAuthenticated(c *fiber.Ctx) error {
|
func EnsureAuthenticated(c *fiber.Ctx) error {
|
||||||
if _, ok := c.Locals("user").(*sec.UserInfo); !ok {
|
if _, ok := c.Locals("user").(models.Account); !ok {
|
||||||
return fiber.NewError(fiber.StatusUnauthorized)
|
return fiber.NewError(fiber.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/authkit"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -57,7 +56,6 @@ func NewServer() *App {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
app.Use(sec.ContextMiddleware(IReader))
|
app.Use(sec.ContextMiddleware(IReader))
|
||||||
app.Use(authkit.ParseAccountMiddleware)
|
|
||||||
|
|
||||||
admin.MapAdminAPIs(app, "/api/admin")
|
admin.MapAdminAPIs(app, "/api/admin")
|
||||||
api.MapAPIs(app, "/api")
|
api.MapAPIs(app, "/api")
|
||||||
|
@ -5,9 +5,9 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBotCount(user uint) (int64, error) {
|
func GetBotCount(user models.Account) (int64, error) {
|
||||||
var count int64
|
var count int64
|
||||||
if err := database.C.Where("automated_id = ?", user).Count(&count).Error; err != nil {
|
if err := database.C.Where("automated_id = ?", user.ID).Count(&count).Error; err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return count, nil
|
return count, nil
|
||||||
|
@ -21,13 +21,13 @@ func AddEvent(user uint, event, target, ip, ua string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddAuditRecord to keep logs to make administrators' operations clear to query
|
// AddAuditRecord to keep logs to make administrators' operations clear to query
|
||||||
func AddAuditRecord(operator uint, act, ip, ua string, metadata map[string]any) {
|
func AddAuditRecord(operator models.Account, act, ip, ua string, metadata map[string]any) {
|
||||||
writeAuditQueue = append(writeAuditQueue, models.AuditRecord{
|
writeAuditQueue = append(writeAuditQueue, models.AuditRecord{
|
||||||
Action: act,
|
Action: act,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
IpAddress: ip,
|
IpAddress: ip,
|
||||||
UserAgent: ua,
|
UserAgent: ua,
|
||||||
AccountID: operator,
|
AccountID: operator.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,21 +15,21 @@ import (
|
|||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAuthPreference(account uint) (models.PreferenceAuth, error) {
|
func GetAuthPreference(account models.Account) (models.PreferenceAuth, error) {
|
||||||
var auth models.PreferenceAuth
|
var auth models.PreferenceAuth
|
||||||
if err := database.C.Where("account_id = ?", account).First(&auth).Error; err != nil {
|
if err := database.C.Where("account_id = ?", account.ID).First(&auth).Error; err != nil {
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return auth, nil
|
return auth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAuthPreference(account uint, config models.AuthConfig) (models.PreferenceAuth, error) {
|
func UpdateAuthPreference(account models.Account, config models.AuthConfig) (models.PreferenceAuth, error) {
|
||||||
var auth models.PreferenceAuth
|
var auth models.PreferenceAuth
|
||||||
var err error
|
var err error
|
||||||
if auth, err = GetAuthPreference(account); err != nil {
|
if auth, err = GetAuthPreference(account); err != nil {
|
||||||
auth = models.PreferenceAuth{
|
auth = models.PreferenceAuth{
|
||||||
AccountID: account,
|
AccountID: account.ID,
|
||||||
Config: datatypes.NewJSONType(config),
|
Config: datatypes.NewJSONType(config),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -44,16 +44,16 @@ func GetNotificationPreferenceCacheKey(accountId uint) string {
|
|||||||
return fmt.Sprintf("notification-preference#%d", accountId)
|
return fmt.Sprintf("notification-preference#%d", accountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNotificationPreference(account uint) (models.PreferenceNotification, error) {
|
func GetNotificationPreference(account models.Account) (models.PreferenceNotification, error) {
|
||||||
var notification models.PreferenceNotification
|
var notification models.PreferenceNotification
|
||||||
cacheManager := cache.New[any](localCache.S)
|
cacheManager := cache.New[any](localCache.S)
|
||||||
marshal := marshaler.New(cacheManager)
|
marshal := marshaler.New(cacheManager)
|
||||||
contx := context.Background()
|
contx := context.Background()
|
||||||
|
|
||||||
if val, err := marshal.Get(contx, GetNotificationPreferenceCacheKey(account), new(models.PreferenceNotification)); err == nil {
|
if val, err := marshal.Get(contx, GetNotificationPreferenceCacheKey(account.ID), new(models.PreferenceNotification)); err == nil {
|
||||||
notification = val.(models.PreferenceNotification)
|
notification = val.(models.PreferenceNotification)
|
||||||
} else {
|
} else {
|
||||||
if err := database.C.Where("account_id = ?", account).First(¬ification).Error; err != nil {
|
if err := database.C.Where("account_id = ?", account.ID).First(¬ification).Error; err != nil {
|
||||||
return notification, err
|
return notification, err
|
||||||
}
|
}
|
||||||
CacheNotificationPreference(notification)
|
CacheNotificationPreference(notification)
|
||||||
@ -76,12 +76,12 @@ func CacheNotificationPreference(prefs models.PreferenceNotification) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateNotificationPreference(account uint, config map[string]bool) (models.PreferenceNotification, error) {
|
func UpdateNotificationPreference(account models.Account, config map[string]bool) (models.PreferenceNotification, error) {
|
||||||
var notification models.PreferenceNotification
|
var notification models.PreferenceNotification
|
||||||
var err error
|
var err error
|
||||||
if notification, err = GetNotificationPreference(account); err != nil {
|
if notification, err = GetNotificationPreference(account); err != nil {
|
||||||
notification = models.PreferenceNotification{
|
notification = models.PreferenceNotification{
|
||||||
AccountID: account,
|
AccountID: account.ID,
|
||||||
Config: lo.MapValues(config, func(v bool, k string) any { return v }),
|
Config: lo.MapValues(config, func(v bool, k string) any { return v }),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,20 +18,20 @@ func ListCommunityRealm() ([]models.Realm, error) {
|
|||||||
return realms, nil
|
return realms, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListOwnedRealm(user uint) ([]models.Realm, error) {
|
func ListOwnedRealm(user models.Account) ([]models.Realm, error) {
|
||||||
var realms []models.Realm
|
var realms []models.Realm
|
||||||
if err := database.C.Where(&models.Realm{AccountID: user}).Find(&realms).Error; err != nil {
|
if err := database.C.Where(&models.Realm{AccountID: user.ID}).Find(&realms).Error; err != nil {
|
||||||
return realms, err
|
return realms, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return realms, nil
|
return realms, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListAvailableRealm(user uint) ([]models.Realm, error) {
|
func ListAvailableRealm(user models.Account) ([]models.Realm, error) {
|
||||||
var realms []models.Realm
|
var realms []models.Realm
|
||||||
var members []models.RealmMember
|
var members []models.RealmMember
|
||||||
if err := database.C.Where(&models.RealmMember{
|
if err := database.C.Where(&models.RealmMember{
|
||||||
AccountID: user,
|
AccountID: user.ID,
|
||||||
}).Find(&members).Error; err != nil {
|
}).Find(&members).Error; err != nil {
|
||||||
return realms, err
|
return realms, err
|
||||||
}
|
}
|
||||||
@ -57,9 +57,9 @@ func GetRealmWithAlias(alias string) (models.Realm, error) {
|
|||||||
return realm, nil
|
return realm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRealm(realm models.Realm, user uint) (models.Realm, error) {
|
func NewRealm(realm models.Realm, user models.Account) (models.Realm, error) {
|
||||||
realm.Members = []models.RealmMember{
|
realm.Members = []models.RealmMember{
|
||||||
{AccountID: user, PowerLevel: 100},
|
{AccountID: user.ID, PowerLevel: 100},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := database.C.Save(&realm).Error
|
err := database.C.Save(&realm).Error
|
||||||
@ -90,14 +90,14 @@ func GetRealmMember(userId uint, realmId uint) (models.RealmMember, error) {
|
|||||||
return member, nil
|
return member, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddRealmMember(user uint, affected models.Account, target models.Realm) error {
|
func AddRealmMember(user models.Account, affected models.Account, target models.Realm) error {
|
||||||
if !target.IsPublic && !target.IsCommunity {
|
if !target.IsPublic && !target.IsCommunity {
|
||||||
if member, err := GetRealmMember(user, target.ID); err != nil {
|
if member, err := GetRealmMember(user.ID, target.ID); err != nil {
|
||||||
return fmt.Errorf("only realm member can add people: %v", err)
|
return fmt.Errorf("only realm member can add people: %v", err)
|
||||||
} else if member.PowerLevel < 50 {
|
} else if member.PowerLevel < 50 {
|
||||||
return fmt.Errorf("only realm moderator can add people")
|
return fmt.Errorf("only realm moderator can add people")
|
||||||
}
|
}
|
||||||
rel, err := GetRelationWithTwoNode(affected.ID, user)
|
rel, err := GetRelationWithTwoNode(affected.ID, user.ID)
|
||||||
if err != nil || HasPermNodeWithDefault(
|
if err != nil || HasPermNodeWithDefault(
|
||||||
rel.PermNodes,
|
rel.PermNodes,
|
||||||
"RealmAdd",
|
"RealmAdd",
|
||||||
@ -116,9 +116,9 @@ func AddRealmMember(user uint, affected models.Account, target models.Realm) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveRealmMember(user uint, affected models.Account, target models.Realm) error {
|
func RemoveRealmMember(user models.Account, affected models.Account, target models.Realm) error {
|
||||||
if user != affected.ID {
|
if user.ID != affected.ID {
|
||||||
if member, err := GetRealmMember(user, target.ID); err != nil {
|
if member, err := GetRealmMember(user.ID, target.ID); err != nil {
|
||||||
return fmt.Errorf("only realm member can remove other member: %v", err)
|
return fmt.Errorf("only realm member can remove other member: %v", err)
|
||||||
} else if member.PowerLevel < 50 {
|
} else if member.PowerLevel < 50 {
|
||||||
return fmt.Errorf("only realm moderator can invite people")
|
return fmt.Errorf("only realm moderator can invite people")
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListAllRelationship(user uint) ([]models.AccountRelationship, error) {
|
func ListAllRelationship(user models.Account) ([]models.AccountRelationship, error) {
|
||||||
var relationships []models.AccountRelationship
|
var relationships []models.AccountRelationship
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where("account_id = ?", user).
|
Where("account_id = ?", user.ID).
|
||||||
Preload("Account").
|
Preload("Account").
|
||||||
Preload("Related").
|
Preload("Related").
|
||||||
Find(&relationships).Error; err != nil {
|
Find(&relationships).Error; err != nil {
|
||||||
@ -22,10 +22,10 @@ func ListAllRelationship(user uint) ([]models.AccountRelationship, error) {
|
|||||||
return relationships, nil
|
return relationships, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListRelationshipWithFilter(user uint, status models.RelationshipStatus) ([]models.AccountRelationship, error) {
|
func ListRelationshipWithFilter(user models.Account, status models.RelationshipStatus) ([]models.AccountRelationship, error) {
|
||||||
var relationships []models.AccountRelationship
|
var relationships []models.AccountRelationship
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where("account_id = ? AND status = ?", user, status).
|
Where("account_id = ? AND status = ?", user.ID, status).
|
||||||
Preload("Account").
|
Preload("Account").
|
||||||
Preload("Related").
|
Preload("Related").
|
||||||
Find(&relationships).Error; err != nil {
|
Find(&relationships).Error; err != nil {
|
||||||
|
@ -5,10 +5,10 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListAbuseReport(account uint) ([]models.AbuseReport, error) {
|
func ListAbuseReport(account models.Account) ([]models.AbuseReport, error) {
|
||||||
var reports []models.AbuseReport
|
var reports []models.AbuseReport
|
||||||
err := database.C.
|
err := database.C.
|
||||||
Where("account_id = ?", account).
|
Where("account_id = ?", account.ID).
|
||||||
Find(&reports).Error
|
Find(&reports).Error
|
||||||
return reports, err
|
return reports, err
|
||||||
}
|
}
|
||||||
@ -51,13 +51,13 @@ func UpdateAbuseReportStatus(id uint, status, message string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAbuseReport(resource string, reason string, account uint) (models.AbuseReport, error) {
|
func NewAbuseReport(resource string, reason string, account models.Account) (models.AbuseReport, error) {
|
||||||
var report models.AbuseReport
|
var report models.AbuseReport
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where(
|
Where(
|
||||||
"resource = ? AND account_id = ? AND status IN ?",
|
"resource = ? AND account_id = ? AND status IN ?",
|
||||||
resource,
|
resource,
|
||||||
account,
|
account.ID,
|
||||||
[]string{models.ReportStatusPending, models.ReportStatusReviewing},
|
[]string{models.ReportStatusPending, models.ReportStatusReviewing},
|
||||||
).First(&report).Error; err == nil {
|
).First(&report).Error; err == nil {
|
||||||
return report, fmt.Errorf("you already reported this resource and it still in process")
|
return report, fmt.Errorf("you already reported this resource and it still in process")
|
||||||
@ -66,7 +66,7 @@ func NewAbuseReport(resource string, reason string, account uint) (models.AbuseR
|
|||||||
report = models.AbuseReport{
|
report = models.AbuseReport{
|
||||||
Resource: resource,
|
Resource: resource,
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
AccountID: account,
|
AccountID: account.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := database.C.Create(&report).Error
|
err := database.C.Create(&report).Error
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckDailyCanSign(user uint) error {
|
func CheckDailyCanSign(user models.Account) error {
|
||||||
probe := time.Now().Format("2006-01-02")
|
probe := time.Now().Format("2006-01-02")
|
||||||
|
|
||||||
var record models.SignRecord
|
var record models.SignRecord
|
||||||
if err := database.C.Where("account_id = ? AND created_at::date = ?", user, probe).First(&record).Error; err != nil {
|
if err := database.C.Where("account_id = ? AND created_at::date = ?", user.ID, probe).First(&record).Error; err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -24,22 +24,22 @@ func CheckDailyCanSign(user uint) error {
|
|||||||
return fmt.Errorf("daliy sign record exists")
|
return fmt.Errorf("daliy sign record exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTodayDailySign(user uint) (models.SignRecord, error) {
|
func GetTodayDailySign(user models.Account) (models.SignRecord, error) {
|
||||||
probe := time.Now().Format("2006-01-02")
|
probe := time.Now().Format("2006-01-02")
|
||||||
|
|
||||||
var record models.SignRecord
|
var record models.SignRecord
|
||||||
if err := database.C.Where("account_id = ? AND created_at::date = ?", user, probe).First(&record).Error; err != nil {
|
if err := database.C.Where("account_id = ? AND created_at::date = ?", user.ID, probe).First(&record).Error; err != nil {
|
||||||
return record, fmt.Errorf("unable get daliy sign record: %v", err)
|
return record, fmt.Errorf("unable get daliy sign record: %v", err)
|
||||||
}
|
}
|
||||||
return record, nil
|
return record, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DailySign(user uint) (models.SignRecord, error) {
|
func DailySign(user models.Account) (models.SignRecord, error) {
|
||||||
tier := rand.Intn(5)
|
tier := rand.Intn(5)
|
||||||
record := models.SignRecord{
|
record := models.SignRecord{
|
||||||
ResultTier: tier,
|
ResultTier: tier,
|
||||||
ResultExperience: rand.Intn(int(math.Max(float64(tier), 1)*100)+1-100) + 100,
|
ResultExperience: rand.Intn(int(math.Max(float64(tier), 1)*100)+1-100) + 100,
|
||||||
AccountID: user,
|
AccountID: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := CheckDailyCanSign(user); err != nil {
|
if err := CheckDailyCanSign(user); err != nil {
|
||||||
@ -47,7 +47,7 @@ func DailySign(user uint) (models.SignRecord, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var profile models.AccountProfile
|
var profile models.AccountProfile
|
||||||
if err := database.C.Where("account_id = ?", user).First(&profile).Error; err != nil {
|
if err := database.C.Where("account_id = ?", user.ID).First(&profile).Error; err != nil {
|
||||||
return record, fmt.Errorf("unable get account profile: %v", err)
|
return record, fmt.Errorf("unable get account profile: %v", err)
|
||||||
} else {
|
} else {
|
||||||
profile.Experience += uint64(record.ResultExperience)
|
profile.Experience += uint64(record.ResultExperience)
|
||||||
|
@ -98,27 +98,27 @@ func GetStatusOnline(uid uint) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatus(user uint, status models.Status) (models.Status, error) {
|
func NewStatus(user models.Account, status models.Status) (models.Status, error) {
|
||||||
if err := database.C.Save(&status).Error; err != nil {
|
if err := database.C.Save(&status).Error; err != nil {
|
||||||
return status, err
|
return status, err
|
||||||
} else {
|
} else {
|
||||||
CacheUserStatus(user, status)
|
CacheUserStatus(user.ID, status)
|
||||||
}
|
}
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditStatus(user uint, status models.Status) (models.Status, error) {
|
func EditStatus(user models.Account, status models.Status) (models.Status, error) {
|
||||||
if err := database.C.Save(&status).Error; err != nil {
|
if err := database.C.Save(&status).Error; err != nil {
|
||||||
return status, err
|
return status, err
|
||||||
} else {
|
} else {
|
||||||
CacheUserStatus(user, status)
|
CacheUserStatus(user.ID, status)
|
||||||
}
|
}
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearStatus(user uint) error {
|
func ClearStatus(user models.Account) error {
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where("account_id = ?", user).
|
Where("account_id = ?", user.ID).
|
||||||
Where("clear_at > ?", time.Now()).
|
Where("clear_at > ?", time.Now()).
|
||||||
Updates(models.Status{ClearAt: lo.ToPtr(time.Now())}).Error; err != nil {
|
Updates(models.Status{ClearAt: lo.ToPtr(time.Now())}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
@ -127,7 +127,7 @@ func ClearStatus(user uint) error {
|
|||||||
marshal := marshaler.New(cacheManager)
|
marshal := marshaler.New(cacheManager)
|
||||||
contx := context.Background()
|
contx := context.Background()
|
||||||
|
|
||||||
marshal.Delete(contx, GetStatusCacheKey(user))
|
marshal.Delete(contx, GetStatusCacheKey(user.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -57,7 +57,7 @@ func NewTicket(user models.Account, ip, ua string) (models.AuthTicket, error) {
|
|||||||
} else {
|
} else {
|
||||||
steps = min(steps, int(count))
|
steps = min(steps, int(count))
|
||||||
|
|
||||||
cfg, err := GetAuthPreference(user.ID)
|
cfg, err := GetAuthPreference(user)
|
||||||
if err == nil && cfg.Config.Data().MaximumAuthSteps >= 1 {
|
if err == nil && cfg.Config.Data().MaximumAuthSteps >= 1 {
|
||||||
steps = min(steps, cfg.Config.Data().MaximumAuthSteps)
|
steps = min(steps, cfg.Config.Data().MaximumAuthSteps)
|
||||||
}
|
}
|
||||||
|
12
pkg/main.go
12
pkg/main.go
@ -58,18 +58,6 @@ func main() {
|
|||||||
http.IReader = reader
|
http.IReader = reader
|
||||||
log.Info().Msg("Internal jwt public key loaded.")
|
log.Info().Msg("Internal jwt public key loaded.")
|
||||||
}
|
}
|
||||||
if reader, err := sec.NewJwtReader(viper.GetString("security.public_key")); err != nil {
|
|
||||||
log.Error().Err(err).Msg("An error occurred when reading public key for jwt. Signing token may not work.")
|
|
||||||
} else {
|
|
||||||
services.EReader = reader
|
|
||||||
log.Info().Msg("Jwt public key loaded.")
|
|
||||||
}
|
|
||||||
if writer, err := sec.NewJwtWriter(viper.GetString("security.private_key")); err != nil {
|
|
||||||
log.Error().Err(err).Msg("An error occurred when reading private key for jwt. Signing token may not work.")
|
|
||||||
} else {
|
|
||||||
services.EWriter = writer
|
|
||||||
log.Info().Msg("Jwt private key loaded.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to database
|
// Connect to database
|
||||||
if err := database.NewGorm(); err != nil {
|
if err := database.NewGorm(); err != nil {
|
||||||
|
@ -20,8 +20,9 @@ database = false
|
|||||||
print_routes = false
|
print_routes = false
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
access_token_duration = 3000
|
issuer = "https://solsynth.dev"
|
||||||
|
cookie_domain = "localhost"
|
||||||
|
cookie_samesite = "Lax"
|
||||||
|
access_token_duration = 300
|
||||||
refresh_token_duration = 2592000
|
refresh_token_duration = 2592000
|
||||||
public_key = "keys/public_key.pem"
|
|
||||||
private_key = "keys/private_key.pem"
|
|
||||||
internal_public_key = "keys/internal_public_key.pem"
|
internal_public_key = "keys/internal_public_key.pem"
|
||||||
|
Loading…
Reference in New Issue
Block a user