58f11302fe
Track authenticated sessions per device (parsing user-agent for desktop vs mobile via mileusna/useragent), enforce configurable concurrent device limits (Auth.DeviceLimits), and surface device status and "remove other devices" management in the account dialog. Adds device/session context to the auth module stores and exposes limits through the API. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.10.1
|
|
|
|
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"img_infinite_canvas/internal/domain/design"
|
|
"img_infinite_canvas/internal/svc"
|
|
"img_infinite_canvas/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListAccountDevicesLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewListAccountDevicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAccountDevicesLogic {
|
|
return &ListAccountDevicesLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ListAccountDevicesLogic) ListAccountDevices() (resp *types.AccountDeviceListResponse, err error) {
|
|
devices, err := l.svcCtx.AuthService.ListDevices(l.ctx, design.UserIDFromContext(l.ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
limits := l.svcCtx.AuthService.DeviceLimits()
|
|
return &types.AccountDeviceListResponse{
|
|
Devices: toAPIAccountDevices(devices),
|
|
Limits: types.AccountDeviceLimits{
|
|
Desktop: limits.Desktop,
|
|
Mobile: limits.Mobile,
|
|
},
|
|
}, nil
|
|
}
|