diff --git a/api/handler/chat_role_handler.go b/api/handler/chat_role_handler.go
index 8e685497..c4b76bd4 100644
--- a/api/handler/chat_role_handler.go
+++ b/api/handler/chat_role_handler.go
@@ -2,6 +2,7 @@ package handler
import (
"chatplus/core"
+ "chatplus/core/types"
"chatplus/store/model"
"chatplus/store/vo"
"chatplus/utils"
@@ -76,3 +77,29 @@ func (h *ChatRoleHandler) List(c *gin.Context) {
}
resp.SUCCESS(c, roleVos)
}
+
+// AddRole 为用户添加角色
+func (h *ChatRoleHandler) AddRole(c *gin.Context) {
+ user, err := utils.GetLoginUser(c, h.db)
+ if err != nil {
+ resp.NotAuth(c)
+ return
+ }
+
+ var data struct {
+ Keys []string `json:"keys"`
+ }
+ if err = c.ShouldBindJSON(&data); err != nil {
+ resp.ERROR(c, types.InvalidArgs)
+ return
+ }
+
+ res := h.db.Model(&model.User{}).Where("id = ?", user.Id).UpdateColumn("chat_roles_json", utils.JsonEncode(data.Keys))
+ if res.Error != nil {
+ logger.Error("添加应用失败:", err)
+ resp.ERROR(c, "更新数据库失败!")
+ return
+ }
+
+ resp.SUCCESS(c)
+}
diff --git a/api/main.go b/api/main.go
index 925130d5..94cfeba9 100644
--- a/api/main.go
+++ b/api/main.go
@@ -185,6 +185,7 @@ func main() {
fx.Invoke(func(s *core.AppServer, h *handler.ChatRoleHandler) {
group := s.Engine.Group("/api/role/")
group.GET("list", h.List)
+ group.POST("add", h.AddRole)
}),
fx.Invoke(func(s *core.AppServer, h *handler.UserHandler) {
group := s.Engine.Group("/api/user/")
diff --git a/api/utils/common.go b/api/utils/common.go
index 01fdd32c..5147d470 100644
--- a/api/utils/common.go
+++ b/api/utils/common.go
@@ -36,7 +36,7 @@ func CopyObject(src interface{}, dst interface{}) error {
pType := reflect.New(value.Type())
v2 := pType.Interface()
err := json.Unmarshal([]byte(v.String()), &v2)
- if err == nil {
+ if err == nil && v2 != nil {
value.Set(reflect.ValueOf(v2).Elem())
}
// map, struct, slice to string
diff --git a/web/src/components/LoginDialog.vue b/web/src/components/LoginDialog.vue
new file mode 100644
index 00000000..1effc4c5
--- /dev/null
+++ b/web/src/components/LoginDialog.vue
@@ -0,0 +1,108 @@
+
+