2021-12-14 14:07:11 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-12-14 14:07:11 +05:30
|
|
|
|
|
|
|
package externalaccount
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-12-15 12:29:57 +05:30
|
|
|
|
2021-12-14 14:07:11 +05:30
|
|
|
"github.com/markbates/goth"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Store represents a thing that stores things
|
|
|
|
type Store interface {
|
|
|
|
Get(interface{}) interface{}
|
|
|
|
Set(interface{}, interface{}) error
|
|
|
|
Release() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkAccountFromStore links the provided user with a stored external user
|
|
|
|
func LinkAccountFromStore(store Store, user *user_model.User) error {
|
|
|
|
gothUser := store.Get("linkAccountGothUser")
|
|
|
|
if gothUser == nil {
|
|
|
|
return fmt.Errorf("not in LinkAccount session")
|
|
|
|
}
|
|
|
|
|
|
|
|
return LinkAccountToUser(user, gothUser.(goth.User))
|
|
|
|
}
|