2023-03-29 17:12:45 +08:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
type UserCenter interface {
|
|
|
|
Base
|
2023-04-03 11:17:38 +08:00
|
|
|
// Description returns the description of the user center, including the name, icon, url, etc.
|
2023-03-29 17:12:45 +08:00
|
|
|
Description() UserCenterDesc
|
2023-04-03 11:17:38 +08:00
|
|
|
// ControlCenterItems returns the items that will be displayed in the control center
|
2023-03-29 17:12:45 +08:00
|
|
|
ControlCenterItems() []ControlCenter
|
2023-04-03 11:17:38 +08:00
|
|
|
// LoginCallback is called when the user center login callback is called
|
2023-03-29 17:12:45 +08:00
|
|
|
LoginCallback(ctx *GinContext) (userInfo *UserCenterBasicUserInfo, err error)
|
2023-04-03 11:17:38 +08:00
|
|
|
// SignUpCallback is called when the user center sign up callback is called
|
2023-03-29 17:12:45 +08:00
|
|
|
SignUpCallback(ctx *GinContext) (userInfo *UserCenterBasicUserInfo, err error)
|
2023-04-03 11:17:38 +08:00
|
|
|
// UserInfo returns the user information
|
2023-03-29 17:12:45 +08:00
|
|
|
UserInfo(externalID string) (userInfo *UserCenterBasicUserInfo, err error)
|
2023-04-03 11:17:38 +08:00
|
|
|
// UserList returns the user list information
|
2023-03-29 17:12:45 +08:00
|
|
|
UserList(externalIDs []string) (userInfo []*UserCenterBasicUserInfo, err error)
|
2023-04-03 11:17:38 +08:00
|
|
|
// UserSettings returns the user settings
|
2023-03-29 17:12:45 +08:00
|
|
|
UserSettings(externalID string) (userSettings *SettingInfo, err error)
|
2023-04-03 11:17:38 +08:00
|
|
|
// PersonalBranding returns the personal branding information
|
2023-03-29 17:12:45 +08:00
|
|
|
PersonalBranding(externalID string) (branding []*PersonalBranding)
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserCenterDesc struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
LoginRedirectURL string `json:"login_redirect_url"`
|
|
|
|
SignUpRedirectURL string `json:"sign_up_redirect_url"`
|
|
|
|
RankAgentEnabled bool `json:"rank_agent_enabled"`
|
|
|
|
}
|
|
|
|
|
2023-04-03 11:17:38 +08:00
|
|
|
type UserStatus int
|
|
|
|
|
|
|
|
const (
|
|
|
|
UserStatusAvailable UserStatus = 1
|
|
|
|
UserStatusSuspended UserStatus = 9
|
|
|
|
UserStatusDeleted UserStatus = 10
|
|
|
|
)
|
|
|
|
|
2023-03-29 17:12:45 +08:00
|
|
|
type UserCenterBasicUserInfo struct {
|
2023-04-03 11:17:38 +08:00
|
|
|
ExternalID string `json:"external_id"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Rank int `json:"rank"`
|
|
|
|
Avatar string `json:"avatar"`
|
|
|
|
Mobile string `json:"mobile"`
|
|
|
|
Status UserStatus `json:"status"`
|
2023-03-29 17:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ControlCenter struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Label string `json:"label"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SettingInfo struct {
|
|
|
|
ProfileSettingRedirectURL string `json:"profile_setting_redirect_url"`
|
|
|
|
AccountSettingRedirectURL string `json:"account_setting_redirect_url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PersonalBranding struct {
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Label string `json:"label"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// CallUserCenter is a function that calls all registered parsers
|
|
|
|
CallUserCenter,
|
|
|
|
registerUserCenter = MakePlugin[UserCenter](false)
|
|
|
|
)
|
|
|
|
|
|
|
|
func UserCenterEnabled() (enabled bool) {
|
|
|
|
_ = CallUserCenter(func(fn UserCenter) error {
|
|
|
|
enabled = true
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func RankAgentEnabled() (enabled bool) {
|
|
|
|
_ = CallUserCenter(func(fn UserCenter) error {
|
|
|
|
enabled = fn.Description().RankAgentEnabled
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserCenter() (uc UserCenter, ok bool) {
|
|
|
|
_ = CallUserCenter(func(fn UserCenter) error {
|
|
|
|
uc = fn
|
|
|
|
ok = true
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|