Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last_login field to User struct #583

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions account_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ const (
UserTypeDefault UserType = "default"
)

// LastLogin represents a LastLogin object
type LastLogin struct {
LoginDatetime *time.Time `json:"-"`
Status string `json:"status"`
}

// User represents a User object
type User struct {
Username string `json:"username"`
Email string `json:"email"`
LastLogin *LastLogin `json:"last_login"`
UserType UserType `json:"user_type"`
Restricted bool `json:"restricted"`
TFAEnabled bool `json:"tfa_enabled"`
Expand All @@ -42,6 +49,26 @@ type UserUpdateOptions struct {
Restricted *bool `json:"restricted,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (ll *LastLogin) UnmarshalJSON(b []byte) error {
type Mask LastLogin

p := struct {
*Mask
LoginDatetime *parseabletime.ParseableTime `json:"login_datetime"`
}{
Mask: (*Mask)(ll),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

ll.LoginDatetime = (*time.Time)(p.LoginDatetime)

return nil
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (i *User) UnmarshalJSON(b []byte) error {
type Mask User
Expand Down