-
Notifications
You must be signed in to change notification settings - Fork 27
/
do_generate_recovery_code.go
44 lines (35 loc) · 1.19 KB
/
do_generate_recovery_code.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
package nodes
import (
"github.com/authgear/authgear-server/pkg/lib/interaction"
)
func init() {
interaction.RegisterNode(&NodeDoGenerateRecoveryCode{})
}
type EdgeDoGenerateRecoveryCode struct {
RecoveryCodes []string
}
func (e *EdgeDoGenerateRecoveryCode) Instantiate(ctx *interaction.Context, graph *interaction.Graph, rawInput interface{}) (interaction.Node, error) {
return &NodeDoGenerateRecoveryCode{
RecoveryCodes: e.RecoveryCodes,
}, nil
}
type NodeDoGenerateRecoveryCode struct {
RecoveryCodes []string `json:"recovery_nodes"`
}
func (n *NodeDoGenerateRecoveryCode) Prepare(ctx *interaction.Context, graph *interaction.Graph) error {
return nil
}
func (n *NodeDoGenerateRecoveryCode) GetEffects() ([]interaction.Effect, error) {
return []interaction.Effect{
interaction.EffectRun(func(ctx *interaction.Context, graph *interaction.Graph, nodeIndex int) error {
if len(n.RecoveryCodes) > 0 {
_, err := ctx.MFA.ReplaceRecoveryCodes(graph.MustGetUserID(), n.RecoveryCodes)
return err
}
return nil
}),
}, nil
}
func (n *NodeDoGenerateRecoveryCode) DeriveEdges(graph *interaction.Graph) ([]interaction.Edge, error) {
return graph.Intent.DeriveEdgesForNode(graph, n)
}