support unlinking external authentication

This commit is contained in:
MaysWind
2025-10-25 02:45:40 +08:00
parent 7b49a9f142
commit ce752c992c
26 changed files with 707 additions and 39 deletions
+50 -3
View File
@@ -11,7 +11,54 @@ type UserExternalAuth struct {
CreatedUnixTime int64
}
// UserExternalAuthRevokeRequest represents all parameters of user external auth revoke request
type UserExternalAuthRevokeRequest struct {
ExternalAuthType core.UserExternalAuthType `json:"externalAuthType" binding:"required,notBlank"`
// UserExternalAuthUnlinkRequest represents all parameters of user external auth unlink request
type UserExternalAuthUnlinkRequest struct {
ExternalAuthType string `json:"externalAuthType" binding:"required,notBlank"`
Password string `json:"password" binding:"required,min=6,max=128"`
}
// UserExternalAuthInfoResponse represents a view-object of user external auth
type UserExternalAuthInfoResponse struct {
ExternalAuthCategory string `json:"externalAuthCategory"`
ExternalAuthType core.UserExternalAuthType `json:"externalAuthType"`
Linked bool `json:"linked"`
ExternalUsername string `json:"externalUsername,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
}
// ToUserExternalAuthInfoResponse returns a view-object according to database model
func (a *UserExternalAuth) ToUserExternalAuthInfoResponse() *UserExternalAuthInfoResponse {
return &UserExternalAuthInfoResponse{
ExternalAuthCategory: a.ExternalAuthType.GetCategory(),
ExternalAuthType: a.ExternalAuthType,
Linked: true,
ExternalUsername: a.ExternalUsername,
CreatedAt: a.CreatedUnixTime,
}
}
// UserExternalAuthInfoResponsesSlice represents the slice data structure of UserExternalAuthInfoResponse
type UserExternalAuthInfoResponsesSlice []*UserExternalAuthInfoResponse
// Len returns the count of items
func (a UserExternalAuthInfoResponsesSlice) Len() int {
return len(a)
}
// Swap swaps two items
func (a UserExternalAuthInfoResponsesSlice) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
// Less reports whether the first item is less than the second one
func (a UserExternalAuthInfoResponsesSlice) Less(i, j int) bool {
if a[i].Linked && !a[j].Linked {
return true
} else if !a[i].Linked && a[j].Linked {
return false
} else if !a[i].Linked && !a[j].Linked {
return a[i].ExternalAuthType < a[j].ExternalAuthType
}
return a[i].CreatedAt > a[j].CreatedAt
}