mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
updated setting
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
16
backend/utils/encrypt.go
Normal file
16
backend/utils/encrypt.go
Normal file
@@ -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))
|
||||
}
|
||||
@@ -353,6 +353,8 @@ export default {
|
||||
'On Task End': '当任务结束',
|
||||
'On Task Error': '当任务发生错误',
|
||||
'Never': '从不',
|
||||
'DingTalk AppKey': '钉钉 AppKey',
|
||||
'DingTalk AppSecret': '钉钉 AppSecret',
|
||||
|
||||
// 其他
|
||||
tagsView: {
|
||||
|
||||
@@ -24,6 +24,25 @@
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item prop="ding_talk_app_key" :label="$t('DingTalk AppKey')">
|
||||
<el-input v-model="userInfo.setting.ding_talk_app_key" :placeholder="$t('DingTalk AppKey')"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="ding_talk_app_secret" :label="$t('DingTalk AppSecret')">
|
||||
<template v-if="isShowDingTalkAppSecret">
|
||||
<el-input
|
||||
v-model="userInfo.setting.ding_talk_app_secret"
|
||||
:placeholder="$t('DingTalk AppSecret')"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-input
|
||||
type="password"
|
||||
suffix-icon="el-icon-view"
|
||||
v-model="userInfo.setting.ding_talk_app_secret"
|
||||
:placeholder="$t('DingTalk AppSecret')"
|
||||
/>
|
||||
</template>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<div class="buttons">
|
||||
<el-button type="success" @click="saveUserInfo">{{$t('Save')}}</el-button>
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user