mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 23:47:33 +08:00
support unlinking external authentication
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user