service

package
v0.0.0-...-ca83848 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRegistrationDisabled    = &Error{"Registration disabled", 403, "", ""}
	ErrInvalidEmail            = &Error{"Invalid email", 400, "", ""}
	ErrInvalidUsername         = &Error{"Invalid username", 400, "", ""}
	ErrInvalidCollectionName   = &Error{"Invalid collection name", 400, "", ""}
	ErrPasswordNotMatch        = &Error{"Password not match", 403, "", ""}
	ErrPasswordTooShort        = &Error{"Password too short", 400, "", ""}
	ErrPasswordChangeDisabled  = &Error{"Password change disabled for this account", 403, "", ""}
	ErrUserNotExist            = &Error{"User not exist", 404, "", ""}
	ErrUserNameExist           = &Error{"User Name exist", 403, "", ""}
	ErrUserEmailExist          = &Error{"User Email exist", 403, "", ""}
	ErrUserDeletionDisabled    = &Error{"User deletion disabled for this account", 403, "", ""}
	ErrUserIsTheLastAdmin      = &Error{"User is the last admin", 403, "", ""}
	ErrAccessDenied            = &Error{"Access denied", 403, "", ""}
	ErrInputDecodeFailed       = &Error{"Input decode failed", 400, "", ""}
	ErrAuthtokenNotExist       = &Error{"Authtoken not exist", 403, "", ""}
	ErrAuthtokenExpired        = &Error{"Authtoken expired", 403, "", ""}
	ErrDB                      = &Error{"DB error", 500, "", ""}
	ErrBotsDontMatter          = &Error{"Bots don't matter", 403, "", ""}
	ErrCollectionNotExist      = &Error{"Collection not exist", 404, "", ""}
	ErrCollectionLimitExceeded = &Error{"Collection limit exceeded", 403, "", ""}
	ErrCollectionNameExist     = &Error{"Collection name exists", 403, "", ""}
	ErrSessionNotExist         = &Error{"Session not exist", 404, "", ""}
	ErrTeammateExist           = &Error{"Teammate exist", 403, "", ""}
	ErrBackupNotExist          = &Error{"Backup not exist", 404, "", ""}
	ErrEmailSending            = &Error{"Can't send email", 500, "", ""}
	ErrEmailExpired            = &Error{"Email expired", 403, "", ""}
)

The possible errors

Functions

func AddTeammate

func AddTeammate(collection *Collection, input TeammateT) error

AddTeammate adds a teammate to the collection

func ChangePassword

func ChangePassword(user *User, currentPassword string, password string) error

ChangePassword change a user's password when the password match

func ChangePasswordForce

func ChangePasswordForce(user *User, password string) error

ChangePasswordForce change a user's password

func ChangePasswordWithResetKey

func ChangePasswordWithResetKey(user *User, resetKey, password string) error

ChangePasswordWithResetKey changes the user's password with a resetKey

func CheckAuthToken

func CheckAuthToken(tokenID string) (uint64, error)

CheckAuthToken check whether the AuthToken is valid

func CollectionCreateAccessCheck

func CollectionCreateAccessCheck(user *User, loggedInUser *User) error

CollectionCreateAccessCheck checks the create access

func CollectionReadAccessCheck

func CollectionReadAccessCheck(collection *Collection, user *User) error

CollectionReadAccessCheck checks the read access

func CollectionWriteAccessCheck

func CollectionWriteAccessCheck(collection *Collection, user *User) error

CollectionWriteAccessCheck checks the write access

func CreatePageview

func CreatePageview(userAgent string, input CreatePageviewInputT) error

CreatePageview creates a pageview

func CreateSession

func CreateSession(userAgent string, remoteAddr string, input CreateSessionInputT) (string, error)

CreateSession creates a session

func DeleteAuthToken

func DeleteAuthToken(tokenID string) error

DeleteAuthToken deletes an AuthToken

func DeleteCollection

func DeleteCollection(collection *Collection) error

DeleteCollection deletes the collection

