Documentation
¶
Index ¶
- Constants
- Variables
- func SetAuthContext(ctx scene.Context, userID string, srv UserInfoService)
- type AuthContext
- type AuthenticationManageService
- type AuthenticationRepository
- type AuthenticationService
- type HTTPLoginStatusVerifier
- type LoginStatus
- type User
- type UserInfo
- type UserInfoRepository
- type UserInfoService
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 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 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 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 ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.