diff --git a/app/apiException/apiException.go b/app/apiException/apiException.go index 77d1850..21c944a 100644 --- a/app/apiException/apiException.go +++ b/app/apiException/apiException.go @@ -37,6 +37,7 @@ var ( NotBorrowingRecord = NewError(http.StatusInternalServerError, 200523, "含有非借用中的记录,请重新选择") SendVerificationCodeLimit = NewError(http.StatusInternalServerError, 200524, "短信发送超限,请1分钟后再试") CampusMismatch = NewError(http.StatusInternalServerError, 200525, "暂无该校区绑定信息") + OAuthNotUpdate = NewError(http.StatusInternalServerError, 200526, "统一身份认证密码未更新") NotInit = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound)) NotFound = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound)) Unknown = NewError(http.StatusInternalServerError, 300500, "系统异常,请稍后重试!") diff --git a/app/controllers/funcControllers/libraryController/libraryController.go b/app/controllers/funcControllers/libraryController/libraryController.go index ecc89af..7e06d6d 100644 --- a/app/controllers/funcControllers/libraryController/libraryController.go +++ b/app/controllers/funcControllers/libraryController/libraryController.go @@ -17,9 +17,7 @@ func GetCurrent(c *gin.Context) { } list, err := funnelServices.GetCurrentBorrow(user) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, "Library") - } + userServices.DelPassword(err, user, "Library") _ = c.AbortWithError(200, err) return } @@ -34,9 +32,7 @@ func GetHistory(c *gin.Context) { } list, err := funnelServices.GetHistoryBorrow(user) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, "Library") - } + userServices.DelPassword(err, user, "Library") _ = c.AbortWithError(200, err) return } diff --git a/app/controllers/funcControllers/zfController/zfController.go b/app/controllers/funcControllers/zfController/zfController.go index 0205c59..2a4f2bd 100644 --- a/app/controllers/funcControllers/zfController/zfController.go +++ b/app/controllers/funcControllers/zfController/zfController.go @@ -42,9 +42,7 @@ func GetClassTable(c *gin.Context) { result, err := funnelServices.GetClassTable(user, postForm.Year, postForm.Term, loginType) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, loginType) - } + userServices.DelPassword(err, user, loginType) _ = c.AbortWithError(200, err) return } @@ -73,9 +71,7 @@ func GetScore(c *gin.Context) { result, err := funnelServices.GetScore(user, postForm.Year, postForm.Term, loginType) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, loginType) - } + userServices.DelPassword(err, user, loginType) _ = c.AbortWithError(200, err) return } @@ -104,9 +100,7 @@ func GetMidTermScore(c *gin.Context) { result, err := funnelServices.GetMidTermScore(user, postForm.Year, postForm.Term, loginType) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, loginType) - } + userServices.DelPassword(err, user, loginType) _ = c.AbortWithError(200, err) return } @@ -135,9 +129,7 @@ func GetExam(c *gin.Context) { result, err := funnelServices.GetExam(user, postForm.Year, postForm.Term, loginType) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, loginType) - } + userServices.DelPassword(err, user, loginType) _ = c.AbortWithError(200, err) return } @@ -191,11 +183,7 @@ func GetRoom(c *gin.Context) { result, err := funnelServices.GetRoom(user, postForm.Year, postForm.Term, postForm.Campus, postForm.Weekday, postForm.Week, postForm.Sections, loginType) if err != nil { - if err == apiException.NoThatPasswordOrWrong { - userServices.DelPassword(user, loginType) - _ = c.AbortWithError(200, err) - return - } + userServices.DelPassword(err, user, loginType) _ = c.AbortWithError(200, err) return } diff --git a/app/services/funnelServices/funnelServices.go b/app/services/funnelServices/funnelServices.go index 827590a..368d071 100644 --- a/app/services/funnelServices/funnelServices.go +++ b/app/services/funnelServices/funnelServices.go @@ -46,6 +46,9 @@ func FetchHandleOfPost(form url.Values, url funnelApi.FunnelApi) (interface{}, e if rc.Code == 412 { return rc.Data, apiException.NoThatPasswordOrWrong } + if rc.Code == 416 { + return rc.Data, apiException.OAuthNotUpdate + } return rc.Data, nil } func FetchHandleOfGet(url funnelApi.FunnelApi) (interface{}, error) { diff --git a/app/services/userCenterServices/auth.go b/app/services/userCenterServices/auth.go index 7175756..48bfe39 100644 --- a/app/services/userCenterServices/auth.go +++ b/app/services/userCenterServices/auth.go @@ -24,7 +24,7 @@ func Login(stu_id string, pass string) error { } if resp.Code == 404 { return apiException.UserNotFind - } else if resp.Code == 405 { + } else if resp.Code == 409 { return apiException.NoThatPasswordOrWrong } else if resp.Code == 200 { return nil diff --git a/app/services/userServices/setUser.go b/app/services/userServices/setUser.go index 4950538..aaa0179 100644 --- a/app/services/userServices/setUser.go +++ b/app/services/userServices/setUser.go @@ -2,6 +2,7 @@ package userServices import ( "time" + "wejh-go/app/apiException" "wejh-go/app/models" "wejh-go/app/services/funnelServices" "wejh-go/config/database" @@ -58,21 +59,17 @@ func SetDeviceID(user *models.User, deviceID string) { database.DB.Save(user) } -func DelPassword(user *models.User, passwordType string) { - switch passwordType { - case "ZF": - { +func DelPassword(err error, user *models.User, passwordType string) { + if err == apiException.NoThatPasswordOrWrong || err == apiException.OAuthNotUpdate { + switch passwordType { + case "ZF": user.ZFPassword = "" - } - case "OAUTH": - { + case "OAUTH": user.OauthPassword = "" - } - case "Library": - { + case "Library": user.LibPassword = "" } + EncryptUserKeyInfo(user) + database.DB.Save(user) } - EncryptUserKeyInfo(user) - database.DB.Save(user) }