From c0d6c90c5539073ac7f58f1f68699cfb946c47a6 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期二, 17 十二月 2019 11:27:59 +0800
Subject: [PATCH] update capture
---
controllers/user.go | 114 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 94 insertions(+), 20 deletions(-)
diff --git a/controllers/user.go b/controllers/user.go
index f473545..3dd1090 100644
--- a/controllers/user.go
+++ b/controllers/user.go
@@ -3,6 +3,7 @@
import (
"basic.com/dbapi.git"
"github.com/gin-gonic/gin"
+ "net/http"
"time"
"webserver/extend/code"
"webserver/extend/util"
@@ -20,14 +21,14 @@
// @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]
+// @Router /data/api-u/sys/login [post]
func (uc UserController) Login(c *gin.Context) {
userName := c.PostForm("username")
password := c.PostForm("password")
@@ -43,8 +44,14 @@
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)
- util.ResponseFormat(c,code.Success,map[string]interface{}{
+
+
+ userId := loginedM["id"].(string)
+ auth.RemoveOutUser(userId)
+
+ c.JSON(200,map[string]interface{}{
"userInfo":loginedM,
"access_token":tokenStr,
"refresh_token":tokenStr,
@@ -53,10 +60,40 @@
"expires_in":time.Now().Add(time.Hour * 8).Unix(),
})
} else {
- util.ResponseFormat(c,code.LoginInfoError,"鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒")
+ c.JSON(500,"鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒")
}
}
+// @Security ApiKeyAuth
+// @Summary 淇敼褰撳墠鐧诲綍鐢ㄦ埛鐨勫瘑鐮�
+// @Description 淇敼褰撳墠鐧诲綍鐢ㄦ埛鐨勫瘑鐮�
+// @Accept x-www-form-urlencoded
+// @Produce json
+// @Tags 鐢ㄦ埛
+// @Param oldPwd formData string true "鏃у瘑鐮�"
+// @Param newPwd 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-u/users/updatePwd [post]
+func (uc UserController) UpdatePwd(c *gin.Context) {
+ oldPwd := c.PostForm("oldPwd")
+ newPwd := c.PostForm("newPwd")
+ if oldPwd == "" || newPwd == "" {
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
+ }
+ authDriver := auth.GenerateAuthDriver()
+ userM := (*authDriver).User(c)
+ userId := userM["id"].(string)
+ var userApi dbapi.UserApi
+ if b,_ :=userApi.UpdatePwd(userId, oldPwd, newPwd);b {
+ util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛")
+ } else {
+ util.ResponseFormat(c,code.AccountPassUnmatch,"瀵嗙爜鏈夎")
+ }
+}
+
+// @Security ApiKeyAuth
// @Summary 鑾峰彇褰撳墠鐢ㄦ埛淇℃伅
// @Description 鑾峰彇褰撳墠鐢ㄦ埛淇℃伅
// @Accept json
@@ -69,9 +106,9 @@
authDriver := auth.GenerateAuthDriver()
user := (*authDriver).User(c)
if user !=nil {
- util.ResponseFormat(c,code.Success,user)
+ c.JSON(http.StatusOK,user)
} else {
- util.ResponseFormat(c,code.TokenNotFound,"")
+ c.JSON(http.StatusUnauthorized,"")
}
}
// @Router /data/api-u/sys/refresh_token [post]
@@ -81,13 +118,24 @@
// @Router /data/api-u/sys/logout [get]
func (uc UserController) Logout(c *gin.Context){
- util.ResponseFormat(c,code.LogoutSuccess,"閫�鍑烘垚鍔�")
+ 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()
+ b,d := api.FindAllUser(userId)
if b {
util.ResponseFormat(c,code.Success,d)
} else {
@@ -98,33 +146,59 @@
type UserEditVo struct {
Id string `json:"id"`
UserName string `json:"username"`
- OldPwd string `json:"oldPwd"`
NewPwd string `json:"newPwd"`
- RoleIds []string `json:"roleIds"`
+ MenuIds []string `json:"menuIds"`
}
-// @Summary 鏇存柊鐢ㄦ埛鍚嶏紝瀵嗙爜鍜岃鑹叉潈闄�
-// @Description 鏇存柊鐢ㄦ埛鍚嶏紝瀵嗙爜鍜岃鑹叉潈闄�
+// @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 UserEditVo true "鐢ㄦ埛缂栬緫淇℃伅"
+// @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/users/edit [post]
-func (uc UserController) Edit(c *gin.Context) {
+// @Router /data/api-v/users/saveAuth [post]
+func (uc UserController) SaveAuth(c *gin.Context) {
var userEditVo UserEditVo
err := c.BindJSON(&userEditVo)
- if err !=nil || userEditVo.Id =="" || userEditVo.OldPwd == "" || userEditVo.NewPwd =="" || userEditVo.UserName == "" {
+ if err !=nil || userEditVo.Id =="" || userEditVo.UserName == "" {
util.ResponseFormat(c,code.RequestParamError,"")
return
}
paramBody := util.Struct2Map(userEditVo)
var api dbapi.UserApi
- b,d := api.Edit(paramBody)
+ b, d := api.SaveAuth(paramBody)
if b {
+ auth.SetOutUser(userEditVo.Id)
util.ResponseFormat(c,code.UpdateSuccess,d)
} else {
- util.ResponseFormat(c,code.UpdateFail,"鏇存柊澶辫触")
+ util.ResponseFormat(c,code.UpdateFail,"淇濆瓨澶辫触")
}
}
\ No newline at end of file
--
Gitblit v1.8.0