code.gitea.io/gitea@v1.21.7/services/externalaccount/link.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package externalaccount
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  
    10  	user_model "code.gitea.io/gitea/models/user"
    11  
    12  	"github.com/markbates/goth"
    13  )
    14  
    15  // Store represents a thing that stores things
    16  type Store interface {
    17  	Get(any) any
    18  	Set(any, any) error
    19  	Release() error
    20  }
    21  
    22  // LinkAccountFromStore links the provided user with a stored external user
    23  func LinkAccountFromStore(ctx context.Context, store Store, user *user_model.User) error {
    24  	gothUser := store.Get("linkAccountGothUser")
    25  	if gothUser == nil {
    26  		return fmt.Errorf("not in LinkAccount session")
    27  	}
    28  
    29  	return LinkAccountToUser(ctx, user, gothUser.(goth.User))
    30  }