From d8ce530648126daac9cf9131d084ee56268355ca Mon Sep 17 00:00:00 2001 From: 18650180552 Date: Wed, 15 May 2019 17:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=96=B0=E7=9A=84=E5=89=8D=E7=AB=AF=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + controller/middle/auth.go | 12 ++++++++++-- controller/user.go | 9 ++++----- model/model.go | 2 +- user.yaml | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a3a2640..b1e55f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ glide.yaml api_user.exe user.exe +background.exe diff --git a/controller/middle/auth.go b/controller/middle/auth.go index 61273ba..e3cb043 100644 --- a/controller/middle/auth.go +++ b/controller/middle/auth.go @@ -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() } \ No newline at end of file diff --git a/controller/user.go b/controller/user.go index adab4fa..1c59268 100644 --- a/controller/user.go +++ b/controller/user.go @@ -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) diff --git a/model/model.go b/model/model.go index 572aead..fcfc951 100644 --- a/model/model.go +++ b/model/model.go @@ -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) { diff --git a/user.yaml b/user.yaml index 3d59a3c..7d254e6 100644 --- a/user.yaml +++ b/user.yaml @@ -13,7 +13,7 @@ redis1: mysql: addr: 118.24.238.198 user: server - password: 123 + password: server db: background max_open: 100 MaxIdle: 99