Browse Source

SMTP config form in settings, config struct

Vova Tkach 5 years ago
parent
commit
0418a93832
2 changed files with 61 additions and 0 deletions
  1. 11 0
      engine/wrapper/config/config.go
  2. 50 0
      modules/module_settings.go

+ 11 - 0
engine/wrapper/config/config.go

@@ -36,6 +36,12 @@ type Config struct {
 			Url     string
 		}
 	}
+	SMTP struct {
+		Host     string
+		Port     int
+		Login    string
+		Password string
+	}
 }
 
 func ConfigNew() *Config {
@@ -77,6 +83,11 @@ func (this *Config) configDefault() {
 	this.API.XML.Name = ""
 	this.API.XML.Company = ""
 	this.API.XML.Url = ""
+
+	this.SMTP.Host = ""
+	this.SMTP.Port = 587
+	this.SMTP.Login = ""
+	this.SMTP.Password = ""
 }
 
 func (this *Config) ConfigRead(file string) error {

+ 50 - 0
modules/module_settings.go

@@ -25,6 +25,7 @@ func (this *Modules) RegisterModule_Settings() *Module {
 			{Mount: "robots-txt", Name: "Robots.txt", Show: true, Icon: assets.SysSvgIconBug},
 			{Mount: "pagination", Name: "Pagination", Show: true, Icon: assets.SysSvgIconPagination},
 			{Mount: "thumbnails", Name: "Thumbnails", Show: true, Icon: assets.SysSvgIconThumbnails},
+			{Mount: "smtp", Name: "SMTP", Show: true, Icon: assets.SysSvgIconEmail},
 			{Mount: "api", Name: "API", Show: true, Icon: assets.SysSvgIconApi},
 		},
 	}, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
@@ -384,6 +385,55 @@ func (this *Modules) RegisterModule_Settings() *Module {
 				},
 			})
 
+			sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
+		} else if wrap.CurrSubModule == "smtp" {
+			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
+				{Name: "SMTP"},
+			})
+
+			content += builder.DataForm(wrap, []builder.DataFormField{
+				{
+					Kind:  builder.DFKHidden,
+					Name:  "action",
+					Value: "settings-smtp",
+				},
+				{
+					Kind:    builder.DFKText,
+					Caption: "SMTP server host",
+					Name:    "smtp-host",
+					Value:   (*wrap.Config).SMTP.Host,
+					Hint:    "Example: smtp.gmail.com",
+				},
+				{
+					Kind:     builder.DFKNumber,
+					Caption:  "SMTP server port",
+					Name:     "smtp-port",
+					Min:      "0",
+					Max:      "9999",
+					Required: true,
+					Value:    utils.IntToStr((*wrap.Config).SMTP.Port),
+					Hint:     "Example: 587",
+				},
+				{
+					Kind:    builder.DFKText,
+					Caption: "SMTP user login",
+					Name:    "smtp-login",
+					Value:   (*wrap.Config).SMTP.Login,
+					Hint:    "Example: example@gmail.com",
+				},
+				{
+					Kind:    builder.DFKText,
+					Caption: "SMTP user password",
+					Name:    "smtp-password",
+					Value:   (*wrap.Config).SMTP.Password,
+				},
+				{
+					Kind:   builder.DFKSubmit,
+					Value:  "Save",
+					Target: "add-edit-button",
+				},
+			})
+
 			sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
 		} else if wrap.CurrSubModule == "api" {
 			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{