From 438daea4337768cd4fa47c9f88481e89805e03e9 Mon Sep 17 00:00:00 2001 From: ckt1031 <65409152+ckt1031@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:14:41 +0800 Subject: [PATCH] fix: google id --- controller/google.go | 22 +++------------------- model/user.go | 2 +- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/controller/google.go b/controller/google.go index c5c0fa11..654b8abe 100644 --- a/controller/google.go +++ b/controller/google.go @@ -35,7 +35,7 @@ func getGoogleUserInfoByCode(codeFromURLParamaters string, host string) (*Google RequestClient := &http.Client{} accessTokenBody := bytes.NewBuffer([]byte(fmt.Sprintf( - "code=%s&client_id=%s&client_secret=%s&redirect_uri=%s/oauth/google&grant_type=authorization_code", + "code=%s&client_id=%s&client_secret=%s&redirect_uri=https://%s/oauth/google&grant_type=authorization_code", codeFromURLParamaters, common.GoogleClientId, common.GoogleClientSecret, host, ))) @@ -112,15 +112,7 @@ func GoogleOAuth(c *gin.Context) { } code := c.Query("code") - // Get protocal whether http or https and host - host := c.Request.Host - if c.Request.TLS == nil { - host = "http://" + host - } else { - host = "https://" + host - } - - googleUser, err := getGoogleUserInfoByCode(code, host) + googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host) if err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, @@ -187,15 +179,7 @@ func GoogleBind(c *gin.Context) { } code := c.Query("code") - // Get protocal whether http or https and host - host := c.Request.Host - if c.Request.TLS == nil { - host = "http://" + host - } else { - host = "https://" + host - } - - googleUser, err := getGoogleUserInfoByCode(code, host) + googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host) if err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, diff --git a/model/user.go b/model/user.go index 6ccf9001..82037019 100644 --- a/model/user.go +++ b/model/user.go @@ -180,7 +180,7 @@ func (user *User) FillUserByWeChatId() error { } func (user *User) FillUserByGoogleId() error { - if user.WeChatId == "" { + if user.GoogleId == "" { return errors.New("Google id 为空!") } DB.Where(User{GoogleId: user.GoogleId}).First(user)