This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
account_email_verify.go
62 lines (49 loc) · 1.9 KB
/
account_email_verify.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
package secrethub
import (
"fmt"
"github.com/secrethub/secrethub-cli/internals/cli"
"github.com/secrethub/secrethub-cli/internals/cli/ui"
)
// AccountEmailVerifyCommand is a command to inspect account details.
type AccountEmailVerifyCommand struct {
io ui.IO
newClient newClientFunc
}
// NewAccountEmailVerifyCommand creates a new AccountEmailVerifyCommand.
func NewAccountEmailVerifyCommand(io ui.IO, newClient newClientFunc) *AccountEmailVerifyCommand {
return &AccountEmailVerifyCommand{
io: io,
newClient: newClient,
}
}
// Register registers the command, arguments and flags on the provided Registerer.
func (cmd *AccountEmailVerifyCommand) Register(r cli.Registerer) {
clause := r.Command("verify-email", "Resend verification email to the registered email address.")
clause.HelpLong("When you create your account, a verification email is automatically sent to the email address you used to sign up. " +
"In case anything goes wrong (e.g. the email ended up in your junk folder), this command lets you resend the verification email. " +
"Once received, click the link in the verification email to verify your email address.")
clause.BindAction(cmd.Run)
clause.BindArguments(nil)
}
// Run handles the command with the options as specified in the command.
func (cmd *AccountEmailVerifyCommand) Run() error {
client, err := cmd.newClient()
if err != nil {
return err
}
user, err := client.Me().GetUser()
if err != nil {
return err
}
if user.EmailVerified {
fmt.Fprintln(cmd.io.Output(), "Your email address is already verified.")
return nil
}
err = client.Me().SendVerificationEmail()
if err != nil {
return err
}
fmt.Fprintf(cmd.io.Output(), "An email has been sent to %s with an email verification link. Please check your mail and click the link.\n\n", user.Email)
fmt.Fprintf(cmd.io.Output(), "Please contact support@secrethub.io if the problem persists.\n\n")
return nil
}