diff --git a/backend/model/user.go b/backend/model/user.go index 246fa448..3e24e096 100644 --- a/backend/model/user.go +++ b/backend/model/user.go @@ -25,6 +25,8 @@ type User struct { type UserSetting struct { NotificationTrigger string `json:"notification_trigger" bson:"notification_trigger"` + DingTalkAppKey string `json:"ding_talk_app_key" bson:"ding_talk_app_key"` + DingTalkAppSecret string `json:"ding_talk_app_secret" bson:"ding_talk_app_secret"` } func (user *User) Save() error { diff --git a/backend/routes/user.go b/backend/routes/user.go index 8aae8b24..9afddffc 100644 --- a/backend/routes/user.go +++ b/backend/routes/user.go @@ -216,6 +216,8 @@ func PostMe(c *gin.Context) { Email string `json:"email"` Password string `json:"password"` NotificationTrigger string `json:"notification_trigger"` + DingTalkAppKey string `json:"ding_talk_app_key"` + DingTalkAppSecret string `json:"ding_talk_app_secret"` } ctx := context.WithGinContext(c) user := ctx.User() @@ -237,6 +239,12 @@ func PostMe(c *gin.Context) { if reqBody.NotificationTrigger != "" { user.Setting.NotificationTrigger = reqBody.NotificationTrigger } + if reqBody.DingTalkAppKey != "" { + user.Setting.DingTalkAppKey = reqBody.DingTalkAppKey + } + if reqBody.DingTalkAppSecret != "" { + user.Setting.DingTalkAppSecret = reqBody.DingTalkAppSecret + } if err := user.Save(); err != nil { HandleError(http.StatusInternalServerError, c, err) return diff --git a/backend/utils/encrypt.go b/backend/utils/encrypt.go new file mode 100644 index 00000000..52013b9c --- /dev/null +++ b/backend/utils/encrypt.go @@ -0,0 +1,16 @@ +package utils + +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/base64" + "encoding/hex" +) + +func ComputeHmacSha256(message string, secret string) string { + key := []byte(secret) + h := hmac.New(sha256.New, key) + h.Write([]byte(message)) + sha := hex.EncodeToString(h.Sum(nil)) + return base64.StdEncoding.EncodeToString([]byte(sha)) +} diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 841316fb..740408a2 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -353,6 +353,8 @@ export default { 'On Task End': '当任务结束', 'On Task Error': '当任务发生错误', 'Never': '从不', + 'DingTalk AppKey': '钉钉 AppKey', + 'DingTalk AppSecret': '钉钉 AppSecret', // 其他 tagsView: { diff --git a/frontend/src/views/setting/Setting.vue b/frontend/src/views/setting/Setting.vue index 83695f59..49a38700 100644 --- a/frontend/src/views/setting/Setting.vue +++ b/frontend/src/views/setting/Setting.vue @@ -24,6 +24,25 @@ + + + + + + +
{{$t('Save')}} @@ -58,7 +77,8 @@ export default { rules: { password: [{ trigger: 'blur', validator: validatePass }], email: [{ trigger: 'blur', validator: validateEmail }] - } + }, + isShowDingTalkAppSecret: false } }, methods: { @@ -74,7 +94,9 @@ export default { const res = await this.$store.dispatch('user/postInfo', { password: this.userInfo.password, email: this.userInfo.email, - notification_trigger: this.userInfo.setting.notification_trigger + notification_trigger: this.userInfo.setting.notification_trigger, + ding_talk_app_key: this.userInfo.setting.ding_talk_app_key, + ding_talk_app_secret: this.userInfo.setting.ding_talk_app_secret }) if (!res || res.error) { this.$message.error(res.error)