MCPcopy
hub / github.com/tinyauthapp/tinyauth / verifyUserCmd

Function verifyUserCmd

cmd/tinyauth/verify_user.go:34–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34func verifyUserCmd() *cli.Command {
35 tCfg := NewVerifyUserConfig()
36
37 loaders := []cli.ResourceLoader{
38 &cli.FlagLoader{},
39 }
40
41 return &cli.Command{
42 Name: "verify",
43 Description: "Verify a user is set up correctly",
44 Configuration: tCfg,
45 Resources: loaders,
46 Run: func(_ []string) error {
47 tlog.NewSimpleLogger().Init()
48
49 if tCfg.Interactive {
50 form := huh.NewForm(
51 huh.NewGroup(
52 huh.NewInput().Title("User (username:hash:totp)").Value(&tCfg.User).Validate((func(s string) error {
53 if s == "" {
54 return errors.New("user cannot be empty")
55 }
56 return nil
57 })),
58 huh.NewInput().Title("Username").Value(&tCfg.Username).Validate((func(s string) error {
59 if s == "" {
60 return errors.New("username cannot be empty")
61 }
62 return nil
63 })),
64 huh.NewInput().Title("Password").Value(&tCfg.Password).Validate((func(s string) error {
65 if s == "" {
66 return errors.New("password cannot be empty")
67 }
68 return nil
69 })),
70 huh.NewInput().Title("TOTP Code (optional)").Value(&tCfg.Totp),
71 ),
72 )
73
74 theme := new(themeBase)
75 err := form.WithTheme(theme).Run()
76
77 if err != nil {
78 return fmt.Errorf("failed to run interactive prompt: %w", err)
79 }
80 }
81
82 user, err := utils.ParseUser(tCfg.User)
83
84 if err != nil {
85 return fmt.Errorf("failed to parse user: %w", err)
86 }
87
88 if user.Username != tCfg.Username {
89 return fmt.Errorf("username is incorrect")
90 }
91

Callers 1

mainFunction · 0.85

Calls 4

NewSimpleLoggerFunction · 0.92
ParseUserFunction · 0.92
NewVerifyUserConfigFunction · 0.85
InitMethod · 0.45

Tested by

no test coverage detected