-
Notifications
You must be signed in to change notification settings - Fork 32
/
verify.go
58 lines (49 loc) · 1.18 KB
/
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
package cmd
import (
"context"
"fmt"
"strings"
"github.com/urfave/cli"
"github.com/arigatomachine/cli/api"
"github.com/arigatomachine/cli/config"
)
func init() {
version := cli.Command{
Name: "verify",
ArgsUsage: "<code>",
Usage: "Verify the email address for your account",
Category: "ACCOUNT",
Action: chain(
ensureDaemon, ensureSession, verifyEmailCmd,
),
}
Cmds = append(Cmds, version)
}
func verifyEmailCmd(ctx *cli.Context) error {
cfg, err := config.LoadConfig()
if err != nil {
return err
}
client := api.NewClient(cfg)
c := context.Background()
args := ctx.Args()
if len(args) > 1 {
text := "Too many arguments.\n\n"
text += usageString(ctx)
return cli.NewExitError(text, -1)
}
if len(args) != 1 {
text := "Missing verification code.\n\n"
text += usageString(ctx)
return cli.NewExitError(text, -1)
}
err = client.Users.VerifyEmail(c, args[0])
if err != nil {
if strings.Contains(err.Error(), "wrong user state: active") {
return cli.NewExitError("Email already verified :)", -1)
}
return cli.NewExitError("Email verification failed, please try again.", -1)
}
fmt.Println("Your account is now verified.")
return nil
}