From 2f48d457730ece630405b555ec9253333648df3a Mon Sep 17 00:00:00 2001 From: Husile <73925108+Bsheepcoder@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:54:34 +0800 Subject: [PATCH] feat: fix OIDC address field (#3013) * feat:add fields of sync-database * feat:add fields of sync-database * feat: add several fields related to the OIDC specification address * feat: add the field Address to Address structure in UserWithoutThirdIdp * fix: delete redundant fields * fix: add Address struct and delete redundant fields --- object/token_jwt.go | 143 +++++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 60 deletions(-) diff --git a/object/token_jwt.go b/object/token_jwt.go index 7970b204..cfbe076b 100644 --- a/object/token_jwt.go +++ b/object/token_jwt.go @@ -50,48 +50,48 @@ type UserWithoutThirdIdp struct { UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"` DeletedTime string `xorm:"varchar(100)" json:"deletedTime"` - Id string `xorm:"varchar(100) index" json:"id"` - Type string `xorm:"varchar(100)" json:"type"` - Password string `xorm:"varchar(150)" json:"password"` - PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"` - PasswordType string `xorm:"varchar(100)" json:"passwordType"` - DisplayName string `xorm:"varchar(100)" json:"displayName"` - FirstName string `xorm:"varchar(100)" json:"firstName"` - LastName string `xorm:"varchar(100)" json:"lastName"` - Avatar string `xorm:"varchar(500)" json:"avatar"` - AvatarType string `xorm:"varchar(100)" json:"avatarType"` - PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"` - Email string `xorm:"varchar(100) index" json:"email"` - EmailVerified bool `json:"emailVerified"` - Phone string `xorm:"varchar(100) index" json:"phone"` - CountryCode string `xorm:"varchar(6)" json:"countryCode"` - Region string `xorm:"varchar(100)" json:"region"` - Location string `xorm:"varchar(100)" json:"location"` - Address []string `json:"address"` - Affiliation string `xorm:"varchar(100)" json:"affiliation"` - Title string `xorm:"varchar(100)" json:"title"` - IdCardType string `xorm:"varchar(100)" json:"idCardType"` - IdCard string `xorm:"varchar(100) index" json:"idCard"` - Homepage string `xorm:"varchar(100)" json:"homepage"` - Bio string `xorm:"varchar(100)" json:"bio"` - Tag string `xorm:"varchar(100)" json:"tag"` - Language string `xorm:"varchar(100)" json:"language"` - Gender string `xorm:"varchar(100)" json:"gender"` - Birthday string `xorm:"varchar(100)" json:"birthday"` - Education string `xorm:"varchar(100)" json:"education"` - Score int `json:"score"` - Karma int `json:"karma"` - Ranking int `json:"ranking"` - IsDefaultAvatar bool `json:"isDefaultAvatar"` - IsOnline bool `json:"isOnline"` - IsAdmin bool `json:"isAdmin"` - IsForbidden bool `json:"isForbidden"` - IsDeleted bool `json:"isDeleted"` - SignupApplication string `xorm:"varchar(100)" json:"signupApplication"` - Hash string `xorm:"varchar(100)" json:"hash"` - PreHash string `xorm:"varchar(100)" json:"preHash"` - AccessKey string `xorm:"varchar(100)" json:"accessKey"` - AccessSecret string `xorm:"varchar(100)" json:"accessSecret"` + Id string `xorm:"varchar(100) index" json:"id"` + Type string `xorm:"varchar(100)" json:"type"` + Password string `xorm:"varchar(150)" json:"password"` + PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"` + PasswordType string `xorm:"varchar(100)" json:"passwordType"` + DisplayName string `xorm:"varchar(100)" json:"displayName"` + FirstName string `xorm:"varchar(100)" json:"firstName"` + LastName string `xorm:"varchar(100)" json:"lastName"` + Avatar string `xorm:"varchar(500)" json:"avatar"` + AvatarType string `xorm:"varchar(100)" json:"avatarType"` + PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"` + Email string `xorm:"varchar(100) index" json:"email"` + EmailVerified bool `json:"emailVerified"` + Phone string `xorm:"varchar(100) index" json:"phone"` + CountryCode string `xorm:"varchar(6)" json:"countryCode"` + Region string `xorm:"varchar(100)" json:"region"` + Location string `xorm:"varchar(100)" json:"location"` + Address Address `json:"address"` + Affiliation string `xorm:"varchar(100)" json:"affiliation"` + Title string `xorm:"varchar(100)" json:"title"` + IdCardType string `xorm:"varchar(100)" json:"idCardType"` + IdCard string `xorm:"varchar(100) index" json:"idCard"` + Homepage string `xorm:"varchar(100)" json:"homepage"` + Bio string `xorm:"varchar(100)" json:"bio"` + Tag string `xorm:"varchar(100)" json:"tag"` + Language string `xorm:"varchar(100)" json:"language"` + Gender string `xorm:"varchar(100)" json:"gender"` + Birthday string `xorm:"varchar(100)" json:"birthday"` + Education string `xorm:"varchar(100)" json:"education"` + Score int `json:"score"` + Karma int `json:"karma"` + Ranking int `json:"ranking"` + IsDefaultAvatar bool `json:"isDefaultAvatar"` + IsOnline bool `json:"isOnline"` + IsAdmin bool `json:"isAdmin"` + IsForbidden bool `json:"isForbidden"` + IsDeleted bool `json:"isDeleted"` + SignupApplication string `xorm:"varchar(100)" json:"signupApplication"` + Hash string `xorm:"varchar(100)" json:"hash"` + PreHash string `xorm:"varchar(100)" json:"preHash"` + AccessKey string `xorm:"varchar(100)" json:"accessKey"` + AccessSecret string `xorm:"varchar(100)" json:"accessSecret"` GitHub string `xorm:"github varchar(100)" json:"github"` Google string `xorm:"varchar(100)" json:"google"` @@ -148,6 +148,15 @@ type ClaimsWithoutThirdIdp struct { jwt.RegisteredClaims } +type Address struct { + Formatted string `json:"formatted"` + StreetAddress string `json:"street_address"` + Locality string `json:"locality"` + Region string `json:"region"` + PostalCode string `json:"postal_code"` + Country string `json:"country"` +} + func getShortUser(user *User) *UserShort { res := &UserShort{ Owner: user.Owner, @@ -162,6 +171,13 @@ func getShortUser(user *User) *UserShort { return res } +func getStreetAddress(user *User) string { + if len(user.Address) > 0 { + return user.Address[0] + } + return "" +} + func getUserWithoutThirdIdp(user *User) *UserWithoutThirdIdp { res := &UserWithoutThirdIdp{ Owner: user.Owner, @@ -170,24 +186,31 @@ func getUserWithoutThirdIdp(user *User) *UserWithoutThirdIdp { UpdatedTime: user.UpdatedTime, DeletedTime: user.DeletedTime, - Id: user.Id, - Type: user.Type, - Password: user.Password, - PasswordSalt: user.PasswordSalt, - PasswordType: user.PasswordType, - DisplayName: user.DisplayName, - FirstName: user.FirstName, - LastName: user.LastName, - Avatar: user.Avatar, - AvatarType: user.AvatarType, - PermanentAvatar: user.PermanentAvatar, - Email: user.Email, - EmailVerified: user.EmailVerified, - Phone: user.Phone, - CountryCode: user.CountryCode, - Region: user.Region, - Location: user.Location, - Address: user.Address, + Id: user.Id, + Type: user.Type, + Password: user.Password, + PasswordSalt: user.PasswordSalt, + PasswordType: user.PasswordType, + DisplayName: user.DisplayName, + FirstName: user.FirstName, + LastName: user.LastName, + Avatar: user.Avatar, + AvatarType: user.AvatarType, + PermanentAvatar: user.PermanentAvatar, + Email: user.Email, + EmailVerified: user.EmailVerified, + Phone: user.Phone, + CountryCode: user.CountryCode, + Region: user.Region, + Location: user.Location, + Address: Address{ + Formatted: "", + StreetAddress: getStreetAddress(user), + Locality: "", + Region: "", + PostalCode: "", + Country: "", + }, Affiliation: user.Affiliation, Title: user.Title, IdCardType: user.IdCardType,