From 44f1c38811283ca27eb817703b2cdefb090a859b Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Fri, 17 Dec 2021 16:22:04 +0800 Subject: [PATCH] update --- control/service.go | 27 ++++++++++++++++++++++++++- email/email.go | 17 ++++++++++++----- email/service.go | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/control/service.go b/control/service.go index 0c26600..6a12e5c 100644 --- a/control/service.go +++ b/control/service.go @@ -2,9 +2,12 @@ package control import ( "encoding/json" + "strings" "github.com/gin-gonic/gin" "kumoly.io/kumoly/app/auth" + "kumoly.io/kumoly/app/email" + "kumoly.io/kumoly/app/errors" "kumoly.io/kumoly/app/server" "kumoly.io/kumoly/app/system" "kumoly.io/kumoly/app/task" @@ -31,14 +34,36 @@ func (srv Service) Load() error { panic(err) } data := map[string]interface{}{} - if err := json.Unmarshal([]byte(conf), data); err != nil { + if err := json.Unmarshal([]byte(conf), &data); err != nil { panic(err) } server.OK(c, data) }) + ctlAPI.GET("test_email", auth.ACAdmin(), func(c *gin.Context) { + tos := c.Query("to") + if tos == "" { + panic(errors.ErrorBadRequest) + } + to := strings.Split(tos, ",") + if err := email.Send("test@kumoly.io", to, "Test Email", &email.Body{ + Greeting: "Dear", + Receiver: "Administrator", + Intros: []string{ + "This is a test email.", + }, + }); err != nil { + panic(err) + } + server.OK(c, "email sent.") + }) + + // this should be in task service ctlAPI.GET("tasks", auth.ACAdmin(), func(c *gin.Context) { server.OK(c, task.GetProfile()) }) + ctlAPI.GET("task", auth.ACAdmin(), func(c *gin.Context) { + server.OK(c, task.GetTasks()) + }) return nil } diff --git a/email/email.go b/email/email.go index b8c7e17..e393c96 100644 --- a/email/email.go +++ b/email/email.go @@ -11,6 +11,7 @@ func init() { viper.SetDefault("email.port", 587) viper.SetDefault("email.username", "test@kumoly.io") viper.SetDefault("email.password", "test") + viper.SetDefault("logo", "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png") } type App struct { @@ -21,16 +22,22 @@ type App struct { } type Body struct { - App App - Intros []string - Outros []string - Content string + // App replaced with global config + App App + Intros []string + Content string + Outros []string + + // Greeting ignored if empty Greeting string + // Receiver ignored if Greeting or Receiver empty Receiver string + // Signature default `Best Regards` Signature string - Sender string + // Sender default {{.App.Name}} + Sender string } // host string, port int, username string, password string diff --git a/email/service.go b/email/service.go index 6c07d89..3770d84 100644 --- a/email/service.go +++ b/email/service.go @@ -20,6 +20,7 @@ func (srv *Service) Init() error { app.Copyright = fmt.Sprintf("Copyright © %v %s. All rights reserved.", time.Now().Year(), app.Name) app.Link = viper.GetString("server.url") + app.Logo = viper.GetString("logo") dial = gomail.NewDialer( viper.GetString("email.host"),