| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "github.com/gin-gonic/gin" |
| | | "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/user/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, |
| | | "token":tokenStr, |
| | | }) |
| | | } else { |
| | | util.ResponseFormat(c,code.SigninInfoError,"用户名或密码错误") |
| | | } |
| | | } |