authentication

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Lens scene.ModuleName = "authentication"

Variables

View Source
var (
	ErrAuthenticationFailed = _eg.CreateError(0, "authentication failed")
	ErrUserAlreadyExists    = _eg.CreateError(1, "user already exists")
	ErrUserNotFound         = _eg.CreateError(2, "user not found")
	ErrNotLogin             = _eg.CreateError(3, "not login")
)

Functions

func SetAuthContext added in v0.2.8

func SetAuthContext(ctx scene.Context, userID string, srv UserInfoService)

Types

type AuthContext

type AuthContext struct {
	UserID string
	// contains filtered or unexported fields
}

func GetAuthContext added in v0.2.8

func GetAuthContext(ctx scene.Context) (AuthContext, bool)

func NewAuthContext

func NewAuthContext(
	userID string,
	srv UserInfoService) AuthContext

func (*AuthContext) IsLogin

func (c *AuthContext) IsLogin() bool

func (*AuthContext) UserInfo

func (c *AuthContext) UserInfo() (UserInfo, error)

type AuthenticationManageService

type AuthenticationManageService interface {
	AuthenticationService
	AddUser(username, password string) (User, error)
	DeleteUser(userId string) error
	UpdateUser(user User) error
}

type AuthenticationRepository

type AuthenticationRepository interface {
	scene.Named
	Authenticate(username string, password string) (userID string, err error)
	UserById(userId string) (User, error)
	UserByName(username string) (User, error)
	UserByEmail(email string) (User, error)

	AddUser(username, password string) (User, error)
	DeleteUser(userId string) error
	UpdateUser(user User) error
}

type AuthenticationService

type AuthenticationService interface {
	scene.Service
	Authenticate(username string, password string) (userID string, err error)
	UserById(userId string) (User, error)
	UserByName(username string) (User, error)
	UserByEmail(email string) (User, error)
}

type HTTPLoginStatusVerifier

type HTTPLoginStatusVerifier interface {
	scene.Service
	Verify(request *http.Request) (status LoginStatus, err error)
	Login(userId string, resp http.ResponseWriter) (status LoginStatus, err error)
	Logout(resp http.ResponseWriter) (err error)
}

type LoginStatus

type LoginStatus struct {
	UserID   string `json:"user_id"`
	Token    string `json:"token"`
	Verifier string `json:"verifier"`
	ExpireAt int64  `json:"expire_at"`
}

type User

type User struct {
	// UserID unique id. should be generated by server.
	UserID string `json:"user_id" bson:"user_id"`
	// Username unique name. should be unique. should be input by user. but can be changed
	Username string `json:"username" bson:"username"`
	// Password just password. for now, store in plain text
	Password string `json:"password" bson:"password"`
	// Email user's email address
	Email string `json:"email" bson:"email"`
}

type UserInfo

type UserInfo struct {
	// Stored value
	UserID      string `json:"user_id" bson:"user_id"`
	DisplayName string `json:"display_name" bson:"display_name"`
	Avatar      string `json:"avatar" bson:"avatar"`
	Timezone    string `json:"timezone" bson:"timezone"`
	// Derived value
	Username string `json:"username" bson:"username,omitempty"` // from User
	Email    string `json:"email" bson:"email,omitempty"`       // from User
}

type UserInfoRepository

type UserInfoRepository interface {
	scene.Named
	InfoById(userId string) (UserInfo, error)
}

type UserInfoService

type UserInfoService interface {
	scene.Service
	InfoById(userId string) (UserInfo, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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