Bläddra i källkod

feat: 当前用户接口

runningwater 8 månader sedan
förälder
incheckning
426687fbfd
3 ändrade filer med 31 tillägg och 3 borttagningar
  1. 18 0
      app/http/controllers/api/v1/users_controller.go
  2. 7 3
      gohub.http
  3. 6 0
      routes/api.go

+ 18 - 0
app/http/controllers/api/v1/users_controller.go

@@ -0,0 +1,18 @@
+package v1
+
+import (
+	"github.com/runningwater/gohub/pkg/auth"
+	"github.com/runningwater/gohub/pkg/response"
+
+	"github.com/gin-gonic/gin"
+)
+
+type UsersController struct {
+	BaseApiController
+}
+
+// CurrentUser 当前登录用户信息
+func (ctrl *UsersController) CurrentUser(c *gin.Context) {
+	users := auth.CurrentUser(c)
+	response.Data(c, users)
+}

+ 7 - 3
gohub.http

@@ -45,7 +45,7 @@ Content-Type: application/json
 {
     "name":"summer",
     "password":"secret",
-    "password_confirm":"no_match",
+    "password_confirm":"secret",
     "verify_code": "123123",
     "phone": "00011059149"
 }
@@ -69,7 +69,7 @@ Content-Type: application/json
 {
     "captcha_id" :"xTS6AtcgjUVABJj2M9NE",
     "captcha_answer": "338750",
-    "login_id": "summer@testing.com",
+    "login_id": "summer",
     "password": "secret"
 }
 
@@ -86,4 +86,8 @@ Authorization: Bearer {{access_token}}
 
 ### /test_gust 测试认证
 GET {{base_url}}/test_gust HTTP/1.1
-Authorization: Bearer {{access_token}}
+Authorization: Bearer {{access_token}}
+
+### GET /current_user 当前登陆用户
+GET {{base_url}}/v1/auth/user HTTP/1.1
+Authorization: Bearer {{access_token}}

+ 6 - 0
routes/api.go

@@ -6,6 +6,8 @@ import (
 
 	"github.com/runningwater/gohub/app/http/controllers/api/v1/auth"
 	"github.com/runningwater/gohub/app/http/middlewares"
+
+	controllers "github.com/runningwater/gohub/app/http/controllers/api/v1"
 )
 
 // RegisterAPIRoutes 注册路由
@@ -48,6 +50,10 @@ func RegisterAPIRoutes(router *gin.Engine) {
 			pc := new(auth.PasswordController)
 			// 使用手机重置密码
 			authGroup.POST("/password-reset/using-phone", middlewares.LimitPerRoute("20-H"), pc.ResetByPhone)
+
+			uc := new(controllers.UsersController)
+			// 当前登录用户信息
+			authGroup.GET("/user", middlewares.AuthJWT(), uc.CurrentUser)
 		}
 	}
 }