Skip to content

Commit 955c991

Browse files
committed
Updated content and all other changes
1 parent cbbcbb3 commit 955c991

14 files changed

Lines changed: 92 additions & 483 deletions

File tree

api/securityConfiguration.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@ type ResetResponse struct {
1414
XToken string `json:"xtoken"`
1515
}
1616

17-
type EmailResponse struct {
18-
Domains []string `json:"Domains"`
19-
ListType string `json:"ListType"`
20-
RegistrationType string `json:"RegistrationType"`
21-
}
22-
23-
type RegistrationRestrictionTypeSchema struct {
24-
SelectedRestrictionType string `json:"selectedRestrictionType"`
25-
}
26-
27-
type EmailWhiteBLackListSchema struct {
28-
Domains []string `json:"Domains"`
29-
}
30-
3117
func ResetSecret() error {
3218

3319
// Restting the Secret
@@ -72,41 +58,4 @@ func ResetSecret() error {
7258
_ = cmdutil.WriteFile("token.json", lInfo)
7359
return nil
7460

75-
}
76-
77-
func GetEmailWhiteListBlackList() (*EmailResponse, error) {
78-
79-
url := conf.AdminConsoleAPIDomain + "/security-configuration/restriction/config?"
80-
resp, err := request.Rest(http.MethodGet, url, nil, "")
81-
if err != nil {
82-
return nil, err
83-
}
84-
var resObj EmailResponse
85-
err = json.Unmarshal(resp, &resObj)
86-
if err != nil {
87-
return nil, err
88-
}
89-
return &resObj, nil
90-
91-
}
92-
93-
func AddEmailWhitelistBlacklist(restrictionType RegistrationRestrictionTypeSchema, data EmailWhiteBLackListSchema) error {
94-
typeUrl := conf.AdminConsoleAPIDomain + "/security-configuration/restriction/type?"
95-
body, _ := json.Marshal(restrictionType)
96-
_, err := request.Rest(http.MethodPut, typeUrl, nil, string(body))
97-
98-
if err != nil {
99-
return err
100-
}
101-
102-
if restrictionType.SelectedRestrictionType != "none" {
103-
domainUrl := conf.AdminConsoleAPIDomain + "/security-configuration/restriction/config?"
104-
body, _ := json.Marshal(data)
105-
_, err := request.Rest(http.MethodPost, domainUrl, nil, string(body))
106-
107-
if err != nil {
108-
return err
109-
}
110-
}
111-
return nil
11261
}

cmd/add/accessRestriction/accessRestriction.go

Lines changed: 0 additions & 114 deletions
This file was deleted.

cmd/add/add.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/loginradius/lr-cli/cmd/add/hooks"
1010
"github.com/loginradius/lr-cli/cmd/add/social"
11-
"github.com/loginradius/lr-cli/cmd/add/accessRestriction"
1211
"github.com/loginradius/lr-cli/cmd/add/smtpConfiguration"
1312

1413
"github.com/spf13/cobra"
@@ -46,8 +45,6 @@ func NewaddCmd() *cobra.Command {
4645
customFieldsCmd := customField.NewAddCFCmd()
4746
cmd.AddCommand(customFieldsCmd)
4847

49-
accessRestrictionCmd := accessRestriction.NewaccessRestrictionCmd()
50-
cmd.AddCommand(accessRestrictionCmd)
5148

5249
smtpConfigurationCmd := smtpConfiguration.NewsmtpConfigurationCmd()
5350
cmd.AddCommand(smtpConfigurationCmd)

cmd/add/smtpConfiguration/smtpConfiguration.go

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@ func NewsmtpConfigurationCmd() *cobra.Command {
2828
Use: "smtp-configuration",
2929
Short: "Add a SMTP configuration",
3030
Long: `Configure your SMTP email settings to allow LoginRadius to send email from your email server automatically.`,
31-
Example: heredoc.Doc(`$ lr add smtp-configuration
32-
SMTP Providers : <Provider>
33-
(If you dont have mailazy account. Please Create a mailazy account via https://app.mailazy.com/signup)(only for mailazy)
34-
? Key: dgfdfg? Key: <Key>(only for mailazy)
35-
? Secret: <Secret>(only for mailazy)
36-
? From Name: <Name>
37-
? From Email Id: <Email ID>
38-
39-
? SMTP User Name: <User name>(not for mailazy)
40-
? SMTP Password: <Password>(not for mailazy)
41-
? Enable SSL(Y/N): Yes(not for mailazy)
42-
43-
SMTP settings saved
44-
? Configure and send an email to verify your configuration settings are correct (Y/N): Yes
45-
? To Email : <Email ID for Verification>
46-
SMTP settings are verified
31+
Example: heredoc.Doc(`
32+
$ lr add smtp-configuration
33+
SMTP Providers: Mailazy
34+
If you don't have a mailazy account. Please Create a mailazy account via https://app.mailazy.com/signup
35+
? Key: <Key>
36+
? Secret: <Secret>
37+
? From Name: <Name>
38+
? From Email Id: <Email ID>
39+
40+
SMTP settings are saved
41+
42+
? Send an email to verify your configuration settings are correct (Y/N): Yes
43+
? To Email: <Email ID for Verification>
44+
SMTP settings are verified
4745
`),
4846
RunE: func(cmd *cobra.Command, args []string) error {
4947
return addAccessRestriction()
@@ -61,9 +59,9 @@ func addAccessRestriction() error {
6159
var num int
6260
var isSsl bool
6361
var isMailazy bool
64-
num = len(cmdutil.SMTP_PROVIDERS)
62+
num = len(cmdutil.SmtpProviders)
6563
for i := 0; i < num; i++ {
66-
smtpProviders = append(smtpProviders, cmdutil.SMTP_PROVIDERS[i].Name)
64+
smtpProviders = append(smtpProviders, cmdutil.SmtpProviders[i].Name)
6765
}
6866
for _,val := range smtpLabels {
6967

@@ -76,8 +74,8 @@ func addAccessRestriction() error {
7674
return err
7775
}
7876
} else if val == "IsSsl" && num != 0 {
79-
isSsl = cmdutil.SMTP_PROVIDERS[num].EnableSSL
80-
if err := prompt.Confirm(cmdutil.SmtpOptionNames[val] + "(Y/N):",
77+
isSsl = cmdutil.SmtpProviders[num].EnableSSL
78+
if err := prompt.Confirm(cmdutil.SmtpOptionNames[val] + ":",
8179
&isSsl); err != nil {
8280
return err
8381
}
@@ -95,7 +93,7 @@ func addAccessRestriction() error {
9593
var promptRes string
9694

9795
if val == "Key" {
98-
fmt.Println("(If you dont have mailazy account. Please Create a mailazy account via https://app.mailazy.com/signup)")
96+
fmt.Println("(If you don't have a mailazy account. Please Create a mailazy account via https://app.mailazy.com/signup)")
9997
}
10098
prompt.SurveyAskOne(&survey.Input{
10199
Message: cmdutil.SmtpOptionNames[val] + ":",
@@ -105,12 +103,12 @@ func addAccessRestriction() error {
105103
return errors.New(cmdutil.SmtpOptionNames[val] + " is required")
106104
}
107105
if val == "FromEmailId" && !cmdutil.ValidateEmail.MatchString(promptRes) {
108-
return &cmdutil.FlagError{Err: errors.New("Email has invalid format.")}
106+
return &cmdutil.FlagError{Err: errors.New("Invalid email format")}
109107
}
110108
if val == "SmtpPort" {
111109
smtpPort, err := strconv.ParseInt(promptRes, 10, 64)
112110
if err != nil {
113-
return &cmdutil.FlagError{Err: errors.New("Please enter valid SMTP Port")}
111+
return &cmdutil.FlagError{Err: errors.New("Please enter the valid SMTP Port")}
114112
}
115113
field.SetInt(smtpPort)
116114
} else {
@@ -134,12 +132,12 @@ func addAccessRestriction() error {
134132
}
135133
smtpSchema.UserName = smtpSchema.Key
136134
smtpSchema.Password = smtpSchema.Secret
137-
smtpSchema.IsSsl = cmdutil.SMTP_PROVIDERS[num].EnableSSL
135+
smtpSchema.IsSsl = cmdutil.SmtpProviders[num].EnableSSL
138136

139137
} else if num != 9 {
140138
var err error
141-
smtpSchema.SmtpHost = cmdutil.SMTP_PROVIDERS[num].SmtpHost
142-
smtpSchema.SmtpPort,err = strconv.Atoi(cmdutil.SMTP_PROVIDERS[num].SmtpPort)
139+
smtpSchema.SmtpHost = cmdutil.SmtpProviders[num].SmtpHost
140+
smtpSchema.SmtpPort,err = strconv.Atoi(cmdutil.SmtpProviders[num].SmtpPort)
143141
if err != nil {
144142
return err
145143
}
@@ -149,10 +147,10 @@ func addAccessRestriction() error {
149147
if err != nil {
150148
return err
151149
}
152-
fmt.Println("SMTP settings saved")
150+
fmt.Println("SMTP settings are saved")
153151
var verify bool
154152

155-
if err := prompt.Confirm("Configure and send an email to verify your configuration settings are correct (Y/N):",
153+
if err := prompt.Confirm("Send an email to verify your configuration settings are correct?",
156154
&verify); err != nil {
157155
return err
158156
}
@@ -165,6 +163,10 @@ func addAccessRestriction() error {
165163
prompt.SurveyAskOne(&survey.Input{
166164
Message: "To Email :",
167165
}, &emailid, survey.WithValidator(survey.Required))
166+
167+
if !cmdutil.ValidateEmail.MatchString(emailid) {
168+
return &cmdutil.FlagError{Err: errors.New("Invalid email format")}
169+
}
168170

169171
var respMap map[string]string
170172
data, _ := json.Marshal(smtpSchema)
@@ -182,9 +184,12 @@ func addAccessRestriction() error {
182184
verifySchema.Message = "This is the test email to validate your SMTP credentials for LoginRadius' User Registration feature on your website. <br><br>The SMTP server credentials are verified.<br><br>Thank you,<br>LoginRadius Team"
183185
verifySchema.Subject = "Test Email - LoginRadius"
184186
verifySchema.SmtpPort = smtpSchema.SmtpPort
187+
verifySchema.IsSsl = smtpSchema.IsSsl
188+
185189
err = api.VerifySMTPConfiguration(verifySchema)
186190
if err != nil {
187-
return err
191+
fmt.Println("Error: " + strings.Replace(err.Error(), "Learn more at", "", 1))
192+
return nil
188193
}
189194
fmt.Println("SMTP settings are verified")
190195

0 commit comments

Comments
 (0)