From f4e8f206a6760bdc31734dfcb1c65916b5b76311 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 22 八月 2019 12:05:58 +0800
Subject: [PATCH] add cluster

---
 controllers/user.go |   76 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 1 deletions(-)

diff --git a/controllers/user.go b/controllers/user.go
index e212688..0f0b1e2 100644
--- a/controllers/user.go
+++ b/controllers/user.go
@@ -1,9 +1,83 @@
 package controllers
 
 import (
+	"basic.com/dbapi.git"
 	"github.com/gin-gonic/gin"
+	"net/http"
+	"time"
+	"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 username query string true "鐢ㄦ埛鍚�"
+// @Param password query 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) {
+	userName := c.PostForm("username")
+	password := c.PostForm("password")
+	if userName == "" || password == "" {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.UserApi
+	flag, data := api.Login(userName, password)
+	if flag {
+		authDriver := auth.GenerateAuthDriver()
+		loginedM := util.Struct2Map(data)
+		tokenStr := (*authDriver).Login(c.Request, c.Writer, loginedM)
+		c.JSON(200,map[string]interface{}{
+			"userInfo":loginedM,
+			"access_token":tokenStr,
+			"refresh_token":tokenStr,
+			"scope":"app",
+			"token_type":"Bearer",
+			"expires_in":time.Now().Add(time.Hour * 8).Unix(),
+		})
+	} else {
+		c.JSON(500,"鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒")
+	}
+}
+
+// @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)
+	if user !=nil {
+		c.JSON(http.StatusOK,user)
+	} else {
+		c.JSON(http.StatusUnauthorized,"")
+	}
+}
+// @Router /data/api-u/sys/refresh_token [post]
+func (controller UserController) RefreshToken(c *gin.Context){
+
+}
+
+// @Router /data/api-u/sys/logout [get]
+func (controller UserController) Logout(c *gin.Context){
+	c.JSON(http.StatusOK,"閫�鍑烘垚鍔�")
 }
\ No newline at end of file

--
Gitblit v1.8.0