2017-04-30 22:02:49 +00:00
|
|
|
package manage
|
2017-04-28 03:54:46 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-16 09:58:33 +00:00
|
|
|
"encoding/json"
|
2018-01-30 11:26:04 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
"github.com/ouqiang/gocron/models"
|
|
|
|
"github.com/ouqiang/gocron/modules/logger"
|
|
|
|
"github.com/ouqiang/gocron/modules/utils"
|
|
|
|
"gopkg.in/macaron.v1"
|
2017-04-28 03:54:46 +00:00
|
|
|
)
|
|
|
|
|
2017-04-30 17:12:07 +00:00
|
|
|
// region slack
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func EditSlack(ctx *macaron.Context) {
|
|
|
|
ctx.Data["Title"] = "Slack配置"
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
slack, err := settingModel.Slack()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
|
|
|
ctx.Data["Slack"] = slack
|
|
|
|
ctx.HTML(200, "manage/slack")
|
2017-04-28 03:54:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 17:12:07 +00:00
|
|
|
func Slack(ctx *macaron.Context) string {
|
2017-09-16 09:58:33 +00:00
|
|
|
settingModel := new(models.Setting)
|
|
|
|
slack, err := settingModel.Slack()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
|
|
|
json := utils.JsonResponse{}
|
|
|
|
|
|
|
|
return json.Success("", slack)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateSlackUrl(ctx *macaron.Context) string {
|
2017-09-16 09:58:33 +00:00
|
|
|
url := ctx.QueryTrim("url")
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
_, err := settingModel.UpdateSlackUrl(url)
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func CreateSlackChannel(ctx *macaron.Context) string {
|
|
|
|
channel := ctx.QueryTrim("channel")
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
if settingModel.IsChannelExist(channel) {
|
|
|
|
json := utils.JsonResponse{}
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return json.CommonFailure("Channel已存在")
|
|
|
|
}
|
|
|
|
_, err := settingModel.CreateChannel(channel)
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func RemoveSlackChannel(ctx *macaron.Context) string {
|
|
|
|
id := ctx.ParamsInt(":id")
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
_, err := settingModel.RemoveChannel(id)
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region 邮件
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func EditMail(ctx *macaron.Context) {
|
|
|
|
ctx.Data["Title"] = "邮件配置"
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
mail, err := settingModel.Mail()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
|
|
|
ctx.Data["Mail"] = mail
|
|
|
|
ctx.HTML(200, "manage/mail")
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Mail(ctx *macaron.Context) string {
|
2017-09-16 09:58:33 +00:00
|
|
|
settingModel := new(models.Setting)
|
|
|
|
mail, err := settingModel.Mail()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
json := utils.JsonResponse{}
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return json.Success("", mail)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type MailServerForm struct {
|
2017-09-16 09:58:33 +00:00
|
|
|
Host string `binding:"Required;MaxSize(100)"`
|
|
|
|
Port int `binding:"Required;Range(1-65535)"`
|
|
|
|
User string `binding:"Required;MaxSize(64);Email"`
|
|
|
|
Password string `binding:"Required;MaxSize(64)"`
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateMailServer(ctx *macaron.Context, form MailServerForm) string {
|
2017-09-16 09:58:33 +00:00
|
|
|
jsonByte, _ := json.Marshal(form)
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
_, err := settingModel.UpdateMailServer(string(jsonByte))
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 02:42:03 +00:00
|
|
|
func ClearMailServer(ctx *macaron.Context) string {
|
2017-09-16 09:58:33 +00:00
|
|
|
jsonByte, _ := json.Marshal(MailServerForm{})
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
_, err := settingModel.UpdateMailServer(string(jsonByte))
|
2017-05-12 02:42:03 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-05-12 02:42:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func CreateMailUser(ctx *macaron.Context) string {
|
|
|
|
username := ctx.QueryTrim("username")
|
|
|
|
email := ctx.QueryTrim("email")
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
if username == "" || email == "" {
|
|
|
|
json := utils.JsonResponse{}
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return json.CommonFailure("用户名、邮箱均不能为空")
|
|
|
|
}
|
|
|
|
_, err := settingModel.CreateMailUser(username, email)
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
func RemoveMailUser(ctx *macaron.Context) string {
|
|
|
|
id := ctx.ParamsInt(":id")
|
|
|
|
settingModel := new(models.Setting)
|
|
|
|
_, err := settingModel.RemoveMailUser(id)
|
2017-04-30 17:12:07 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
return utils.JsonResponseByErr(err)
|
2017-04-30 17:12:07 +00:00
|
|
|
}
|
2017-04-28 03:54:46 +00:00
|
|
|
|
2017-09-16 09:58:33 +00:00
|
|
|
// endregion
|