118 lines
2.3 KiB
Go
118 lines
2.3 KiB
Go
package entities
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"net/mail"
|
|
"strings"
|
|
)
|
|
|
|
type KeySelection []int
|
|
|
|
type CustomerId uuid.UUID
|
|
|
|
func (c *CustomerId) String() string {
|
|
id := uuid.UUID(*c)
|
|
return id.String()
|
|
}
|
|
|
|
type SessionId uuid.UUID
|
|
type UserId uuid.UUID
|
|
|
|
func (u *UserId) String() string {
|
|
id := uuid.UUID(*u)
|
|
return id.String()
|
|
}
|
|
|
|
func UserIdFromString(userId string) UserId {
|
|
id, err := uuid.Parse(userId)
|
|
if err != nil {
|
|
fmt.Errorf("unable to parse user id %+v", err)
|
|
}
|
|
return UserId(id)
|
|
}
|
|
|
|
func (s *SessionId) String() string {
|
|
id := uuid.UUID(*s)
|
|
return id.String()
|
|
}
|
|
|
|
type UserEmail string
|
|
|
|
func ParseEmail(email string) (UserEmail, error) {
|
|
_, err := mail.ParseAddress(email)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return UserEmail(strings.ToLower(email)), err
|
|
|
|
}
|
|
|
|
type IdxInterface []int
|
|
type SvgIdInterface []int
|
|
|
|
func SessionIdFromString(sessionId string) (SessionId, error) {
|
|
id, err := uuid.Parse(sessionId)
|
|
if err != nil {
|
|
return SessionId{}, err
|
|
}
|
|
|
|
return SessionId(id), nil
|
|
}
|
|
|
|
type EncipheredNKode struct {
|
|
Code string
|
|
Mask string
|
|
}
|
|
|
|
type RGBColor struct {
|
|
Red int `json:"red"`
|
|
Green int `json:"green"`
|
|
Blue int `json:"blue"`
|
|
}
|
|
|
|
var SetColors = []RGBColor{
|
|
{0, 0, 0}, // Black
|
|
{255, 0, 0}, // Red
|
|
{0, 128, 0}, // Dark Green
|
|
{0, 0, 255}, // Blue
|
|
{244, 200, 60}, // Yellow
|
|
{255, 0, 255}, // Magenta
|
|
{0, 200, 200}, // Cyan
|
|
{127, 0, 127}, // Purple
|
|
{232, 92, 13}, // Orange
|
|
{0, 127, 127}, // Teal
|
|
{127, 127, 0}, // Olive
|
|
{127, 0, 0}, // Dark Red
|
|
{128, 128, 128}, // Gray
|
|
{228, 102, 102}, // Dark Purple
|
|
{185, 17, 240}, // Salmon
|
|
{16, 200, 100}, // Green
|
|
}
|
|
|
|
type SignupResetInterface struct {
|
|
SessionId string `json:"session_id"`
|
|
UserIdxInterface IdxInterface `json:"user_interface"`
|
|
SvgInterface []string `json:"svg_interface"`
|
|
Colors []RGBColor `json:"colors"`
|
|
}
|
|
|
|
type LoginInterface struct {
|
|
UserIdxInterface IdxInterface `json:"user_interface"`
|
|
SvgInterface []string `json:"svg_interface"`
|
|
AttrsPerKey int `json:"attrs_per_key"`
|
|
NumbOfKeys int `json:"numb_of_keys"`
|
|
Colors []RGBColor `json:"colors"`
|
|
}
|
|
|
|
type UserPermission int
|
|
|
|
const (
|
|
Default UserPermission = iota
|
|
Admin
|
|
)
|
|
|
|
func (p UserPermission) String() string {
|
|
return [...]string{"Default", "Admin"}[p]
|
|
}
|