master
taoshihan 2 months ago
parent 779bbb5e7f
commit 299a46060e

@ -8,25 +8,25 @@ import (
func GetNotice(c *gin.Context) { func GetNotice(c *gin.Context) {
kefuId := c.Query("kefu_id") kefuId := c.Query("kefu_id")
user := models.FindUser(kefuId) user := models.FindUser(kefuId)
if user.ID==0{ if user.ID == 0 {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 400, "code": 400,
"msg": "user not found", "msg": "user not found",
}) })
return return
} }
welcomeMessage:=models.FindConfig("WelcomeMessage") welcomeMessage := models.FindConfigByUserId(user.Name, "WelcomeMessage")
offlineMessage:=models.FindConfig("OfflineMessage") offlineMessage := models.FindConfigByUserId(user.Name, "OfflineMessage")
allNotice:=models.FindConfig("AllNotice") allNotice := models.FindConfigByUserId(user.Name, "AllNotice")
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,
"msg": "ok", "msg": "ok",
"result": gin.H{ "result": gin.H{
"welcome":welcomeMessage, "welcome": welcomeMessage,
"offline":offlineMessage, "offline": offlineMessage,
"avatar":user.Avator, "avatar": user.Avator,
"nickname":user.Nickname, "nickname": user.Nickname,
"allNotice":allNotice, "allNotice": allNotice,
}, },
}) })
} }

@ -79,17 +79,17 @@ func PostVisitorLogin(c *gin.Context) {
) )
if ipcity != nil { if ipcity != nil {
city = ipcity.CountryName + ipcity.RegionName + ipcity.CityName city = ipcity.CountryName + ipcity.RegionName + ipcity.CityName
name = ipcity.CountryName + ipcity.RegionName + ipcity.CityName name = ipcity.CountryName + ipcity.RegionName + ipcity.CityName
if ipcity.CityName == "本机地址" || ipcity.RegionName == "本机地址" || ipcity.CountryName == "本机地址" {
city = "local address"
}
} else { } else {
city = "未识别地区" city = "Unrecognized Region"
name = "匿名网友" name = "visitor"
} }
if city == "本机地址本机地址" {
name = "local address" if name == "本机地址本机地址" {
}
if ipcity.CountryName == "本机地址本机地址" {
name = "local visitor" name = "local visitor"
} }
client_ip := c.ClientIP() client_ip := c.ClientIP()
@ -138,9 +138,9 @@ func PostVisitorLogin(c *gin.Context) {
visitor.VisitorId = id visitor.VisitorId = id
//各种通知 //各种通知
go SendNoticeEmail(visitor.Name, "来了") go SendNoticeEmail(visitor.Name, " incoming!")
go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+"来了") go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+" incoming!")
go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+"来了", visitor.VisitorId) go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+" incoming!", visitor.VisitorId)
go ws.VisitorOnline(kefuInfo.Name, visitor) go ws.VisitorOnline(kefuInfo.Name, visitor)
//go SendServerJiang(visitor.Name, "来了", c.Request.Host) //go SendServerJiang(visitor.Name, "来了", c.Request.Host)
@ -294,7 +294,7 @@ func GetKefusVisitorOnlines(c *gin.Context) {
for _, user := range users { for _, user := range users {
user.LastMessage = temp[user.Uid] user.LastMessage = temp[user.Uid]
if user.LastMessage == "" { if user.LastMessage == "" {
user.LastMessage = "新访客" user.LastMessage = "new visitor"
} }
} }

@ -7,6 +7,7 @@ type Config struct {
ConfName string `json:"conf_name"` ConfName string `json:"conf_name"`
ConfKey string `json:"conf_key"` ConfKey string `json:"conf_key"`
ConfValue string `json:"conf_value"` ConfValue string `json:"conf_value"`
UserId string `json:"user_id"`
} }
func UpdateConfig(key string, value string) { func UpdateConfig(key string, value string) {
@ -32,3 +33,11 @@ func FindConfig(key string) string {
} }
return "" return ""
} }
func FindConfigByUserId(userId, key string) string {
for _, config := range CustomConfigs {
if key == config.ConfKey && config.UserId == userId {
return config.ConfValue
}
}
return ""
}

