diff options
author | renothing <261274+renothing@users.noreply.github.com> | 2019-07-27 21:15:30 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-07-27 16:15:30 +0300 |
commit | cbf231a67595feb36fccb68dc00b2bc7607fa882 (patch) | |
tree | 9f200fb9c89dc79a2f6a6472901668753a742aa3 /models/user.go | |
parent | 700cd346fad3a0bed203bfb032f7b4bc9d1f2551 (diff) | |
download | gitea-cbf231a67595feb36fccb68dc00b2bc7607fa882.tar.gz gitea-cbf231a67595feb36fccb68dc00b2bc7607fa882.zip |
fix wrong email when use gitea as OAuth2 provider (#7640)
when you use gitea as OAuth2 provider, the /api/v1/user should return
user primary email as identifier, which is unique in OAuth2 clients.
this patch use convert.ToUser replace all u.APIFormat in api requests,
return primary email when caller is yourself or admin.
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/models/user.go b/models/user.go index aa3e527cd5..1f684a5940 100644 --- a/models/user.go +++ b/models/user.go @@ -204,9 +204,9 @@ func (u *User) UpdateTheme(themeName string) error { return UpdateUserCols(u, "theme") } -// getEmail returns an noreply email, if the user has set to keep his +// GetEmail returns an noreply email, if the user has set to keep his // email address private, otherwise the primary email address. -func (u *User) getEmail() string { +func (u *User) GetEmail() string { if u.KeepEmailPrivate { return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress) } @@ -219,7 +219,7 @@ func (u *User) APIFormat() *api.User { ID: u.ID, UserName: u.Name, FullName: u.FullName, - Email: u.getEmail(), + Email: u.GetEmail(), AvatarURL: u.AvatarLink(), Language: u.Language, IsAdmin: u.IsAdmin, @@ -434,7 +434,7 @@ func (u *User) GetFollowing(page int) ([]*User, error) { func (u *User) NewGitSig() *git.Signature { return &git.Signature{ Name: u.GitName(), - Email: u.getEmail(), + Email: u.GetEmail(), When: time.Now(), } } |