Allow username to be used with multiple forges (#5676)

This commit is contained in:
6543
2025-10-23 17:28:01 +02:00
committed by GitHub
parent c77ca3eb33
commit 6fa163514b
3 changed files with 7 additions and 6 deletions

View File

@@ -210,6 +210,7 @@ func HandleAuth(c *gin.Context) {
// insert the user into the database
if err := _store.CreateUser(user); err != nil {
log.Error().Err(err).Msgf("cannot insert %s", user.Login)
log.Trace().Msgf("user was: %#v", user)
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=internal_error")
return
}

View File

@@ -120,16 +120,16 @@ func (c *Gitea) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mode
token, err := config.Exchange(oauth2Ctx, req.Code)
if err != nil {
return nil, redirectURL, err
return nil, redirectURL, fmt.Errorf("oauth2 config exchange failed: %w", err)
}
client, err := c.newClientToken(ctx, token.AccessToken)
if err != nil {
return nil, redirectURL, err
return nil, redirectURL, fmt.Errorf("client creation with new access token failed: %w", err)
}
account, _, err := client.GetMyUserInfo()
if err != nil {
return nil, redirectURL, err
return nil, redirectURL, fmt.Errorf("fetching user info failed: %w", err)
}
return &model.User{

View File

@@ -34,14 +34,14 @@ type User struct {
// required: true
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
ForgeID int64 `json:"forge_id,omitempty" xorm:"forge_id UNIQUE(forge)"`
ForgeID int64 `json:"forge_id,omitempty" xorm:"forge_id UNIQUE(forge_id) UNIQUE(forge_login)"`
ForgeRemoteID ForgeRemoteID `json:"forge_remote_id" xorm:"forge_remote_id UNIQUE(forge)"`
ForgeRemoteID ForgeRemoteID `json:"forge_remote_id" xorm:"forge_remote_id UNIQUE(forge_id)"`
// Login is the username for this user.
//
// required: true
Login string `json:"login" xorm:"UNIQUE 'login'"`
Login string `json:"login" xorm:"'login' UNIQUE(forge_login)"`
// AccessToken is the oauth2 access token.
AccessToken string `json:"-" xorm:"TEXT 'access_token'"`