func DeleteCollectionShard

func DeleteCollectionShard(collection *Collection, shardID string) error

DeleteCollectionShard deletes a shard

func DeleteUser

func DeleteUser(user *User, password string) error

DeleteUser deletes a user when the password patch

func DeleteUserByAdmin

func DeleteUserByAdmin(name string) error

DeleteUserByAdmin deletes a user by Admin

func GetCollectionData

func GetCollectionData(collection *Collection, input *CollectionDataInputT) (*db.CollectionDataT, error)

GetCollectionData returns the collection data

func GetCollectionShards

func GetCollectionShards(collection *Collection) ([]db.ShardDataT, error)

GetCollectionShards return the collection shards

func GetCollectionStatData

func GetCollectionStatData(collection *Collection, input *CollectionDataInputT) (*db.CollectionStatDataT, error)

GetCollectionStatData return the collection stats

func GetPageviews

func GetPageviews(collection *Collection, sessionKey string) ([]*db.PageviewDataT, error)

GetPageviews return the pageviews for the collection

func GetSessions

func GetSessions(collection *Collection, input *CollectionDataInputT) ([]*db.SessionDataT, error)

GetSessions return the collection's sessions

func RemoveTeammate

func RemoveTeammate(collection *Collection, email string) error

RemoveTeammate removes the teammate from the collection

func RunBackup

func RunBackup(backupID string) error

RunBackup runs the backup

func SeedCollection

func SeedCollection(from time.Time, to time.Time, collectionID string, n int) error

SeedCollection seed a collection with n sessions

func SendResetPassword

func SendResetPassword(user *User) error

SendResetPassword sends an email to change user's password

func SendVerifyEmail

func SendVerifyEmail(user *User) error

SendVerifyEmail sends an email verify email to a user

func UpdateCollection

func UpdateCollection(collection *Collection, name string) error

UpdateCollection updates the collection's name

func UpdateSession

func UpdateSession(userAgent string, CollectionID string, sessionKey string) error

UpdateSession updates the session.End field

func UpdateUser

func UpdateUser(name string, input *UserUpdateT) error

UpdateUser updates a user with UserUpdateT struct

func VerifyEmail

func VerifyEmail(user *User, verificationKey string) error

VerifyEmail verifies the user email address with the verificationKey

Types

type AuthToken

type AuthToken = db.AuthToken

AuthToken is the db's authToken struct

type Backup

type Backup struct {
	ID  string `json:"id"`
	Dir string `json:"dir"`
}

Backup stores the backup's properties

func GetBackups

func GetBackups() []Backup

GetBackups returns the backup configuration

type Collection

type Collection = db.Collection

Collection is the db's collection struct

func CreateCollection

func CreateCollection(ownerID uint64, name string) (*Collection, error)

CreateCollection creates a collection

func CreateCollectionByID

func CreateCollectionByID(id string, name string, username string) (*Collection, error)

CreateCollectionByID creates a collection with a fixed ID

func GetCollection

func GetCollection(id string) (*Collection, error)

GetCollection fetch a collection by ID

func GetCollectionByName

func GetCollectionByName(user *db.User, name string) (*Collection, error)

GetCollectionByName fetch a collection by name

type CollectionDataInputT

type CollectionDataInputT = db.CollectionDataInputT

CollectionDataInputT is the db's collectionDataInputT struct

type CollectionInfoT

type CollectionInfoT struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	OwnerName     string `json:"owner_name"`
	Created       int64  `json:"created"`
	TeammateCount int    `json:"teammate_count"`
}

CollectionInfoT is struct for clients, stores the user information

func GetCollections

func GetCollections() ([]CollectionInfoT, error)

GetCollections returns all collection

type CollectionSummaryOptions

type CollectionSummaryOptions = db.CollectionSummaryOptions

CollectionSummaryOptions contains options for the db.GetCollectionSummary function

type CollectionSummaryT

type CollectionSummaryT struct {
	ID   string `json:"id"`
	User string `json:"user"`
	Name string `json:"name"`
	db.CollectionSummary
}

