88
99 "github.com/MakeNowJust/heredoc"
1010
11- "github.com/loginradius/lr-cli/api"
1211 "github.com/loginradius/lr-cli/cmdutil"
13- "github.com/loginradius/lr-cli/config"
1412 "github.com/loginradius/lr-cli/request"
1513
1614 "github.com/spf13/cobra"
@@ -28,9 +26,10 @@ type account struct {
2826}
2927
3028type Result struct {
31- FirstName string `json:"FirstName"`
32- Uid string `json:"Uid"`
33- ID string `json:"ID"`
29+ FirstName * string `json:"FirstName"`
30+ Email []EmailVal `json:"Email"`
31+ Uid string `json:"Uid"`
32+ ID string `json:"ID"`
3433}
3534
3635func NewaccountCmd () * cobra.Command {
@@ -45,17 +44,15 @@ func NewaccountCmd() *cobra.Command {
4544 Short : "add account" ,
4645 Long : `This commmand adds account` ,
4746 Example : heredoc .Doc (`$ lr add account --name <name> --email <email>
48- User Account is successfully created
49- First name is: <first name>
50- Uid is: <uid>
51- ID is: <id>
47+ User Account successfully created
48+ First name: <first name>
49+ Email: <email>
50+ Uid: <uid>
51+ ID: <id>
5252 ` ),
5353 RunE : func (cmd * cobra.Command , args []string ) error {
5454 if opts .Email [0 ].Value == "" {
55- return & cmdutil.FlagError {Err : errors .New ("`email` is required argument" )}
56- }
57- if opts .FirstName == "" {
58- return & cmdutil.FlagError {Err : errors .New ("`name` is required argument" )}
55+ return & cmdutil.FlagError {Err : errors .New ("`email` required argument" )}
5956 }
6057 return add (* opts )
6158
@@ -65,20 +62,17 @@ func NewaccountCmd() *cobra.Command {
6562 fl := cmd .Flags ()
6663 fl .StringVarP (& opts .Email [0 ].Value , "email" , "e" , "" , "emailID" )
6764 fl .StringVarP (& opts .FirstName , "name" , "n" , "" , "first name" )
68-
65+ fl . Lookup ( "name" ). NoOptDefVal = ""
6966 return cmd
7067}
7168
7269func add (Account account ) error {
7370 Account .Password = cmdutil .GeneratePassword ()
7471
75- resObj , err := api .GetSites ()
76-
77- url := config .GetInstance ().LoginRadiusAPIDomain + "/identity/v2/manage/account?apikey=" + resObj .Key + "&apisecret=" + resObj .Secret
7872 body , _ := json .Marshal (Account )
7973
8074 var resultResp Result
81- resp , err := request .Rest (http .MethodPost , url , nil , string (body ))
75+ resp , err := request .RestLRAPI (http .MethodPost , "/identity/v2/manage/account" , nil , string (body ))
8276
8377 if err != nil {
8478 return err
@@ -87,9 +81,21 @@ func add(Account account) error {
8781 if err != nil {
8882 return err
8983 }
90- fmt .Println ("User Account is successfully created" )
91- fmt .Println ("First name is:" + resultResp .FirstName )
92- fmt .Println ("Uid is:" + resultResp .Uid )
93- fmt .Println ("ID is:" + resultResp .ID )
84+
85+ body , _ = json .Marshal (map [string ]string {
86+ "email" : resultResp .Email [0 ].Value ,
87+ })
88+ _ , err = request .RestLRAPI (http .MethodPost , "/identity/v2/manage/account/forgot/token?SendEmail=true" , nil , string (body ))
89+ if err != nil {
90+ return err
91+ }
92+ fmt .Println ("User Account successfully created, Please Check email to set the password" )
93+ fmt .Println ("Please find the user details below:" )
94+ if * resultResp .FirstName != "" {
95+ fmt .Println ("First name: " + * resultResp .FirstName )
96+ }
97+ fmt .Println ("Email: " + resultResp .Email [0 ].Value )
98+ fmt .Println ("Uid: " + resultResp .Uid )
99+ fmt .Println ("ID: " + resultResp .ID )
94100 return nil
95101}
0 commit comments