Documentation ¶
Index ¶
- Variables
- func SaltPw(hasher hash.Hash, pw, salt string) string
- type Auth
- func (auth *Auth) AddNewSession() string
- func (auth *Auth) CheckLoginStatus(ctx *gin.Context)
- func (auth *Auth) CheckSession(ctx *gin.Context)
- func (auth *Auth) GetSessionInfo(id string) (*LoginInfo, error)
- func (auth *Auth) LogIn(sesID, name, password string) error
- func (auth *Auth) LogOut(id string) error
- type Authentikator
- type LoginController
- func (controller *LoginController) GetUser(ctx *gin.Context)
- func (controller *LoginController) LogOut(ctx *gin.Context)
- func (controller *LoginController) Login(ctx *gin.Context)
- func (controller *LoginController) NewSession(ctx *gin.Context)
- func (controller *LoginController) SetEmail(ctx *gin.Context)
- type LoginInfo
- type LoginService
- type Session
- type UserRepo
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyLoggedIn = errors.New("Already logged in")
var ErrInvalidSession = errors.New("Session not valid")
var ErrUserDoesNotExist = errors.New("User with this Name does not exist")
var ErrUserNotKnown = errors.New("User not in database")
var ErrUsernameTaken = errors.New("already exists")
var ErrWrongCredetials = errors.New("Wrong creds for username")
Functions ¶
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth maps session ids to sessions
func (*Auth) AddNewSession ¶
AddNewSession creates a new sessionid and remembers the session for later reference by the client
func (*Auth) CheckLoginStatus ¶
CheckLoginStatus checks if the session is logged in and then executes the given handle
func (*Auth) CheckSession ¶
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 ¶
GetSessionInfo maps the sessionid to the LoginInfo
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
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.