2020-06-25 01:20:58 +02:00
|
|
|
package session
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
2020-06-25 01:20:58 +02:00
|
|
|
|
|
|
|
type Saved struct {
|
2020-06-25 14:54:04 +02:00
|
|
|
User string `json:"user"`
|
2020-06-25 01:20:58 +02:00
|
|
|
Tokens []string `json:"tokens"`
|
|
|
|
Expiration int64 `json:"expiration"`
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
type UIDs []string
|
|
|
|
|
|
|
|
func (list UIDs) String() string {
|
|
|
|
return strings.Join(list, ",")
|
|
|
|
}
|
|
|
|
|
2020-06-25 01:20:58 +02:00
|
|
|
type Data struct {
|
2020-10-03 13:50:30 +02:00
|
|
|
User entity.User `json:"user"` // Session user, guest or anonymous person.
|
|
|
|
Tokens []string `json:"tokens"` // Slice of secret share tokens.
|
|
|
|
Shares UIDs `json:"shares"` // Slice of shared entity UIDs.
|
2020-06-25 14:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s Data) Saved() Saved {
|
2020-10-03 13:50:30 +02:00
|
|
|
return Saved{User: s.User.UserUID, Tokens: s.Tokens}
|
2020-06-25 14:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s Data) Invalid() bool {
|
2020-10-03 13:50:30 +02:00
|
|
|
return s.User.ID == 0 || s.User.UserUID == "" || (s.Guest() && s.NoShares())
|
2020-06-25 01:20:58 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
func (s Data) Valid() bool {
|
|
|
|
return !s.Invalid()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Data) Guest() bool {
|
|
|
|
return s.User.Guest()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Data) NoShares() bool {
|
|
|
|
return len(s.Shares) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Data) HasShare(uid string) bool {
|
|
|
|
for _, share := range s.Shares {
|
|
|
|
if share == uid {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-06-25 01:20:58 +02:00
|
|
|
}
|