2021-12-14 16:37:11 +08:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-12-14 16:37:11 +08:00
|
|
|
|
|
|
|
package externalaccount
|
|
|
|
|
|
|
|
import (
|
2023-09-25 21:17:37 +08:00
|
|
|
"context"
|
2021-12-14 16:37:11 +08:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2024-02-24 12:18:49 +08:00
|
|
|
|
|
|
|
"github.com/markbates/goth"
|
2021-12-14 16:37:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Store represents a thing that stores things
|
|
|
|
type Store interface {
|
2023-07-05 02:36:08 +08:00
|
|
|
Get(any) any
|
|
|
|
Set(any, any) error
|
2021-12-14 16:37:11 +08:00
|
|
|
Release() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkAccountFromStore links the provided user with a stored external user
|
2023-09-25 21:17:37 +08:00
|
|
|
func LinkAccountFromStore(ctx context.Context, store Store, user *user_model.User) error {
|
2024-02-24 12:18:49 +08:00
|
|
|
gothUser := store.Get("linkAccountGothUser")
|
|
|
|
if gothUser == nil {
|
2021-12-14 16:37:11 +08:00
|
|
|
return fmt.Errorf("not in LinkAccount session")
|
|
|
|
}
|
|
|
|
|
2024-02-24 12:18:49 +08:00
|
|
|
return LinkAccountToUser(ctx, user, gothUser.(goth.User))
|
2021-12-14 16:37:11 +08:00
|
|
|
}
|