authStuff

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyLoggedIn = errors.New("Already logged in")
View Source
var ErrInvalidSession = errors.New("Session not valid")
View Source
var ErrUserDoesNotExist = errors.New("User with this Name does not exist")
View Source
var ErrUserNotKnown = errors.New("User not in database")
View Source
var ErrUsernameTaken = errors.New("already exists")
View Source
var ErrWrongCredetials = errors.New("Wrong creds for username")

Functions

func SaltPw

func SaltPw(hasher hash.Hash, pw, salt string) string

Types

type Auth

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

Auth maps session ids to sessions

func NewAuth

func NewAuth(usrRepo *UserRepo, sessionTTL int) *Auth

NewAuth is a constructor for Auth

func (*Auth) AddNewSession

func (auth *Auth) AddNewSession() string

AddNewSession creates a new sessionid and remembers the session for later reference by the client

func (*Auth) CheckLoginStatus

func (auth *Auth) CheckLoginStatus(ctx *gin.Context)

CheckLoginStatus checks if the session is logged in and then executes the given handle

func (*Auth) CheckSession

func (auth *Auth) CheckSession(ctx *gin.Context)

CheckSession checks if the sessionID is valid. If no sessionID is given, a new one is created and added as a header

func (*Auth) GetSessionInfo

func (auth *Auth) GetSessionInfo(id string) (*LoginInfo, error)

GetSessionInfo maps the sessionid to the LoginInfo

func (*Auth) LogIn

func (auth *Auth) LogIn(sesID, name, password string) error

LogIn checks the credentials against the authentikator and marks the session as loggedin

func (*Auth) LogOut

func (auth *Auth) LogOut(id string) error

LogOut clears the LoginInfo of this session

type Authentikator

type Authentikator interface {
	// contains filtered or unexported methods
}

Authentikator is an interface that will allow for other sign-in methods later

type LoginController

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

LoginController is the controller for the logins

func NewLoginController

func NewLoginController(auth *Auth) *LoginController

NewLoginController creates a new LoginController and initializes the service

func (*LoginController) GetUser

func (controller *LoginController) GetUser(ctx *gin.Context)

GetUser sends the info for a logged in user

func (*LoginController) LogOut

func (controller *LoginController) LogOut(ctx *gin.Context)

LogOut uncouples the session from the logininfo

func (*LoginController) Login

func (controller *LoginController) Login(ctx *gin.Context)

Login checks whether "name" and "password" are valid and updates the logininfo if so

func (*LoginController) NewSession

func (controller *LoginController) NewSession(ctx *gin.Context)

NewSession creates a new session id and writes it to as an answer

func (*LoginController) SetEmail

func (controller *LoginController) SetEmail(ctx *gin.Context)

SetEmail sets the email for a logged in user

type LoginInfo

type LoginInfo struct {
	Name      string
	LoggedIn  bool
	Salt      string
	Pwhash    string
	LastLogin time.Time
	Email     string
}

LoginInfo is passed into the context if the session has a logged in user

func GetLoginInfoFromCtx

func GetLoginInfoFromCtx(ctx *gin.Context) (*LoginInfo, error)

GetLoginInfoFromCtx : Utility function for other controllers to get the LoginInfo from their Context

type LoginService

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

func NewLoginService

func NewLoginService(usrRepo *UserRepo) *LoginService

func (*LoginService) Add

func (ls *LoginService) Add(new *LoginInfo) error

func (*LoginService) SetEmail

func (ls *LoginService) SetEmail(username, email string) error

type Session

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

Session identifies a session with a Client. If the client logs in, the session remembers the login info (without the password of course) until the client logs out.

type UserRepo

type UserRepo struct {
	Lock sync.RWMutex
	// contains filtered or unexported fields
}

func NewUserRepo

func NewUserRepo(dir string) (*UserRepo, error)

func (*UserRepo) BackupTo

func (ur *UserRepo) BackupTo(bkpDest string) error

func (*UserRepo) DeleteInstance

func (ur *UserRepo) DeleteInstance(infoName string) error

func (*UserRepo) GetAllUsers

func (ur *UserRepo) GetAllUsers() ([]*LoginInfo, error)

func (*UserRepo) GetInstance

func (ur *UserRepo) GetInstance(infoName string) (*LoginInfo, error)

func (*UserRepo) SaveInstance

func (ur *UserRepo) SaveInstance(info *LoginInfo) error

Jump to

Keyboard shortcuts

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