| | |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "time" |
| | | "webserver/extend/code" |
| | | "webserver/extend/util" |
| | | "webserver/middlewares/auth" |
| | |
| | | // @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/user/login [post] |
| | | // @Router /data/api-v/sys/login [post] |
| | | func (controller UserController) Login(c *gin.Context) { |
| | | var userVo UserVo |
| | | if err := c.BindJSON(&userVo);err !=nil { |
| | |
| | | tokenStr := (*authDriver).Login(c.Request, c.Writer, util.Struct2Map(userInfo)) |
| | | util.ResponseFormat(c,code.Success,map[string]interface{}{ |
| | | "userInfo":userInfo, |
| | | "token":tokenStr, |
| | | "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){ |
| | | |
| | | } |