diff --git a/Makefile b/Makefile index 9176929c9581199112a4084f416fe701f4a31989..11bf430b21d48543c8281e1503d53650915dff03 100644 --- a/Makefile +++ b/Makefile @@ -23,3 +23,6 @@ default: app app: $(GOBUILD) -o output/app app/main.go + +env: + go env -w GOPROXY=https://goproxy.cn diff --git a/app/handler/auth.go b/app/handler/auth.go index a05b618ca5f27f5c8993f263e3ed52903293566b..1c66a9ecc21dfe145e8e8b5a05bfdc18a9e8d421 100644 --- a/app/handler/auth.go +++ b/app/handler/auth.go @@ -1,17 +1,15 @@ package handler import ( - "encoding/json" "fmt" - config "gitee.com/lanshiren/miniprogram/app/conf" + "net/http" + "strconv" + "strings" + "gitee.com/lanshiren/miniprogram/app/log" "gitee.com/lanshiren/miniprogram/app/model" "gitee.com/lanshiren/miniprogram/app/service" "github.com/gin-gonic/gin" - "github.com/xlstudio/wxbizdatacrypt" - "net/http" - "strconv" - "strings" ) // Secret ... @@ -115,23 +113,23 @@ func HandleAuthCode(c *gin.Context) { // AuthorizedLogin ... func AuthorizedLogin(c *gin.Context) { token := c.Request.Header.Get("token") - userData, _ := service.TryGetUserSession("session-" + token) + dataRes, _ := service.TryGetUserSession("session-" + token) var loginData model.LoginData if err := c.BindJSON(&loginData); err != nil { log.MainLogger.Error(fmt.Sprintf("bind client json to code err: %v", err)) } - pc := wxbizdatacrypt.WxBizDataCrypt{AppId: config.Conf.AppID, SessionKey: strings.Split(userData, "$")[1]} - result, err := pc.Decrypt(loginData.EncryptedData, loginData.Iv, true) - if err != nil { - fmt.Println(err) - } else { - log.MainLogger.Info(result.(string)) - } - var userInfo model.UserInfo - err = json.Unmarshal([]byte(result.(string)), &userInfo) + // pc := wxbizdatacrypt.WxBizDataCrypt{AppId: config.Conf.AppID, SessionKey: strings.Split(userData, "$")[1]} + // result, err := pc.Decrypt(loginData.EncryptedData, loginData.Iv, true) + // if err != nil { + // fmt.Println(err) + // } else { + // log.MainLogger.Info(result.(string)) + // } + userInfo := loginData.UserInfoVo + // err = json.Unmarshal([]byte(result.(string)), &userInfo) // commit user info to db - if err = service.UpdateUserInfo( - userInfo.OpenId, + if err := service.UpdateUserInfo( + strings.Split(dataRes, "$")[0], model.UsersDO{ Nickname: userInfo.NickName, Gender: userInfo.Gender, @@ -152,7 +150,6 @@ func AuthorizedLogin(c *gin.Context) { "userInfo": userInfo, }), }) - return } // Authorize ... diff --git a/app/model/auth.go b/app/model/auth.go index d25f5407c830b316e5aed9d96063099d0f5c30b6..4a1dd9cb8e4b3793170ed129e189c0597295dd39 100644 --- a/app/model/auth.go +++ b/app/model/auth.go @@ -5,8 +5,9 @@ type AuthData struct { } type LoginData struct { - EncryptedData string `json:"encryptedData"` - Iv string `json:"iv"` + EncryptedData string `json:"encryptedData"` + Iv string `json:"iv"` + UserInfoVo UserInfo `json:"userInfo"` } type Watermark struct { diff --git a/app/model/users_do.go b/app/model/users_do.go index 9808e42f4d839539de961eaaa49fec92b3695ada..a9eb911edd1219c37450a9e9a283fb03cddd2f8a 100644 --- a/app/model/users_do.go +++ b/app/model/users_do.go @@ -3,10 +3,11 @@ package model import ( "errors" "fmt" - config "gitee.com/lanshiren/miniprogram/app/conf" "strconv" "strings" "time" + + config "gitee.com/lanshiren/miniprogram/app/conf" ) const ( diff --git a/app/service/activity.go b/app/service/activity.go index aaf099aa7ac082943090e2919271cbcc6db56630..709b4c9028bade0606bc57d3bb6e2121d9f3ae26 100644 --- a/app/service/activity.go +++ b/app/service/activity.go @@ -171,11 +171,11 @@ func RegistrationActivity(userId uint, acId uint) error { if err != nil { return err } - if acDo.CurCount > acDo.CountLimit { + if acDo.CurCount >= acDo.CountLimit { return errors.New("人数已满,停止报名。") } if time.Now().Unix() > acDo.RegistrationDeadline { - //return errors.New("截止时间已到,禁止报名。") + return errors.New("截止时间已到,禁止报名。") } rss, err := model.GetRegistrationByUIDAndAcID(userId, acId) fmt.Printf("RSS %v", rss)