-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8627fe
commit f45ed8b
Showing
10 changed files
with
213 additions
and
201 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
package passport | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"github.com/timidsmile/pspace/components" | ||
"net/http" | ||
"github.com/timidsmile/pspace/service" | ||
"strconv" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func GetUserInfoAction(c *gin.Context) { | ||
fmt.Println("in getU") | ||
response := components.NewResponse() | ||
c.Header("Access-Control-Allow-Origin", "*") | ||
c.Header("Access-Control-Allow-Origin", "https://www.pspace.com") | ||
defer c.JSON(http.StatusOK, response) | ||
|
||
// 直接从表单中取数据形式获取参数 | ||
userIdStr := c.PostForm("userID") | ||
|
||
userID, _ := strconv.ParseInt(userIdStr, 10, 64) | ||
userID := c.MustGet("userID").(int64) | ||
fmt.Println(userID) | ||
|
||
userServ := service.UserBasicService{} | ||
userBasic := userServ.GetByUserID(userID) | ||
|
||
response.Data = userBasic; | ||
response.Data = userBasic | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ func main() { | |
} | ||
|
||
router := router.LoadRouters() | ||
|
||
router.Run() // listen and serve on 0.0.0.0:8080 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
package middleware | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"github.com/timidsmile/pspace/components" | ||
"net/http" | ||
"github.com/timidsmile/pspace/service" | ||
) | ||
|
||
func CheckLogin(c *gin.Context) { | ||
response := components.NewResponse() | ||
defer c.JSON(http.StatusOK, response) | ||
|
||
token, exist := c.GetPostForm("token") | ||
if !exist { | ||
response.Code = 1 | ||
response.Msg = "用户未登录!" | ||
c.Abort() | ||
return | ||
} | ||
|
||
// 验证token是否正确 | ||
userSession := components.Session{} | ||
tokenInRedis := userSession.Get(token) | ||
|
||
if tokenInRedis == nil { | ||
response.Code = 2 | ||
response.Msg = "用户未登录!" | ||
c.Abort() | ||
return | ||
if cookie, err := c.Request.Cookie("token"); err == nil { | ||
token := cookie.Value | ||
|
||
if token == "" { | ||
response := components.NewResponse() | ||
response.Code = 1 | ||
response.Msg = "用户未登录!" | ||
c.JSON(http.StatusOK, response) | ||
|
||
c.Abort() | ||
return | ||
} | ||
|
||
userSession := components.Session{} | ||
tokenInRedis := userSession.Get(token) | ||
if tokenInRedis == nil { | ||
response := components.NewResponse() | ||
response.Code = 1 | ||
response.Msg = "用户未登录!" | ||
c.JSON(http.StatusOK, response) | ||
|
||
c.Abort() | ||
return | ||
} | ||
|
||
userID := tokenInRedis.UserID | ||
fmt.Println(userID) | ||
c.Set("userID", userID) | ||
} | ||
|
||
// 用户已登陆 | ||
userID := tokenInRedis.UserID | ||
|
||
userServ := service.UserBasicService{} | ||
users := userServ.GetByUserID(userID) | ||
|
||
response.Data = users | ||
c.Next() | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters