-
Notifications
You must be signed in to change notification settings - Fork 27
/
check_identity_conflict.go
54 lines (43 loc) · 1.65 KB
/
check_identity_conflict.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nodes
import (
"errors"
"github.com/authgear/authgear-server/pkg/lib/authn/identity"
"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/interaction"
)
func init() {
interaction.RegisterNode(&NodeCheckIdentityConflict{})
}
type EdgeCheckIdentityConflict struct {
NewIdentity *identity.Info
}
func (e *EdgeCheckIdentityConflict) Instantiate(ctx *interaction.Context, graph *interaction.Graph, rawInput interface{}) (interaction.Node, error) {
dupeIdentity, err := ctx.Identities.CheckDuplicated(e.NewIdentity)
if err != nil && !errors.Is(err, identity.ErrIdentityAlreadyExists) {
return nil, err
}
return &NodeCheckIdentityConflict{
NewIdentity: e.NewIdentity,
DuplicatedIdentity: dupeIdentity,
}, nil
}
type NodeCheckIdentityConflict struct {
NewIdentity *identity.Info `json:"new_identity"`
DuplicatedIdentity *identity.Info `json:"duplicated_identity"`
IdentityConflictConfig *config.IdentityConflictConfig `json:"-"`
}
func (n *NodeCheckIdentityConflict) Prepare(ctx *interaction.Context, graph *interaction.Graph) error {
n.IdentityConflictConfig = ctx.Config.Identity.OnConflict
return nil
}
func (n *NodeCheckIdentityConflict) GetEffects() ([]interaction.Effect, error) {
return nil, nil
}
func (n *NodeCheckIdentityConflict) DeriveEdges(graph *interaction.Graph) ([]interaction.Edge, error) {
return graph.Intent.DeriveEdgesForNode(graph, n)
}
func (n *NodeCheckIdentityConflict) FillDetails(err error) error {
spec := n.NewIdentity.ToSpec()
otherSpec := n.DuplicatedIdentity.ToSpec()
return identityFillDetails(err, &spec, &otherSpec)
}