session

package
v0.0.0-...-0bd2313 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteSessionByTokenRequest

type DeleteSessionByTokenRequest struct {
	Token string `json:"-"`
}

type DeleteSessionRequest

type DeleteSessionRequest struct {
	ID uint64 `json:"-"`
}

type GetUserActiveSessionsRequest

type GetUserActiveSessionsRequest struct {
	UserID uint64 `json:"-"`
}

type GetUserActiveSessionsResponse

type GetUserActiveSessionsResponse struct {
	Current *Session   `json:"current,omitempty"`
	Others  []*Session `json:"others,omitempty"`
}

type OAuthSignRequest

type OAuthSignRequest struct {
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Email     string `json:"email,omitempty"`
}

func (OAuthSignRequest) Validate

func (r OAuthSignRequest) Validate() error

type PersistenceProvider

type PersistenceProvider interface {
	SessionPersister() Persister
}

type Persister

type Persister interface {
	FindSession(context.Context, uint64) (*Session, error)
	FindSessionByToken(context.Context, string) (*Session, error)
	FindUserSessions(context.Context, uint64) ([]*Session, error)
	CreateSession(context.Context, *Session) error
	RemoveSession(context.Context, uint64) error
	RemoveUserSessions(context.Context, uint64, ...string) error
}

type Properties

type Properties struct {
	IPLocation *ip.IPLocation  `json:"ip_location,omitempty"`
	UAInfo     *httplib.UAInfo `json:"ua_info,omitempty"`
}

type Service

type Service interface {
	GetSession(context.Context, string) (*Session, error)
	GetUserActiveSessions(context.Context, *GetUserActiveSessionsRequest) (*GetUserActiveSessionsResponse, error)
	DeleteSession(context.Context, *DeleteSessionRequest) error
	DeleteSessionByToken(context.Context, *DeleteSessionByTokenRequest) error
	IssueSession(context.Context, *SigninRequest) (*Session, error)
	OAuthIssueSession(context.Context, *OAuthSignRequest) (*Session, error)
}

type ServiceProvider

type ServiceProvider interface {
	SessionService() Service
}

type Session

type Session struct {
	ID         uint64      `xorm:"pk 'id'" json:"id"`
	UserID     uint64      `xorm:"'user_id'" json:"-"`
	Token      string      `xorm:"varchar(50) not null unique" json:"-"`
	Active     bool        `xorm:"not null" json:"-"`
	IssuedAt   time.Time   `xorm:"not null" json:"issued_at"`
	ExpiresAt  time.Time   `xorm:"not null" json:"-"`
	Properties *Properties `xorm:"json" json:"properties"`

	CreatedAt time.Time `xorm:"created" json:"-"`
	UpdatedAt time.Time `xorm:"updated" json:"-"`
	DeletedAt time.Time `xorm:"deleted" json:"-"`
}

func NewActiveSession

func NewActiveSession(userID uint64, lifespan time.Duration) *Session

func (*Session) IsActive

func (s *Session) IsActive() bool

func (*Session) SetIPLocation

func (s *Session) SetIPLocation(ipl *ip.IPLocation) *Session

func (*Session) SetUAInfo

func (s *Session) SetUAInfo(uai *httplib.UAInfo) *Session

type SigninRequest

type SigninRequest struct {
	Identifier string `json:"identifier,omitempty"`
	Password   string `json:"password,omitempty"`
	Remember   bool   `json:"remember,omitempty"`
}

func (SigninRequest) Validate

func (r SigninRequest) Validate() error

Jump to

Keyboard shortcuts

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