Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
authentity "spark-server/internal/module/auth/entity"
|
|
userentity "spark-server/internal/module/user/entity"
|
|
"spark-server/internal/pkg/errs"
|
|
)
|
|
|
|
// Static accepts one opaque token. Tests and local bring-up only; production uses JWT.
|
|
type Static struct {
|
|
Token string
|
|
UserID int64
|
|
DeviceID uint64
|
|
}
|
|
|
|
func (s Static) Authenticate(_ context.Context, token string) (*authentity.Principal, error) {
|
|
if s.Token == "" || token != s.Token {
|
|
return nil, errs.ErrUnauthorized
|
|
}
|
|
return &authentity.Principal{UserID: s.UserID, DeviceID: s.DeviceID}, nil
|
|
}
|
|
|
|
// StaticUser is a single email/OTP pair for tests that do not need the user module.
|
|
type StaticUser struct {
|
|
Email string
|
|
Code string
|
|
UserID int64
|
|
SparkID string
|
|
}
|
|
|
|
func (s StaticUser) AuthenticateEmail(_ context.Context, email, verifyCode string, _ *userentity.LoginDevice) (*userentity.User, error) {
|
|
if s.Email == "" || userentity.NormalizeEmail(email) != userentity.NormalizeEmail(s.Email) {
|
|
return nil, errs.ErrUnauthorized
|
|
}
|
|
if s.Code != "" && verifyCode != s.Code {
|
|
return nil, errs.ErrUnauthorized
|
|
}
|
|
sparkID := s.SparkID
|
|
if sparkID == "" {
|
|
sparkID = "static"
|
|
}
|
|
return &userentity.User{ID: s.UserID, SparkID: sparkID, Status: userentity.StatusActive}, nil
|
|
}
|
|
|
|
func (s StaticUser) SendEmailCode(context.Context, string) error { return nil }
|