users

package
v0.0.0-...-905f740 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2022 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalFamily

func MarshalFamily(f *Family) ([]byte, error)

MarshalFamily converts a family struct to a byte slice

func MarshalGroup

func MarshalGroup(g *Group) ([]byte, error)

MarshalGroup converts a group struct to a byte slice

func MarshalUser

func MarshalUser(m *Member) ([]byte, error)

MarshalUser takes a pointer to a Member struct and converts it into a slice of bytes for database storing It returns a non-nil error if there is an error, naturally

func Stringify

func Stringify(b []byte) string

Types

type Family

type Family struct {
	FamilyName string            `json:"name" html:"name"`
	FamilyID   []byte            `json:"id" html:"id"`
	Groups     []string          `json:"groups" html:"groups"`
	Members    []string          `json:"members" html:"members"`
	Elders     []string          `json:"elders" html:"elders"` //they get special priveleges
	Lists      map[string]string `json:"lists" html:"lists"`
	// contains filtered or unexported fields
}

Family will be like a user manager for a group of related people Doesn't have to be an actual family, just a group getting presents for each other I also may change family to a tree structure at some point. I know, womp womp

func NewFamily

func NewFamily(s string, id []byte, m *Member) *Family

NewFamily does what it says on the tin Need a way to make this work with the database

func UnmarshalFamily

func UnmarshalFamily(b []byte) (*Family, error)

UnmarshalFamily reforms a family from binary

func (*Family) AddElder

func (f *Family) AddElder(id string) error

AddElder takes a family member and promotes them to elder. Note that the user MUST already be a member of the family

func (*Family) AddMember

func (f *Family) AddMember(m *Member) error

AddMember takes a userID as an argument and adds them to the family It returns a non-nil error if they are already in the family

func (*Family) IsInFamily

func (f *Family) IsInFamily(id string) bool

IsInFamily takes a userID argument, and returns true if that user is a member of the family, and false if they are not Might be worth converting to hashmap just to avoid this

func (*Family) NewGroup

func (f *Family) NewGroup(s, id string, m ...*Member) *Group

NewGroup takes a string argument and

func (*Family) RemoveElder

func (f *Family) RemoveElder(id string) error

RemoveElder demotes an elder to a regular old family member

func (*Family) RemoveList

func (f *Family) RemoveList(m *Member, id string) error

RemoveList takes a family member and listID as input, and removes the list from both the user and the family. It returns a non-nill error if there is an error

type Group

type Group struct {
	GroupName string   `json:"name" html:"name"`
	GroupID   string   `json:"id" html:"id"`
	Family    string   `json:"family" html:"family"`
	Members   []string `json:"members" html:"members"`
	Lists     []string `json:"lists" html:"lists"` //just list IDs, same as with a member
	// contains filtered or unexported fields
}

Group is an optional subgroup within families. Someday, I may even give groups to groups

func UnmarshalGroup

func UnmarshalGroup(b []byte) (*Group, error)

UnmarshalGroup - Pretty straightforward here

func (*Group) AddMember

func (g *Group) AddMember(id string) error

AddMember takes a string argument for a user's login and adds that member to the group

func (*Group) IsInGroup

func (g *Group) IsInGroup(id string) bool

IsInGroup takes a userID argument, and returns a bool

func (*Group) RemoveMember

func (g *Group) RemoveMember(id string) error

RemoveMember removes a member from a group

type Member

type Member struct {
	Login        string            `json:"login" html:"login"`                 //is this unsecure? Should I be storing the hash instead? Should I be storing at all?
	Password     []byte            `json:"password" html:"password"`           //actual password won't be stored anywhere, just the hash
	OldPasswords [][]byte          `json:"old_passwords" html:"old_passwords"` //should probably make this a tree at some point
	Username     string            `json:"username" html:"username"`
	UserID       []byte            `json:"id" html:"id"`
	Family       []string          `json:"family" html:"family"`
	FirstName    string            `json:"first_name" html:"first_name"`
	LastName     string            `json:"last_name" html:"last_name"`
	Groups       []string          `json:"groups" html:"groups"`
	GroupMap     map[string]string `json:"group_map" html:"group_map"`
	ElderOf      []string          `json:"elder_of" html:"elder_of"` //need to tokenize this somehow
	Lists        []string          `json:"lists" html:"lists"`       //these will be the values for the list ID database key. Maybe change to map, with family name as key?
	Messages     []message         `json:"messages" html:"messages"`
	// contains filtered or unexported fields
}

Member is a member of a family. May also be a member of a group or several groups

func NewMember

func NewMember(l, u, fn, ln, family string, pw, id []byte) *Member

NewMember takes several arguments and returns a pointer to a new member

func UnmarshalUser

func UnmarshalUser(b []byte) (*Member, error)

UnmarshalUser takes a slice of bytes and returns a user

func (*Member) ChangePassword

func (m *Member) ChangePassword(b []byte) error

ChangePassword changes a user's password. Note that security checks should already be handled at this point

func (*Member) JoinGroup

func (m *Member) JoinGroup(id, family string) error

JoinGroup adds a group to a member's groups

func (*Member) NewList

func (m *Member) NewList(id string, f *Family) (*list.List, error)

NewList creates a new list for the member and returns the list

func (*Member) RemoveList

func (m *Member) RemoveList(id string) error

RemoveList takes a listID as input and removes it. It returns a non-nil error if the list is not found

type Messages

type Messages struct {
	Owner    string    `json:"owner" html:"owner"`       //this will be who is viewing these messages
	Messages []message `json:"messages" html:"messages"` //guess this works for now
}

messages is a stack of messages. Each individual user will have their own message stack. This way, messages will be sorted once on sending, and we won't have to do any silly nonsense like

func (*Messages) DeleteMessage

func (me *Messages) DeleteMessage(m message) error

DeleteMessage deletes a message. It returns a non-nil error if no such message is found

func (*Messages) NewMessage

func (me *Messages) NewMessage(m message)

type TokenMap

type TokenMap struct {
	Tokens map[string]string
}

tokenMap holds references to all outsanding tokens, and which family they match to

func NewTokenMap

func NewTokenMap() *TokenMap

func (*TokenMap) Del

func (t *TokenMap) Del(k string)

func (*TokenMap) GenerateToken

func (t *TokenMap) GenerateToken() string

func (*TokenMap) Get

func (t *TokenMap) Get(k string) (string, error)

func (*TokenMap) MarshalBinary

func (t *TokenMap) MarshalBinary() ([]byte, error)

func (*TokenMap) Put

func (t *TokenMap) Put(k, v string)

func (*TokenMap) UnmarshalBinary

func (t *TokenMap) UnmarshalBinary(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL