更改配置,匹配新的前端文件

master
18650180552 2019-05-15 17:28:34 +08:00
parent 93a4a224eb
commit d8ce530648
5 changed files with 17 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
glide.yaml
api_user.exe
user.exe
background.exe

View File

@ -6,17 +6,21 @@ import (
"background/model"
"encoding/json"
"github.com/gin-gonic/gin"
"log"
)
func AuthMiddle(c *gin.Context) {
token := c.Query("token")
user := c.Query("userid")
if user == "" || token == ""{
log.Print("error user not existed")
c.JSON(200,controller.RespBase{
"auth err",20,nil,
})
c.Abort()
return
}
if config.RedisOne().Exists(token).Val(){
if config.RedisOne().Exists(token).Val() {
users := model.Users{}
userInfo := config.RedisOne().Get(token).Val()
e := json.Unmarshal([]byte(userInfo),&users)
@ -24,11 +28,15 @@ func AuthMiddle(c *gin.Context) {
c.JSON(200,controller.RespBase{
"auth err",10,nil,
})
c.Abort()
return
}
}else {
c.JSON(200,controller.RespBase{
"expired",210,nil,
"expired or no login",210,nil,
})
c.Abort()
return
}
c.Next()
}

View File

@ -145,8 +145,7 @@ func (this *UserController) GetUser(c *gin.Context) {
if nil != e {
logs.Error(e.Error())
}
delete(users, "socketToken"+
"")
delete(users, "socketToken")
resp.Status = 0
resp.Msg = "操作成功"
resp.Data = users
@ -316,15 +315,15 @@ func (this *UserController) Login(c *gin.Context) {
socketToken.Write([]byte(createToken(6))) // 需要加密的字符串为 123456
socketTokenMd5 := socketToken.Sum(nil)
m := structs.Map(result[0])
m["socketToken"] = utils.ByteSliceToString(socketTokenMd5)
m["SocketToken"] = utils.ByteSliceToString(socketTokenMd5)
sessionInfo, err := json.Marshal(m)
if err != nil {
log.Println(err.Error())
}
if req.RememberMe == 1 {
config.RedisOne().Set(string(socketTokenMd5), string(sessionInfo), time.Second*2*24*3600*1000)
config.RedisOne().Set(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*2*24*3600*1000)
} else {
config.RedisOne().Set(string(socketTokenMd5), string(sessionInfo), time.Second*8*3600*1000)
config.RedisOne().Set(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*8*3600*1000)
}
//存储session
session := sessions.Get(c)

View File

@ -18,7 +18,7 @@ type Users struct {
DisplayName string `sql:"display_name" json:"display_name"`
EmailAddress string `sql:"email_address" json:"email_address"`
Tel string `sql:"tel" json:"tel"`
Avatar string `sql:"avatar" json:"avatar"`
Avatar string `sql:"Avatar" json:"avatar"`
}
func GetUsers(limit int32, offsetPage int32, name string) ([]Users, int32) {

View File

@ -13,7 +13,7 @@ redis1:
mysql:
addr: 118.24.238.198
user: server
password: 123
password: server
db: background
max_open: 100
MaxIdle: 99