@@ -2,13 +2,9 @@ package cli
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
- "fmt"
7
- "sort"
5
+ "io"
8
6
9
- "github.com/NordSecurity/nordvpn-linux/client"
10
7
"github.com/NordSecurity/nordvpn-linux/daemon/pb"
11
- "github.com/NordSecurity/nordvpn-linux/internal"
12
8
13
9
"github.com/fatih/color"
14
10
"github.com/urfave/cli/v2"
@@ -18,57 +14,28 @@ import (
18
14
const RegisterUsageText = "Registers a new user account"
19
15
20
16
func (c * cmd ) Register (ctx * cli.Context ) error {
21
- email , password , err := ReadCredentialsFromTerminal ()
17
+ cl , err := c .client .LoginOAuth2 (
18
+ context .Background (),
19
+ & pb.LoginOAuth2Request {
20
+ Type : pb .LoginType_LoginType_SIGNUP ,
21
+ },
22
+ )
22
23
if err != nil {
23
24
return formatError (err )
24
25
}
25
26
26
- resp , err := c .client .Register (context .Background (), & pb.RegisterRequest {
27
- Email : email ,
28
- Password : password ,
29
- })
30
- if err != nil {
31
- return formatError (err )
32
- }
33
-
34
- switch resp .Type {
35
- case internal .CodeSuccess :
36
- color .Green (AccountCreationSuccess )
37
- case internal .CodeBadRequest :
38
- err = errors .New (AccountInvalidData )
39
- case internal .CodeConflict :
40
- err = errors .New (AccountEmailTaken )
41
- case internal .CodeInternalError :
42
- err = errors .New (AccountInternalError )
43
- case internal .CodeFailure :
44
- err = internal .ErrUnhandled
45
- }
46
-
47
- if err != nil {
48
- return formatError (err )
49
- }
50
-
51
- planResp , err := c .client .Plans (context .Background (), & pb.Empty {})
52
- if err != nil {
53
- color .Red ("Failed to retrieve subscription plans. Please finish the registration in NordVPN website." )
54
- return browse (client .SubscriptionURL )
55
- }
56
-
57
- plans := planResp .GetPlans ()
58
- // sort plans by cost in ascending order
59
- sort .Slice (plans , func (i , j int ) bool {
60
- costI := plans [i ].GetCost ()
61
- costJ := plans [j ].GetCost ()
62
- // this is done to avoid string -> int conversions
63
- if len (costI ) == len (costJ ) {
64
- return costI < costJ
27
+ for {
28
+ resp , err := cl .Recv ()
29
+ if err != nil {
30
+ if err == io .EOF {
31
+ break
32
+ }
33
+ return formatError (err )
34
+ }
35
+ if url := resp .GetData (); url != "" {
36
+ color .Green ("Continue in the browser: %s" , url )
65
37
}
66
- return len (costI ) < len (costJ )
67
- })
68
- for i , plan := range plans {
69
- description := fmt .Sprintf ("%s for %s %s" , plan .GetTitle (), plan .GetCost (), plan .GetCurrency ())
70
- fmt .Printf ("%d) %s\n " , i + 1 , description )
71
38
}
72
39
73
- return browse ( client . SubscriptionURL )
40
+ return nil
74
41
}
0 commit comments