diff --git a/models/user.go b/models/user.go index 2820d2edb..4dc9aec65 100644 --- a/models/user.go +++ b/models/user.go @@ -214,6 +214,8 @@ func (u *User) APIFormat() *api.User { AvatarURL: u.AvatarLink(), Language: u.Language, IsAdmin: u.IsAdmin, + LastLogin: u.LastLoginUnix.AsTime(), + Created: u.CreatedUnix.AsTime(), } } diff --git a/modules/structs/user.go b/modules/structs/user.go index 251c80312..bf52cc9ed 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -6,6 +6,7 @@ package structs import ( "encoding/json" + "time" ) // User represents a user @@ -25,6 +26,10 @@ type User struct { Language string `json:"language"` // Is the user an administrator IsAdmin bool `json:"is_admin"` + // swagger:strfmt date-time + LastLogin time.Time `json:"last_login,omitempty"` + // swagger:strfmt date-time + Created time.Time `json:"created,omitempty"` } // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index a982cb8d3..80c0811ae 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -236,6 +236,8 @@ func ToUser(user *models.User, signed, admin bool) *api.User { AvatarURL: user.AvatarLink(), FullName: markup.Sanitize(user.FullName), IsAdmin: user.IsAdmin, + LastLogin: user.LastLoginUnix.AsTime(), + Created: user.CreatedUnix.AsTime(), } if signed && (!user.KeepEmailPrivate || admin) { result.Email = user.Email diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 2b40c8979..6f9585fae 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -9715,6 +9715,11 @@ "type": "string", "x-go-name": "AvatarURL" }, + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, "email": { "type": "string", "format": "email", @@ -9741,6 +9746,11 @@ "type": "string", "x-go-name": "Language" }, + "last_login": { + "type": "string", + "format": "date-time", + "x-go-name": "LastLogin" + }, "login": { "description": "the user's username", "type": "string",