/
change_password.go
50 lines (41 loc) · 1.17 KB
/
change_password.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
package viewmodels
import (
"github.com/authgear/authgear-server/pkg/lib/authenticationflow/declarative"
"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/interaction"
)
type ChangePasswordGetter interface {
GetChangeReason() *interaction.AuthenticatorUpdateReason
}
type ChangePasswordViewModel struct {
Force bool
Reason string
}
type ChangePasswordViewModeler struct {
Authentication *config.AuthenticationConfig
LoginID *config.LoginIDConfig
}
func (m *ChangePasswordViewModeler) NewWithGraph(graph *interaction.Graph) ChangePasswordViewModel {
var node ChangePasswordGetter
if !graph.FindLastNode(&node) {
panic("webapp: no node with password change reason found")
}
var reason string
if node.GetChangeReason() != nil {
reason = string(*node.GetChangeReason())
}
return ChangePasswordViewModel{
Force: true,
Reason: reason,
}
}
func (m *ChangePasswordViewModeler) NewWithAuthflow(reason *declarative.PasswordChangeReason) ChangePasswordViewModel {
var reasonStr string
if reason != nil {
reasonStr = string(*reason)
}
return ChangePasswordViewModel{
Force: true,
Reason: reasonStr,
}
}