CollectionSummaryT the struct for the Collection's summary

func GetCollectionSummariesByUserID

func GetCollectionSummariesByUserID(ID uint64, readerID uint64, options CollectionSummaryOptions) ([]CollectionSummaryT, error)

GetCollectionSummariesByUserID returns the collection summaries for the user

type CreatePageviewInputT

type CreatePageviewInputT struct {
	CollectionID string
	SessionKey   string
	Path         string
}

CreatePageviewInputT is the input for the CreatePageView

type CreateSessionInputT

type CreateSessionInputT struct {
	CollectionID     string
	Hostname         string
	BrowserLanguage  string
	ScreenResolution string
	WindowResolution string
	DeviceType       string
	Referrer         string
}

CreateSessionInputT is the struct for creating a session

type CreateUserT

type CreateUserT struct {
	Email    string `json:"email"`
	Name     string `json:"name"`
	Password string `json:"password"`
}

CreateUserT is a struct for the clients to creating a user

type Error

type Error struct {
	Message    string
	Code       int
	Thing      string
	Additional string
}

Error is the Extended error struct

func (*Error) Error

func (e *Error) Error() string

func (*Error) HTTPMessage

func (e *Error) HTTPMessage() string

HTTPMessage returns the default HTTP error message

func (*Error) T

func (e *Error) T(thing string) *Error

T sets the thing which causes the error

func (*Error) Wrap

func (e *Error) Wrap(v ...interface{}) *Error

Wrap add more information to the error

type TeammateT

type TeammateT struct {
	Email string `json:"email"`
}

TeammateT contains the teammates information for the client

func GetCollectionTeammates

func GetCollectionTeammates(collection *Collection) ([]TeammateT, error)

GetCollectionTeammates returns the teammates emails

type User

type User = db.User

User is the the database user struct

func CreateAuthToken

func CreateAuthToken(nameOrEmail string, password string) (string, *User, error)

CreateAuthToken creates an AuthToken

func CreateUser

func CreateUser(input *CreateUserT) (*User, error)

CreateUser can create an user

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail fetch an user by the user's email

func GetUserByID

func GetUserByID(ID uint64) (*User, error)

GetUserByID fetch an user by the user's email

func GetUserByName

func GetUserByName(name string) (*User, error)

GetUserByName fetch an user by the user's name

func RegisterUser

func RegisterUser(input *CreateUserT) (*User, error)

RegisterUser register an user by the user

type UserInfoT

type UserInfoT struct {
	ID                  uint64 `json:"id"`
	Email               string `json:"email"`
	Name                string `json:"name"`
	Created             int64  `json:"created"`
	IsAdmin             bool   `json:"is_admin"`
	DisablePwChange     bool   `json:"disable_pw_change"`
	LimitCollections    bool   `json:"limit_collections"`
	CollectionLimit     uint32 `json:"collection_limit"`
	DisableUserDeletion bool   `json:"disable_user_deletion"`
	EmailVerified       bool   `json:"email_verified"`
	CollectionCount     int    `json:"collection_count"`
}

UserInfoT is struct for clients, stores the user information

func GetUserInfo

func GetUserInfo(name string) (*UserInfoT, error)

GetUserInfo fetch an user by the user's email

func GetUsers

func GetUsers() ([]UserInfoT, error)

GetUsers returns all user

type UserUpdateT

type UserUpdateT struct {
	Name                string `json:"name"`
	Email               string `json:"email"`
	Password            string `json:"password"`
	IsAdmin             bool   `json:"is_admin"`
	DisablePwChange     bool   `json:"disable_pw_change"`
	LimitCollections    bool   `json:"limit_collections"`
	CollectionLimit     uint32 `json:"collection_limit"`
	DisableUserDeletion bool   `json:"disable_user_deletion"`
	EmailVerified       bool   `json:"email_verified"`
}

UserUpdateT is the struct for updating a user

Jump to

Keyboard shortcuts

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