2021-12-14 08:37:11 +00:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-12-14 08:37:11 +00:00
|
|
|
|
|
|
|
package externalaccount
|
|
|
|
|
|
|
|
import (
|
2023-09-25 15:17:37 +02:00
|
|
|
"context"
|
2025-05-29 17:34:29 +02:00
|
|
|
"errors"
|
2021-12-14 08:37:11 +00:00
|
|
|
|
2025-03-27 19:40:14 +00:00
|
|
|
user_model "forgejo.org/models/user"
|
2021-12-15 14:59:57 +08:00
|
|
|
|
2021-12-14 08:37:11 +00:00
|
|
|
"github.com/markbates/goth"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Store represents a thing that stores things
|
|
|
|
type Store interface {
|
2023-07-04 20:36:08 +02:00
|
|
|
Get(any) any
|
|
|
|
Set(any, any) error
|
2021-12-14 08:37:11 +00:00
|
|
|
Release() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkAccountFromStore links the provided user with a stored external user
|
2023-09-25 15:17:37 +02:00
|
|
|
func LinkAccountFromStore(ctx context.Context, store Store, user *user_model.User) error {
|
2021-12-14 08:37:11 +00:00
|
|
|
gothUser := store.Get("linkAccountGothUser")
|
|
|
|
if gothUser == nil {
|
2025-05-29 17:34:29 +02:00
|
|
|
return errors.New("not in LinkAccount session")
|
2021-12-14 08:37:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-25 15:17:37 +02:00
|
|
|
return LinkAccountToUser(ctx, user, gothUser.(goth.User))
|
2021-12-14 08:37:11 +00:00
|
|
|
}
|