| | |
| | | |
| | | // @Summary 用户登录 |
| | | // @Description 用户登录 |
| | | // @Accept json |
| | | // @Accept x-www-form-urlencoded |
| | | // @Produce json |
| | | // @Tags 用户 |
| | | // @Param username query string true "用户名" |
| | | // @Param password query string true "密码" |
| | | // @Param username formData string true "用户名" |
| | | // @Param password formData string 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) { |
| | | // @Router /data/api-u/sys/login [post] |
| | | func (uc UserController) Login(c *gin.Context) { |
| | | userName := c.PostForm("username") |
| | | password := c.PostForm("password") |
| | | if userName == "" || password == "" { |
| | |
| | | if flag { |
| | | authDriver := auth.GenerateAuthDriver() |
| | | loginedM := util.Struct2Map(data) |
| | | tokenStr := (*authDriver).Login(c.Request, c.Writer, loginedM) |
| | | tokenM := make(map[string]interface{},2) |
| | | tokenM["id"] = loginedM["id"] |
| | | tokenM["username"] = loginedM["username"] |
| | | tokenM["permissions"] = loginedM["permissions"] |
| | | tokenStr := (*authDriver).Login(c.Request, c.Writer, tokenM) |
| | | |
| | | |
| | | userId := loginedM["id"].(string) |
| | | auth.RemoveOutUser(userId) |
| | | |
| | | c.JSON(200,map[string]interface{}{ |
| | | "userInfo":loginedM, |
| | | "access_token":tokenStr, |
| | |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 获取当前用户信息 |
| | | // @Description 获取当前用户信息 |
| | | // @Accept 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) { |
| | | // @Router /data/api-u/users/current [get] |
| | | func (uc UserController) Current(c *gin.Context) { |
| | | authDriver := auth.GenerateAuthDriver() |
| | | user := (*authDriver).User(c) |
| | | if user !=nil { |
| | |
| | | func (controller UserController) Logout(c *gin.Context){ |
| | | c.JSON(http.StatusOK,"退出成功") |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @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-u/users/findAllUser [get] |
| | | */ |
| | | func (uc UserController) FindAllUser(c *gin.Context) { |
| | | authDriver := auth.GenerateAuthDriver() |
| | | userM := (*authDriver).User(c) |
| | | userId := userM["id"].(string) |
| | | var api dbapi.UserApi |
| | | b,d := api.FindAllUser(userId) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | type UserEditVo struct { |
| | | Id string `json:"id"` |
| | | UserName string `json:"username"` |
| | | NewPwd string `json:"newPwd"` |
| | | MenuIds []string `json:"menuIds"` |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 编辑此用户,返回此用户的权限菜单 |
| | | // @Description 编辑此用户,返回此用户的权限菜单 |
| | | // @Accept x-www-form-urlencoded |
| | | // @Produce json |
| | | // @Tags 用户 |
| | | // @Param userId formData string true "用户id" |
| | | // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" |
| | | // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" |
| | | // @Router /data/api-u/users/findById [post] |
| | | */ |
| | | func (uc UserController) FindById(c *gin.Context) { |
| | | userId := c.PostForm("userId") |
| | | if userId == "" { |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | | return |
| | | } |
| | | var api dbapi.UserApi |
| | | b, d := api.FindById(userId) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 更新用户名,密码和菜单权限 |
| | | // @Description 更新用户名,密码和菜单权限 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags 用户 |
| | | // @Param userVo body controllers.UserEditVo 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/saveAuth [post] |
| | | */ |
| | | func (uc UserController) SaveAuth(c *gin.Context) { |
| | | var userEditVo UserEditVo |
| | | err := c.BindJSON(&userEditVo) |
| | | if err !=nil || userEditVo.Id =="" || userEditVo.UserName == "" { |
| | | util.ResponseFormat(c,code.RequestParamError,"") |
| | | return |
| | | } |
| | | paramBody := util.Struct2Map(userEditVo) |
| | | var api dbapi.UserApi |
| | | b, d := api.SaveAuth(paramBody) |
| | | if b { |
| | | auth.SetOutUser(userEditVo.Id) |
| | | util.ResponseFormat(c,code.UpdateSuccess,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.UpdateFail,"保存失败") |
| | | } |
| | | } |