master
Evan Chen 2021-12-17 16:22:04 +08:00
parent 977436d334
commit 44f1c38811
3 changed files with 39 additions and 6 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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"),