@ -604,7 +604,7 @@
this.usersMap=[]; this.usersMap=[];
for(let i=0;i<retData.length;i++){ for(let i=0;i<retData.length;i++){
this.usersMap[retData[i].uid]=retData[i].username; this.usersMap[retData[i].uid]=retData[i].username;
retData[i].last_message="新访客"; retData[i].last_message="new visitor";
} }
if(this.users.length==0){ if(this.users.length==0){
this.users = retData; this.users = retData;

@ -360,7 +360,7 @@
var code=res.code; var code=res.code;
if(code!=200) return; if(code!=200) return;
_this.kefuInfo=res.result; _this.kefuInfo=res.result;
_this.showTitle(_this.kefuInfo.nickname+" is ready to help"); _this.showTitle(_this.kefuInfo.nickname+" at your service.");
if(!_this.kefuInfo.welcome) return; if(!_this.kefuInfo.welcome) return;
var msg={ var msg={
content:replaceContent(_this.kefuInfo.welcome), content:replaceContent(_this.kefuInfo.welcome),

@ -3,7 +3,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="renderer" content="webkit"> <meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Go Open Source Live Chat Software</title> <title>GoflyLiveChat - Open Source Live Chat</title>
<link rel="stylesheet" href="/static/cdn/element-ui/2.15.1/theme-chalk/index.min.css"> <link rel="stylesheet" href="/static/cdn/element-ui/2.15.1/theme-chalk/index.min.css">
<script src="/static/cdn/vue/2.6.11/vue.min.js"></script> <script src="/static/cdn/vue/2.6.11/vue.min.js"></script>
<script src="/static/cdn/element-ui/2.15.1/index.js"></script> <script src="/static/cdn/element-ui/2.15.1/index.js"></script>
@ -52,34 +52,34 @@
<div id="app" class="signin"> <div id="app" class="signin">
<template> <template>
<div class="loginHtml"> <div class="loginHtml">
<h1 class="loginTitle">Open Source Live Chat</h1> <h1 class="loginTitle">Welcome to GoflyLiveChat</h1>
<el-form :model="form" :rules="rules" ref="loginForm" v-show="!showRegHtml"> <el-form :model="form" :rules="rules" ref="loginForm" v-show="!showRegHtml">
<el-form-item prop="account"> <el-form-item prop="account">
<el-input v-model="form.account" placeholder="Username"></el-input> <el-input v-model="form.account" placeholder="Enter your username"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input show-password v-on:keyup.enter.native="handleLogin('loginForm')" v-model="form.password" placeholder="Password"></el-input> <el-input show-password v-on:keyup.enter.native="handleLogin('loginForm')" v-model="form.password" placeholder="Enter your password"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button style="width: 100%" type="primary" @click="handleLogin('loginForm')">Sign In</el-button> <el-button style="width: 100%" type="primary" @click="handleLogin('loginForm')">Log In</el-button>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button style="width: 100%" @click="showRegHtml=true">Create Account</el-button> <el-button style="width: 100%" @click="showRegHtml=true">Create New Account</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-form :model="form" :rules="rules" ref="registerForm" v-show="showRegHtml"> <el-form :model="form" :rules="rules" ref="registerForm" v-show="showRegHtml">
<el-form-item prop="account"> <el-form-item prop="account">
<el-input v-model="form.account" placeholder="Username"></el-input> <el-input v-model="form.account" placeholder="Choose a username"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input show-password v-model="form.password" placeholder="Password"></el-input> <el-input show-password v-model="form.password" placeholder="Create a password"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="rePassword"> <el-form-item prop="rePassword">
<el-input show-password v-on:keyup.enter.native="handleRegister('registerForm')" v-model="form.rePassword" placeholder="Confirm Password"></el-input> <el-input show-password v-on:keyup.enter.native="handleRegister('registerForm')" v-model="form.rePassword" placeholder="Confirm password"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button style="width: 100%" type="primary" @click="handleRegister('registerForm')">Register</el-button> <el-button style="width: 100%" type="primary" @click="handleRegister('registerForm')">Sign Up</el-button>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button style="width: 100%" @click="showRegHtml=false">Back to Login</el-button> <el-button style="width: 100%" @click="showRegHtml=false">Back to Login</el-button>
@ -87,7 +87,7 @@
</el-form> </el-form>
</div> </div>
<p class="copyright">Go Open Source Live Chat Software</p> <p class="copyright">GoflyLiveChat - Open Source Live Chat Platform</p>
</template> </template>
</div> </div>
</body> </body>
@ -103,11 +103,11 @@
}, },
rules: { rules: {
account: [ account: [
{ required: true, message: 'Please input your username', trigger: 'blur' }, { required: true, message: 'Username is required', trigger: 'blur' },
{ min: 2, max: 20, message: 'Length should be 2 to 20 characters', trigger: 'blur' } { min: 2, max: 20, message: 'Username must be 2-20 characters', trigger: 'blur' }
], ],
password: [ password: [
{ required: true, message: 'Please input your password', trigger: 'blur' }, { required: true, message: 'Password is required', trigger: 'blur' },
{ min: 2, message: 'Password must be at least 2 characters', trigger: 'blur' } { min: 2, message: 'Password must be at least 2 characters', trigger: 'blur' }
], ],
rePassword: [ rePassword: [
@ -120,7 +120,7 @@
methods: { methods: {
validatePasswordMatch(rule, value, callback) { validatePasswordMatch(rule, value, callback) {
if (value !== this.form.password) { if (value !== this.form.password) {
callback(new Error('Passwords do not match!')); callback(new Error('Passwords don\'t match'));
} else { } else {
callback(); callback();
} }
@ -151,20 +151,20 @@
$.post("/check", data, (response) => { $.post("/check", data, (response) => {
if (response.code === 200) { if (response.code === 200) {
this.$message({ this.$message({
message: 'Login successful', message: 'Welcome back!',
type: 'success' type: 'success'
}); });
localStorage.setItem("token", response.result.token); localStorage.setItem("token", response.result.token);
window.location.href = "/main"; window.location.href = "/main";
} else { } else {
this.$message({ this.$message({
message: response.message || 'Login failed', message: response.message || 'Invalid credentials',
type: 'error' type: 'error'
}); });
} }
}).fail(() => { }).fail(() => {
this.$message({ this.$message({
message: 'Network error', message: 'Connection error',
type: 'error' type: 'error'
}); });
}); });
@ -173,7 +173,7 @@
register() { register() {
if (this.form.password !== this.form.rePassword) { if (this.form.password !== this.form.rePassword) {
this.$message({ this.$message({
message: 'Passwords do not match', message: 'Passwords don\'t match',
type: 'error' type: 'error'
}); });
return; return;
@ -187,7 +187,7 @@
$.post("/register", data, (response) => { $.post("/register", data, (response) => {
if (response.code === 200) { if (response.code === 200) {
this.$message({ this.$message({
message: 'Registration successful', message: 'Account created successfully!',
type: 'success' type: 'success'
}); });
this.showRegHtml = false; this.showRegHtml = false;
@ -199,7 +199,7 @@
} }
}).fail(() => { }).fail(() => {
this.$message({ this.$message({
message: 'Network error', message: 'Connection error',
type: 'error' type: 'error'
}); });
}); });

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
) )
//咨询界面 // 咨询界面
func PageChat(c *gin.Context) { func PageChat(c *gin.Context) {
kefuId := c.Query("kefu_id") kefuId := c.Query("kefu_id")
refer := c.Query("refer") refer := c.Query("refer")
@ -13,20 +13,10 @@ func PageChat(c *gin.Context) {
refer = c.Request.Referer() refer = c.Request.Referer()
} }
if refer == "" { if refer == "" {
refer = "直接访问" refer = "Direct Link"
} }
c.HTML(http.StatusOK, "chat_page.html", gin.H{ c.HTML(http.StatusOK, "chat_page.html", gin.H{
"KEFU_ID": kefuId, "KEFU_ID": kefuId,
"Refer": refer, "Refer": refer,
}) })
} }
func PageKfChat(c *gin.Context) {
kefuId := c.Query("kefu_id")
visitorId := c.Query("visitor_id")
token := c.Query("token")
c.HTML(http.StatusOK, "chat_kf_page.html", gin.H{
"KefuId": kefuId,
"VisitorId": visitorId,
"Token": token,
})
}

@ -171,7 +171,7 @@ func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content s
} }
if !ok || kefu == nil { if !ok || kefu == nil {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
welcome := models.FindConfig("OfflineMessage") welcome := models.FindConfigByUserId(kefuInfo.Name, "OfflineMessage")
if welcome == "" || reply.Content != "" { if welcome == "" || reply.Content != "" {
return return
} }

Loading…
Cancel
Save