users

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package users provides core business logic providing API over credentials store and PM API.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrWrongMailboxPassword is returned when login password is OK but
	// not the mailbox one.
	ErrWrongMailboxPassword = errors.New("wrong mailbox password")

	// ErrUserAlreadyConnected is returned when authentication was OK but
	// there is already active account for this user.
	ErrUserAlreadyConnected = errors.New("user is already connected")
)
View Source
var ErrLoggedOutUser = errors.New("account is logged out, use the app to login again")

ErrLoggedOutUser is sent to IMAP and SMTP if user exists, password is OK but user is logged out from the app.

Functions

func DecodeLogin added in v0.3.0

func DecodeLogin(login string) (string, string)

Extract the login and key slot from the login information

Types

type CredentialsStorer

type CredentialsStorer interface {
	List() (userIDs []string, err error)
	Add(userID, userName, uid, ref string, mailboxPassword []byte, emails []string) (*credentials.Credentials, []byte, error)
	Get(userID string) (*credentials.Credentials, error)
	UpdateEmails(userID string, emails []string) (*credentials.Credentials, error)
	UpdatePassword(userID string, password []byte) (*credentials.Credentials, error)
	UpdateToken(userID, uid, ref string) (*credentials.Credentials, error)
	ListKeySlots(userID string) ([]string, error)
	RemoveKeySlot(userID, slot string) error
	AddKeySlot(userID, slot, mainKey string) (string, error)
	Logout(userID string) (*credentials.Credentials, error)
	Delete(userID string) error
}

type StoreMaker

type StoreMaker interface {
	New(user store.BridgeUser, connected bool) (*store.Store, error)
	Remove(userID string) error
}

type User

type User struct {
	// contains filtered or unexported fields
}

User is a struct on top of API client and credentials store.

func (*User) AddKeySlot added in v0.3.0

func (u *User) AddKeySlot(slot, mainKey string) (string, error)

func (*User) BringOnline added in v0.3.0

func (u *User) BringOnline(slot, password string) error

func (*User) CheckCredentials added in v0.3.0

func (u *User) CheckCredentials(slot, password string) error

func (*User) CloseAllConnections

func (u *User) CloseAllConnections()

CloseAllConnections calls CloseConnection for all users addresses.

func (*User) CloseConnection

func (u *User) CloseConnection(address string)

CloseConnection emits closeConnection event on `address` which should close all active connection.

func (*User) GetAddressID

func (u *User) GetAddressID(address string) (id string, err error)

GetAddressID returns the API ID of the given address.

func (*User) GetAddresses

func (u *User) GetAddresses() []string

GetAddresses returns list of all addresses.

func (*User) GetClient

func (u *User) GetClient() pmapi.Client

func (*User) GetPrimaryAddress

func (u *User) GetPrimaryAddress() string

GetPrimaryAddress returns the user's original address (which is not necessarily the same as the primary address, because a primary address might be an alias and be in position one).

func (*User) GetStore

func (u *User) GetStore() *store.Store

func (*User) GetStoreAddresses

func (u *User) GetStoreAddresses() []string

GetStoreAddresses returns all addresses used by the store (so in combined mode, that's just the original address, but in split mode, that's all active addresses).

func (*User) ID

func (u *User) ID() string

ID returns the user's userID.

func (*User) IsConnected

func (u *User) IsConnected() bool

IsConnected returns whether user is logged in.

func (*User) ListKeySlots added in v0.3.0

func (u *User) ListKeySlots() ([]string, error)

func (*User) Logout

func (u *User) Logout() error

Logout logs out the user from pmapi, the credentials store, the mail store, and tries to remove as much sensitive data as possible.

func (*User) RemoveKeySlot added in v0.3.0

func (u *User) RemoveKeySlot(slot string) error

func (*User) TotalBytes

func (u *User) TotalBytes() int64

TotalBytes returns number of bytes available on server.

func (*User) UnlockCredentials added in v0.3.0

func (u *User) UnlockCredentials(slot, password string) error

func (*User) UpdateSpace

func (u *User) UpdateSpace(apiUser *pmapi.User)

UpdateSpace will update TotalBytes and UsedBytes values from API user. If pointer is nill it will get fresh user from API. API user can come from update event which means it doesn't contain all data. Therefore only positive values will be updated.

func (*User) UpdateUser

func (u *User) UpdateUser(ctx context.Context) error

UpdateUser updates user details from API and saves to the credentials.

func (*User) UsedBytes

func (u *User) UsedBytes() int64

UsedBytes returns number of bytes used on server.

func (*User) Username

func (u *User) Username() string

Username returns the user's username as found in the user's credentials.

type Users

type Users struct {
	// contains filtered or unexported fields
}

Users is a struct handling users.

func New

func New(
	eventListener listener.Listener,
	clientManager pmapi.Manager,
	credStorer CredentialsStorer,
	storeFactory StoreMaker,
) *Users

func (*Users) ClearData

func (u *Users) ClearData() error

ClearData closes all connections (to release db files and so on) and clears all data.

func (*Users) ClearUsers

func (u *Users) ClearUsers() error

ClearUsers deletes all users.

func (*Users) DeleteUser

func (u *Users) DeleteUser(userID string, clearStore bool) error

DeleteUser deletes user completely; it logs user out from the API, stops any active connection, deletes from credentials store and removes from the Bridge struct.

func (*Users) DisableCache

func (u *Users) DisableCache() error

func (*Users) EnableCache

func (u *Users) EnableCache() error

func (*Users) FinishLogin

func (u *Users) FinishLogin(client pmapi.Client, auth *pmapi.Auth, password []byte, mainKey string) (*User, string, error)

FinishLogin finishes the login procedure and adds the user into the credentials store. The main key is only required if we're updating an existing user and only returned if we're creating a new one

func (*Users) GetUser

func (u *Users) GetUser(query string) (*User, error)

GetUser returns a user by `query` which is compared to users' ID, username or any attached e-mail address.

func (*Users) GetUsers

func (u *Users) GetUsers() []*User

GetUsers returns all added users into keychain (even logged out users).

func (*Users) Login

func (u *Users) Login(username string, password []byte) (authClient pmapi.Client, auth *pmapi.Auth, err error)

Login authenticates a user by username/password, returning an authorised client and an auth object. The authorisation scope may not yet be full if the user has 2FA enabled.

func (*Users) MigrateCache

func (u *Users) MigrateCache(srcPath, dstPath string) error

MigrateCache moves the message cache folder from folder srcPath to folder dstPath. srcPath must point to an existing folder. dstPath must be an empty folder or not exist.

Directories

Path Synopsis
Package credentials implements our struct stored in keychain.
Package credentials implements our struct stored in keychain.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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