Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
42
cloud/maplepress-backend/internal/domain/session.go
Normal file
42
cloud/maplepress-backend/internal/domain/session.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Session represents a user's authentication session
|
||||
type Session struct {
|
||||
ID string `json:"id"` // Session UUID
|
||||
UserID uint64 `json:"user_id"` // User's ID
|
||||
UserUUID uuid.UUID `json:"user_uuid"` // User's UUID
|
||||
UserEmail string `json:"user_email"` // User's email
|
||||
UserName string `json:"user_name"` // User's full name
|
||||
UserRole string `json:"user_role"` // User's role (admin, user, etc.)
|
||||
TenantID uuid.UUID `json:"tenant_id"` // Tenant ID for multi-tenancy
|
||||
CreatedAt time.Time `json:"created_at"` // When the session was created
|
||||
ExpiresAt time.Time `json:"expires_at"` // When the session expires
|
||||
}
|
||||
|
||||
// NewSession creates a new session
|
||||
func NewSession(userID uint64, userUUID uuid.UUID, userEmail, userName, userRole string, tenantID uuid.UUID, duration time.Duration) *Session {
|
||||
now := time.Now()
|
||||
return &Session{
|
||||
ID: gocql.TimeUUID().String(),
|
||||
UserID: userID,
|
||||
UserUUID: userUUID,
|
||||
UserEmail: userEmail,
|
||||
UserName: userName,
|
||||
UserRole: userRole,
|
||||
TenantID: tenantID,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(duration),
|
||||
}
|
||||
}
|
||||
|
||||
// IsExpired checks if the session has expired
|
||||
func (s *Session) IsExpired() bool {
|
||||
return time.Now().After(s.ExpiresAt)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue