Documentation ¶
Index ¶
- type AuthenticationRules
- type Authenticator
- func (auth *Authenticator) AuthenticateUser(r *http.Request) error
- func (auth *Authenticator) GetSessionFromRequest(r *http.Request) string
- func (auth *Authenticator) Login(username, password string) (string, model.User, error)
- func (auth *Authenticator) Logout(r *http.Request) error
- func (auth *Authenticator) MassLogout(username string)
- func (auth *Authenticator) MustAuthenticateUser(r *http.Request)
- type SessionManager
- func (sm *SessionManager) GetUser(session string) (model.User, time.Time, bool)
- func (sm *SessionManager) ProlongUserSession(session string, duration time.Duration)
- func (sm *SessionManager) RegisterUser(user model.User, duration time.Duration) (string, error)
- func (sm *SessionManager) RemoveUserSession(session string)
- func (sm *SessionManager) RemoveUsername(username string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticationRules ¶
AuthenticationRules is function to check whether an user allowed to access an URL.
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator is object to authenticate a http request. It also handles login and logout.
func NewAuthenticator ¶
func NewAuthenticator(db *sqlx.DB, rules AuthenticationRules) (*Authenticator, error)
NewAuthenticator returns new Authenticator
func (*Authenticator) AuthenticateUser ¶
func (auth *Authenticator) AuthenticateUser(r *http.Request) error
AuthenticateUser checks whether the session is still valid. If yes, prolong its expiration time as well.
func (*Authenticator) GetSessionFromRequest ¶
func (auth *Authenticator) GetSessionFromRequest(r *http.Request) string
GetSessionFromRequest as its name implies, will get the session ID from http request.
func (*Authenticator) Login ¶
Login verify that username and password match, generate session ID then save it to cache.
func (*Authenticator) Logout ¶
func (auth *Authenticator) Logout(r *http.Request) error
Logout invalidates session
func (*Authenticator) MassLogout ¶
func (auth *Authenticator) MassLogout(username string)
MassLogout invalidates all sessions for an user.
func (*Authenticator) MustAuthenticateUser ¶
func (auth *Authenticator) MustAuthenticateUser(r *http.Request)
MustAuthenticateUser is like AuthenticateUser, except it's panic when request doesn't have a valid session.
type SessionManager ¶
SessionManager is struct to manage all sessions
func NewSessionManager ¶
func NewSessionManager(defaultExpiration, cleanupInterval time.Duration) *SessionManager
NewSessionManager returnns new SessionManager.
func (*SessionManager) ProlongUserSession ¶
func (sm *SessionManager) ProlongUserSession(session string, duration time.Duration)
ProlongUserSession extends the expiration time for specified session
func (*SessionManager) RegisterUser ¶
RegisterUser register user and return its session
func (*SessionManager) RemoveUserSession ¶
func (sm *SessionManager) RemoveUserSession(session string)
RemoveUserSession removes the specified session from list of active user sessions.
func (*SessionManager) RemoveUsername ¶
func (sm *SessionManager) RemoveUsername(username string)
RemoveUsername removes the specified username from list of active sessions. Used for mass logout.