Skip to content

Commit 91e55fe

Browse files
authored
Merge pull request #73 from LoginRadius/develop
Merging to Main for 2.0.0-beta release
2 parents c94faaa + edfbaf0 commit 91e55fe

File tree

35 files changed

+617
-374
lines changed

35 files changed

+617
-374
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This project and everyone participating in it are governed by the [LoginRadius C
2020
### Reporting Bugs
2121

2222
* **Do not open up a GitHub issue if the bug is a security vulnerability
23-
in LoginRadius CLI**, and instead to refer to our [security policy](https://www.loginradius.com/security-policy).
23+
in LoginRadius CLI**, and instead refer to our [security policy](https://www.loginradius.com/security-policy).
2424

2525
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/loginradius/lr-cli/issues).
2626

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LoginRadius CLI
22

3-
`lr` is LoginRadius on the command line. You can perform basic actions of your [LoginRadius Dashboard](https://dashboard.loginradius.com/dashboard) through command line. The actions includes **login, register, logout, email configuration, domain whitelisting etc**.
3+
`lr` is LoginRadius on the command line. You can perform basic actions of your [LoginRadius Admin Console](https://adminconsole.loginradius.com/dashboard) through command line. The actions includes **login, logout, email configuration, domain whitelisting etc**.
44

55
![](./cli_home.png)
66

api/auth.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ func SitesBasic(tokens *SitesToken) error {
142142

143143
func GetAppsInfo() (map[int64]SitesReponse, error) {
144144
var Apps CoreAppData
145-
data, err := cmdutil.ReadFile("siteInfo.json")
146-
if err != nil {
145+
147146
coreAppData := conf.AdminConsoleAPIDomain + "/auth/core-app-data?"
148-
data, err = request.Rest(http.MethodGet, coreAppData, nil, "")
147+
data, err := request.Rest(http.MethodGet, coreAppData, nil, "")
149148
if err != nil {
150149
return nil, err
151150
}
@@ -154,10 +153,6 @@ func GetAppsInfo() (map[int64]SitesReponse, error) {
154153
return nil, err
155154
}
156155
return storeSiteInfo(Apps), nil
157-
}
158-
var siteInfo map[int64]SitesReponse
159-
err = json.Unmarshal(data, &siteInfo)
160-
return siteInfo, nil
161156
}
162157

163158
func CurrentID() (int64, error) {

api/deployment.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package api
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
"strings"
78

89
"net/http"
910
"time"
1011

1112
"github.com/loginradius/lr-cli/cmdutil"
13+
"github.com/loginradius/lr-cli/prompt"
1214
"github.com/loginradius/lr-cli/request"
1315
)
1416

@@ -82,16 +84,19 @@ type CoreAppData struct {
8284
}
8385

8486
func GetSites() (*SitesReponse, error) {
85-
86-
var siteInfo SitesReponse
87-
data, err := cmdutil.ReadFile("currentSite.json")
87+
var url string
88+
url = conf.AdminConsoleAPIDomain + "/deployment/sites?ownerUid=&"
89+
domainResp, err := request.Rest(http.MethodGet, url, nil, "" )
8890
if err != nil {
89-
return nil, errors.New("Please Login to execute this command")
91+
return nil, err
9092
}
91-
err = json.Unmarshal(data, &siteInfo)
93+
var siteInfo SitesReponse
94+
err = json.Unmarshal(domainResp, &siteInfo)
9295
if err != nil {
9396
return nil, err
9497
}
98+
sInfo, _ := json.Marshal(siteInfo)
99+
_ = cmdutil.WriteFile("currentSite.json", sInfo)
95100
return &siteInfo, nil
96101
}
97102

@@ -145,8 +150,8 @@ func CheckLoginMethod() error {
145150
if err != nil {
146151
return err
147152
}
148-
if res.Productplan.Name != "business" {
149-
return errors.New("This command applies to Phone login and Passwordless login which are available only with the Developer Pro plan. Kindly upgrade your plan to use this feature.")
153+
if res.Productplan != nil && res.Productplan.Name != "business" {
154+
return errors.New("this command applies to Phone login and Passwordless login which are available only with the Developer Pro plan. Kindly upgrade your plan to use this feature")
150155
}
151156
return nil
152157
}
@@ -190,13 +195,36 @@ func UpdateDomain(domains []string) error {
190195
return nil
191196
}
192197

193-
func CheckPlan() error {
198+
func CheckTrial() (bool, error) { // returns false if trial period has expired.
194199
sitesResp, err := GetSites()
195200
if err != nil {
196-
return err
201+
return false, err
197202
}
198-
if sitesResp.Productplan.Name == "free" {
199-
return errors.New("Please switch to developer/developer pro app or upgrade your plan to enable this feature.")
203+
today := time.Now()
204+
check := today.After(sitesResp.Productplan.Expirytime)
205+
if check {
206+
return false, nil
200207
}
201-
return nil
208+
return true, nil
209+
}
210+
211+
func CardPay() (bool, error) {
212+
paymentInfo, err := PaymentInfo()
213+
if err != nil {
214+
return false, err
215+
}
216+
paymentMethodId := paymentInfo.Data.Order[0].Paymentdetail.Stripepaymentmethodid
217+
if paymentMethodId == "" {
218+
fmt.Println("Please upgrade services by adding card details in dashboard via browser. ") //trial expired.
219+
fmt.Printf("Press Y to open Browser window:")
220+
var option bool
221+
prompt.Confirm("Do you want to open the browser?", &option)
222+
if !option {
223+
return false, errors.New("Action not possible without updating card details.")
224+
}
225+
cmdutil.Openbrowser(conf.DashboardDomain + "/apps")
226+
fmt.Println("Please Re-Login via CLI.")
227+
return false, nil
228+
}
229+
return true, nil
202230
}

api/platformConfiguration.go

Lines changed: 123 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ package api
33
import (
44
"encoding/json"
55
"net/http"
6-
6+
"strings"
77
"github.com/loginradius/lr-cli/request"
88
)
99

1010
// Social Provider Schemas
1111
type ActiveProvider struct {
12+
Provider string `json:"ProviderName"`
13+
Status bool `json:"Status"`
14+
}
15+
16+
type ProviderDetail struct {
1217
HtmlFileName string `json:"HtmlFileName"`
1318
Provider string `json:"Provider"`
14-
ProviderId int `json:"ProviderId"`
19+
ProviderId string `json:"ProviderId"`
1520
ProviderKey string `json:"ProviderKey"`
1621
ProviderSecret string `json:"ProviderSecret"`
1722
Scope []string `json:"Scope"`
1823
Status bool `json:"Status"`
1924
}
2025

26+
2127
type ProviderOptSchema struct {
2228
Display string `json:"display"`
2329
Name string `json:"name"`
@@ -42,6 +48,7 @@ type AddProviderObj struct {
4248
ProviderSecret string `json:"ProviderSecret"`
4349
Scope []string `json:"Scope"`
4450
Status bool `json:"status"`
51+
HtmlFileName string `json:"HtmlFileName"`
4552
}
4653

4754
type AddProviderSchema struct {
@@ -101,39 +108,67 @@ type Schema struct {
101108
Options []OptSchema `json:"Options"`
102109
Rules string `json:"Rules"`
103110
Type string `json:"Type"`
111+
Permission string `json:"Permission"`
112+
Parent string `json:"Parent"`
104113
}
105114
type OptSchema struct {
106115
Value string `json:"value"`
107116
Text string `json:"text"`
108117
}
109118

110-
type CustomFieldSchema struct {
119+
type CustomSchema struct {
111120
Key string `json:"Key"`
112121
Display string `json:"Display"`
113122
}
114123

115-
type FieldSchema struct {
116-
CustomFields []CustomFieldSchema `json:"customFields"`
117-
RegistrationFields map[string]Schema `json:"registrationFields"`
118-
}
119124
type RegistrationSchema struct {
120-
Data FieldSchema `json:"data"`
125+
Data []Schema `json:"data"`
126+
}
127+
128+
type CustomFieldSchema struct {
129+
Data []CustomSchema `json:"data"`
121130
}
131+
122132
type AddCFRespSchema struct {
123133
ResponseAddCustomField struct {
124134
Data []CustomFieldSchema `json:"Data"`
135+
ErrorCode int `json:"errorCode"`
136+
Message string `json:"message"`
137+
Description string `json:"description"`
138+
125139
} `json:"responseAddCustomField"`
126140
}
127141
type UpdateRegFieldSchema struct {
128-
Fields []Schema `json:"fields"`
142+
Data []Schema `json:"data"`
129143
}
130144

131145
type PasswordlessLogin struct {
132146
Enabled bool `json:"isEnabled"`
133147
}
134148

135-
func GetRegistrationFields() (*RegistrationSchema, error) {
136-
url := conf.AdminConsoleAPIDomain + "/platform-configuration/registration-schema"
149+
type CustomFieldLimit struct {
150+
Limit int `json:"CustomFieldLimit"`
151+
}
152+
153+
154+
func GetAllCustomFields() (*CustomFieldSchema, error) {
155+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/custom-fields?d="
156+
157+
var resultResp CustomFieldSchema
158+
resp, err := request.Rest(http.MethodGet, url, nil, "")
159+
if err != nil {
160+
return nil, err
161+
}
162+
err = json.Unmarshal(resp, &resultResp)
163+
if err != nil {
164+
return nil, err
165+
}
166+
167+
return &resultResp, nil
168+
}
169+
170+
func GetAllRegistrationFields() (map[string]Schema, error) {
171+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/platform-registration-fields?d="
137172

138173
var resultResp RegistrationSchema
139174
resp, err := request.Rest(http.MethodGet, url, nil, "")
@@ -145,14 +180,59 @@ func GetRegistrationFields() (*RegistrationSchema, error) {
145180
if err != nil {
146181
return nil, err
147182
}
183+
provMap := make(map[string]Schema, len(resultResp.Data))
184+
185+
for _ ,value := range resultResp.Data {
186+
if value.Parent == "" {
187+
provMap[strings.ToLower(value.Name)] = value
188+
}
189+
}
148190

191+
192+
return provMap, nil
193+
}
194+
195+
196+
func GetRegistrationFields() (map[string]Schema, error) {
197+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/registration-form-settings?d="
198+
199+
var resultResp RegistrationSchema
200+
resp, err := request.Rest(http.MethodGet, url, nil, "")
201+
if err != nil {
202+
return nil, err
203+
}
204+
err = json.Unmarshal(resp, &resultResp)
205+
if err != nil {
206+
return nil, err
207+
}
208+
provMap := make(map[string]Schema, len(resultResp.Data))
209+
210+
for _ ,value := range resultResp.Data {
211+
provMap[strings.ToLower(value.Name)] = value
212+
}
213+
return provMap, nil
214+
}
215+
216+
func GetCustomFieldLimit() (*CustomFieldLimit, error) {
217+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/custom-fields-limit"
218+
219+
var resultResp CustomFieldLimit
220+
resp, err := request.Rest(http.MethodGet, url, nil, "")
221+
if err != nil {
222+
return nil, err
223+
}
224+
225+
err = json.Unmarshal(resp, &resultResp)
226+
if err != nil {
227+
return nil, err
228+
}
149229
return &resultResp, nil
150230
}
151231

152232
func AddCustomField(customfield string) (*AddCFRespSchema, error) {
153233
url := conf.AdminConsoleAPIDomain + "/platform-configuration/custom-field"
154234
body, _ := json.Marshal(map[string]string{
155-
"customField": customfield,
235+
"customfield": customfield,
156236
})
157237
var resultResp AddCFRespSchema
158238
resp, err := request.Rest(http.MethodPost, url, nil, string(body))
@@ -191,7 +271,7 @@ func DeleteCustomField(field string) (*bool, error) {
191271
}
192272

193273
func UpdateRegField(data UpdateRegFieldSchema) (*RegistrationSchema, error) {
194-
url := conf.AdminConsoleAPIDomain + "/platform-configuration/registration-schema"
274+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/default-fields?d="
195275
body, _ := json.Marshal(data)
196276
var resultResp RegistrationSchema
197277
resp, err := request.Rest(http.MethodPost, url, nil, string(body))
@@ -247,7 +327,8 @@ func GetAllProviders() (map[string]ProviderSchema, error) {
247327
return provMap, nil
248328
}
249329

250-
func GetActiveProviders() (map[string]ActiveProvider, error) {
330+
331+
func GetProvidersDetail() (map[string]ProviderDetail, error) {
251332
url := conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers/options"
252333

253334
resp, err := request.Rest(http.MethodGet, url, nil, "")
@@ -256,6 +337,33 @@ func GetActiveProviders() (map[string]ActiveProvider, error) {
256337
return nil, err
257338
}
258339

340+
type ProviderDetailList struct {
341+
Data []ProviderDetail `json:"Data"`
342+
}
343+
var resultResp ProviderDetailList
344+
345+
err = json.Unmarshal(resp, &resultResp)
346+
if err != nil {
347+
return nil, err
348+
}
349+
350+
provMap := make(map[string]ProviderDetail, len(resultResp.Data))
351+
for _, val := range resultResp.Data {
352+
provMap[strings.ToLower(val.Provider)] = val
353+
}
354+
355+
return provMap , nil
356+
}
357+
358+
func GetActiveProviders() (map[string]ActiveProvider, error) {
359+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers?v="
360+
361+
resp, err := request.Rest(http.MethodGet, url, nil, "")
362+
363+
if err != nil {
364+
return nil, err
365+
}
366+
259367
type ActiveProviderList struct {
260368
Data []ActiveProvider `json:"Data"`
261369
}
@@ -267,7 +375,7 @@ func GetActiveProviders() (map[string]ActiveProvider, error) {
267375
}
268376
provMap := make(map[string]ActiveProvider, len(resultResp.Data))
269377
for _, val := range resultResp.Data {
270-
provMap[val.Provider] = val
378+
provMap[strings.ToLower(val.Provider)] = val
271379
}
272380

273381
return provMap, nil

cli_home.png

-225 KB
Loading

cmd/add/account/account.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func add(Account account) error {
9191
}
9292
fmt.Println("User Account successfully created, Please Check email to set the password")
9393
fmt.Println("Please find the user details below:")
94-
if *resultResp.FirstName != "" {
94+
95+
if Account.FirstName != "" {
9596
fmt.Println("First name: " + *resultResp.FirstName)
9697
}
9798
fmt.Println("Email: " + resultResp.Email[0].Value)

0 commit comments

Comments
 (0)