From 4a2eb6f75b11ccb95e67a6f1c3b7cdf5b2c14d0c Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 03 七月 2019 10:39:00 +0800 Subject: [PATCH] only filter current analyServer es data --- controllers/user.go | 69 ++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 1 deletions(-) diff --git a/controllers/user.go b/controllers/user.go index e212688..5cff7b9 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -1,9 +1,76 @@ package controllers import ( + "basic.com/dbapi.git" + "fmt" "github.com/gin-gonic/gin" + "time" + "webserver/extend/code" + "webserver/extend/util" + "webserver/middlewares/auth" ) -func Login(c *gin.Context) { +type UserController struct { + +} + +type UserVo struct { + UserName string `json:"username"` + Password string `json:"password"` +} + +// @Summary 鐢ㄦ埛鐧诲綍 +// @Description 鐢ㄦ埛鐧诲綍 +// @Accept json +// @Produce json +// @Tags 鐢ㄦ埛 +// @Param user body UserVo true "鐢ㄦ埛淇℃伅" +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"", data:""}" +// @Router /data/api-v/sys/login [post] +func (controller UserController) Login(c *gin.Context) { + var userVo UserVo + if err := c.BindJSON(&userVo);err !=nil { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + var api dbapi.UserApi + flag, userInfo := api.Login(userVo.UserName, userVo.Password) + if flag { + authDriver := auth.GenerateAuthDriver() + tokenStr := (*authDriver).Login(c.Request, c.Writer, util.Struct2Map(userInfo)) + util.ResponseFormat(c,code.Success,map[string]interface{}{ + "userInfo":userInfo, + "access_token":tokenStr, + "refresh_token":tokenStr, + "scope":"app", + "token_type":"Bearer", + "expires_in":time.Now().Add(time.Hour * 8).Unix(), + }) + } else { + util.ResponseFormat(c,code.SigninInfoError,"鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒") + } +} + +// @Summary 鑾峰彇褰撳墠鐢ㄦ埛淇℃伅 +// @Description 鑾峰彇褰撳墠鐢ㄦ埛淇℃伅 +// @Accept json +// @Produce json +// @Tags 鐢ㄦ埛 +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"", data:""}" +// @Router /data/api-v/users/current [get] +func (controller UserController) Current(c *gin.Context) { + authDriver := auth.GenerateAuthDriver() + user := (*authDriver).User(c) + fmt.Println("current:",user) + if user !=nil { + util.ResponseFormat(c,code.Success,user) + } else { + util.ResponseFormat(c,code.NotLogin,"") + } +} + +func (controller UserController) Logout(c *gin.Context){ } \ No newline at end of file -- Gitblit v1.8.0