usersessions

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

The package manages user login sessions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Types

type ActiveSessions

type ActiveSessions struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ActiveSessions stores the list of all the active login sessions associated with a particular user

type ErrorsList

type ErrorsList map[string][]string

type LoginDetails

type LoginDetails struct {
	Un       string
	Pwd      string
	ConnType string
}

type LoginSession

type LoginSession struct {
	LnSessId int
	Token    string
	UserId   int
}

LoginSession stores the details of a login session

type UserModel

type UserModel struct {
	Id             int
	Un             string
	Email          string
	HashedPassword []byte
	Created        time.Time
}

type UserSessions

type UserSessions struct {
	Errors *UserSessionsErrors
	// contains filtered or unexported fields
}

UserSessions serves the user login session requests from the outside modules

func GetUserSessionsInstance

func GetUserSessionsInstance() *UserSessions

func (*UserSessions) GetUserId

func (us *UserSessions) GetUserId(un string) (int, error)

getUserId() returns the id of a user

func (*UserSessions) LogIn

func (us *UserSessions) LogIn(req LoginDetails) (LoginSession, error)

LogIn() verify the user account credentials and (if successfull) create a login session.

func (*UserSessions) LogOut

func (us *UserSessions) LogOut(session LoginSession)

LogOut() destroy the user login session

func (*UserSessions) SetUserDataHandle

func (us *UserSessions) SetUserDataHandle(ud iUserDataStorage)

Set the handler for the UserData interface. This function is used during the initialization of the UserSessionsInst singleton and it should not allow re-assigning the interface handle from other modules.

func (*UserSessions) SignUp

func (us *UserSessions) SignUp(un, pwd, email string, validationErrors ErrorsList) error

SignUp() Validates the user input and creates a new user entry in the user data storage. If any validation errors occur, no entries are creates and the the validationErrors variable is populated accordingly with all the error messages. If a non-validation error occurs, the function returns it. func (us *UserSessions) SignUp(un, pwd, email string, validationErrors ErrorsList) error {

func (*UserSessions) VerifyLoginSession

func (us *UserSessions) VerifyLoginSession(session LoginSession) bool

VerifyLoginSession verify the user login session info

type UserSessionsErrors

type UserSessionsErrors struct {
	ErrInvalidUserCredentials error
	ErrDuplicateEmail         error
	ErrDuplicateUsername      error
	ErrUserDoesNotExist       error
}

type UserSessionsLogger

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

func GetLogger

func GetLogger() *UserSessionsLogger

func (*UserSessionsLogger) SetErrorLogger

func (l *UserSessionsLogger) SetErrorLogger(logger *log.Logger)

func (*UserSessionsLogger) SetInfoLogger

func (l *UserSessionsLogger) SetInfoLogger(logger *log.Logger)

Jump to

Keyboard shortcuts

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