-
Notifications
You must be signed in to change notification settings - Fork 27
/
forgot_password_link_sent.go
86 lines (69 loc) · 2.74 KB
/
forgot_password_link_sent.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package authflowv2
import (
"net/http"
handlerwebapp "github.com/authgear/authgear-server/pkg/auth/handler/webapp"
"github.com/authgear/authgear-server/pkg/auth/handler/webapp/viewmodels"
"github.com/authgear/authgear-server/pkg/auth/webapp"
"github.com/authgear/authgear-server/pkg/lib/authenticationflow/declarative"
"github.com/authgear/authgear-server/pkg/util/clock"
"github.com/authgear/authgear-server/pkg/util/httproute"
"github.com/authgear/authgear-server/pkg/util/template"
)
var TemplateWebAuthflowV2ForgotPasswordLinkSentHTML = template.RegisterHTML(
"web/authflowv2/forgot_password_link_sent.html",
handlerwebapp.Components...,
)
func ConfigureAuthflowV2ForgotPasswordLinkSentRoute(route httproute.Route) httproute.Route {
return route.
WithMethods("OPTIONS", "GET", "POST").
WithPathPattern(AuthflowV2RouteForgotPasswordLinkSent)
}
type AuthflowV2ForgotPasswordLinkSentViewModel struct {
MaskedDisplayName string
ResendCooldown int
}
type AuthflowV2ForgotPasswordLinkSentHandler struct {
Controller *handlerwebapp.AuthflowController
BaseViewModel *viewmodels.BaseViewModeler
Renderer handlerwebapp.Renderer
Clock clock.Clock
}
func (h *AuthflowV2ForgotPasswordLinkSentHandler) GetData(w http.ResponseWriter, r *http.Request, s *webapp.Session, screen *webapp.AuthflowScreenWithFlowResponse) (map[string]interface{}, error) {
data := make(map[string]interface{})
now := h.Clock.NowUTC()
screenData, ok := screen.StateTokenFlowResponse.Action.
Data.(declarative.IntentAccountRecoveryFlowStepVerifyAccountRecoveryCodeData)
if !ok {
panic("unexpected data type in forgot password link sent screen")
}
baseViewModel := h.BaseViewModel.ViewModelForAuthFlow(r, w)
viewmodels.Embed(data, baseViewModel)
linkSendViewModel := &AuthflowV2ForgotPasswordLinkSentViewModel{
MaskedDisplayName: screenData.MaskedDisplayName,
ResendCooldown: int(screenData.CanResendAt.Sub(now).Seconds()),
}
viewmodels.Embed(data, linkSendViewModel)
return data, nil
}
func (h *AuthflowV2ForgotPasswordLinkSentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var handlers handlerwebapp.AuthflowControllerHandlers
handlers.Get(func(s *webapp.Session, screen *webapp.AuthflowScreenWithFlowResponse) error {
data, err := h.GetData(w, r, s, screen)
if err != nil {
return err
}
h.Renderer.RenderHTML(w, r, TemplateWebAuthflowV2ForgotPasswordLinkSentHTML, data)
return nil
})
handlers.PostAction("resend", func(s *webapp.Session, screen *webapp.AuthflowScreenWithFlowResponse) error {
result, err := h.Controller.AdvanceWithInput(r, s, screen, map[string]interface{}{
"resend": true,
}, nil)
if err != nil {
return err
}
result.WriteResponse(w, r)
return nil
})
h.Controller.HandleStep(w, r, &handlers)
}