Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
添加路由,暂时关闭token时效验证
Browse files Browse the repository at this point in the history
  • Loading branch information
mohuishou committed Jan 28, 2018
1 parent 721f189 commit 34adf89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
9 changes: 7 additions & 2 deletions api/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ func Loan(ctx iris.Context) {
func GetBook(ctx iris.Context) {
uid := middleware.GetUserID(ctx)
userLibrary := model.UserLibrary{}
model.DB().Where("user_id = ?", uid).Find(&userLibrary)
if err := model.DB().Where("user_id = ?", uid).Find(&userLibrary).Error; err != nil {
api.Error(ctx, 60401, "用户暂未绑定", map[string]interface{}{
"verify": userLibrary.Verify,
})
return
}
lib, err := userLibrary.GetLibrary()
if err != nil {
api.Error(ctx, 60401, err.Error(), map[string]interface{}{
Expand All @@ -74,7 +79,7 @@ func GetBook(ctx iris.Context) {
return
}

isHistory := "1"
isHistory := ctx.URLParam("is_history")

books := []sculibrary.LoanBook{}
if isHistory == "1" {
Expand Down
16 changes: 7 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/mohuishou/scuplus-go/config"
"github.com/mohuishou/scuplus-go/middleware"

"github.com/betacraft/yaag/irisyaag"
"github.com/betacraft/yaag/yaag"
"github.com/kataras/iris"
"github.com/mohuishou/scuplus-go/route"
)
Expand All @@ -17,13 +15,13 @@ func main() {

env := os.Getenv("SCUPLUS_ENV")
if env == "test" {
yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware.
On: true,
DocTitle: "SCUPLUS",
DocPath: "apidoc/apidoc.html",
BaseUrls: map[string]string{"Production": "", "Staging": ""},
})
app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware.
// yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware.
// On: true,
// DocTitle: "SCUPLUS",
// DocPath: "apidoc/apidoc.html",
// BaseUrls: map[string]string{"Production": "", "Staging": ""},
// })
// app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware.
}

// 注册中间件
Expand Down
21 changes: 10 additions & 11 deletions middleware/jwt.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package middleware

import (
"log"
"time"

"github.com/mohuishou/scuplus-go/config"
Expand Down Expand Up @@ -49,16 +48,16 @@ func jwtMiddle(ctx iris.Context) {
}

// token 时效验证
end, ok := token.Claims.(jwt.MapClaims)["end"].(float64)
if !ok || time.Now().Unix() > int64(end) {
log.Println("[Error]: 登录信息已失效", end)
ctx.JSON(map[string]interface{}{
"status": 401,
"msg": "用户尚未登录,获取用户信息失败",
})
ctx.StopExecution()
return
}
// end, ok := token.Claims.(jwt.MapClaims)["end"].(float64)
// if !ok || time.Now().Unix() > int64(end) {
// log.Println("[Error]: 登录信息已失效", end)
// ctx.JSON(map[string]interface{}{
// "status": 401,
// "msg": "用户尚未登录,获取用户信息失败",
// })
// ctx.StopExecution()
// return
// }

// 设置用户id
ctx.Values().Set("user_id", userID)
Expand Down
1 change: 1 addition & 0 deletions route/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ func Routes(app *iris.Application) {
app.Post("/library/search", library.Search)
app.Get("/library/books", library.GetBook)
app.Post("/library/loan", library.Loan)
app.Post("/library/bind", library.BindLibrary)
}

0 comments on commit 34adf89

Please sign in to comment.