diff --git a/controller/kefu.go b/controller/kefu.go
index 81083b8..83c8a4a 100644
--- a/controller/kefu.go
+++ b/controller/kefu.go
@@ -78,8 +78,6 @@ func GetKefuInfo(c *gin.Context) {
kefuName, _ := c.Get("kefu_name")
user := models.FindUser(kefuName.(string))
info := make(map[string]interface{})
- info["name"] = user.Nickname
- info["id"] = user.Name
info["avator"] = user.Avator
info["username"] = user.Name
info["nickname"] = user.Nickname
@@ -162,6 +160,7 @@ func GetKefuInfoSetting(c *gin.Context) {
func PostKefuRegister(c *gin.Context) {
name := c.PostForm("username")
password := c.PostForm("password")
+ nickname := c.PostForm("nickname")
avatar := "/static/images/4.jpg"
if name == "" || password == "" {
@@ -183,7 +182,7 @@ func PostKefuRegister(c *gin.Context) {
return
}
- userID := models.CreateUser(name, tools.Md5(password), avatar, "")
+ userID := models.CreateUser(name, tools.Md5(password), avatar, nickname)
if userID == 0 {
c.JSON(http.StatusInternalServerError, gin.H{
"code": 500,
diff --git a/controller/notice.go b/controller/notice.go
index 3d002b0..25b847b 100644
--- a/controller/notice.go
+++ b/controller/notice.go
@@ -22,11 +22,11 @@ func GetNotice(c *gin.Context) {
"code": 200,
"msg": "ok",
"result": gin.H{
- "welcome": welcomeMessage,
- "offline": offlineMessage,
+ "welcome": welcomeMessage.ConfValue,
+ "offline": offlineMessage.ConfValue,
"avatar": user.Avator,
"nickname": user.Nickname,
- "allNotice": allNotice,
+ "allNotice": allNotice.ConfValue,
},
})
}
diff --git a/controller/setting.go b/controller/setting.go
index 1797146..37fcd18 100644
--- a/controller/setting.go
+++ b/controller/setting.go
@@ -6,7 +6,8 @@ import (
)
func GetConfigs(c *gin.Context) {
- configs := models.FindConfigs()
+ kefuName, _ := c.Get("kefu_name")
+ configs := models.FindConfigsByUserId(kefuName)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
@@ -25,6 +26,7 @@ func GetConfig(c *gin.Context) {
func PostConfig(c *gin.Context) {
key := c.PostForm("key")
value := c.PostForm("value")
+ kefuName, _ := c.Get("kefu_name")
if key == "" || value == "" {
c.JSON(200, gin.H{
"code": 400,
@@ -32,7 +34,7 @@ func PostConfig(c *gin.Context) {
})
return
}
- models.UpdateConfig(key, value)
+ models.UpdateConfig(kefuName, key, value)
c.JSON(200, gin.H{
"code": 200,
diff --git a/controller/shout.go b/controller/shout.go
index 8dd52e2..ec86cc0 100644
--- a/controller/shout.go
+++ b/controller/shout.go
@@ -147,7 +147,7 @@ func getGetuiToken() string {
json.Unmarshal([]byte(res), &pushRes)
if pushRes.Code == 0 {
token := pushRes.Data["token"].(string)
- models.UpdateConfig("GetuiToken", token)
+ //models.UpdateConfig("GetuiToken", token)
return token
}
}
diff --git a/controller/visitor.go b/controller/visitor.go
index cf48307..766e565 100644
--- a/controller/visitor.go
+++ b/controller/visitor.go
@@ -139,7 +139,7 @@ func PostVisitorLogin(c *gin.Context) {
//各种通知
go SendNoticeEmail(visitor.Name, " incoming!")
- go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+" incoming!")
+ //go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+" incoming!")
go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+" incoming!", visitor.VisitorId)
go ws.VisitorOnline(kefuInfo.Name, visitor)
//go SendServerJiang(visitor.Name, "来了", c.Request.Host)
diff --git a/import.sql b/import.sql
index 7ef9d6f..128f1a7 100644
--- a/import.sql
+++ b/import.sql
@@ -71,7 +71,8 @@ CREATE TABLE `config` (
`conf_value` varchar(255) NOT NULL DEFAULT '',
`user_id` varchar(500) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
- UNIQUE KEY `conf_key` (`conf_key`)
+ KEY `conf_key` (`conf_key`),
+ KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`, `user_id`) VALUES
(NULL, 'Announcement', 'AllNotice', 'Open source customer support system at your service','agent');
diff --git a/models/abouts.go b/models/abouts.go
index 3c09956..7d37796 100644
--- a/models/abouts.go
+++ b/models/abouts.go
@@ -50,5 +50,4 @@ func UpdateAbout(page string, title_cn string, title_en string, keywords_cn stri
HtmlEn: html_en,
}
DB.Model(c).Where("page = ?", page).Update(c)
- InitConfig()
}
diff --git a/models/configs.go b/models/configs.go
index 916014e..e1f32c1 100644
--- a/models/configs.go
+++ b/models/configs.go
@@ -10,21 +10,34 @@ type Config struct {
UserId string `json:"user_id"`
}
-func UpdateConfig(key string, value string) {
- c := &Config{
- ConfValue: value,
+func UpdateConfig(userid interface{}, key string, value string) {
+ config := FindConfigByUserId(userid, key)
+ if config.ID != 0 {
+ config.ConfValue = value
+ DB.Where("user_id = ? and conf_key = ?", userid, key).Update(config)
+ } else {
+ newConfig := &Config{
+ ID: 0,
+ ConfName: "",
+ ConfKey: key,
+ ConfValue: value,
+ UserId: userid.(string),
+ }
+ DB.Create(newConfig)
}
- DB.Model(c).Where("conf_key = ?", key).Update(c)
- InitConfig()
+
}
func FindConfigs() []Config {
var config []Config
DB.Find(&config)
return config
}
-func InitConfig() {
- CustomConfigs = FindConfigs()
+func FindConfigsByUserId(userid interface{}) []Config {
+ var config []Config
+ DB.Where("user_id = ?", userid).Find(&config)
+ return config
}
+
func FindConfig(key string) string {
for _, config := range CustomConfigs {
if key == config.ConfKey {
@@ -33,11 +46,8 @@ func FindConfig(key string) string {
}
return ""
}
-func FindConfigByUserId(userId, key string) string {
- for _, config := range CustomConfigs {
- if key == config.ConfKey && config.UserId == userId {
- return config.ConfValue
- }
- }
- return ""
+func FindConfigByUserId(userId interface{}, key string) Config {
+ var config Config
+ DB.Where("user_id = ? and conf_key = ?", userId, key).Find(&config)
+ return config
}
diff --git a/models/models.go b/models/models.go
index ce639e1..9ea75a0 100644
--- a/models/models.go
+++ b/models/models.go
@@ -35,7 +35,6 @@ func Connect() error {
DB.DB().SetMaxIdleConns(10)
DB.DB().SetMaxOpenConns(100)
DB.DB().SetConnMaxLifetime(59 * time.Second)
- InitConfig()
return nil
}
func Execute(sql string) error {
diff --git a/static/templates/login.html b/static/templates/login.html
index bf47b4f..fbc1bbf 100644
--- a/static/templates/login.html
+++ b/static/templates/login.html
@@ -72,6 +72,9 @@
+
+
+
@@ -99,13 +102,18 @@
form: {
account: "",
password: "",
- rePassword: ""
+ rePassword: "",
+ nickname:"",
},
rules: {
account: [
{ required: true, message: 'Username is required', trigger: 'blur' },
{ min: 2, max: 20, message: 'Username must be 2-20 characters', trigger: 'blur' }
],
+ nickname: [
+ { required: true, message: 'DisplayName is required', trigger: 'blur' },
+ { min: 1, max: 60, message: 'DisplayName must be 1-60 characters', trigger: 'blur' }
+ ],
password: [
{ required: true, message: 'Password is required', trigger: 'blur' },
{ min: 2, message: 'Password must be at least 2 characters', trigger: 'blur' }
@@ -182,6 +190,7 @@
let data = {
"username": this.form.account,
"password": this.form.password,
+ "nickname": this.form.nickname,
};
$.post("/register", data, (response) => {
diff --git a/static/templates/pannel.html b/static/templates/pannel.html
index 6d4369a..a5b240d 100644
--- a/static/templates/pannel.html
+++ b/static/templates/pannel.html
@@ -79,7 +79,7 @@