Skip to content

Commit

Permalink
fix: 补充统一未更新时的错误响应和统一解绑
Browse files Browse the repository at this point in the history
  • Loading branch information
Penryn committed Dec 16, 2024
1 parent 58fcc5b commit 32b4032
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/apiException/apiException.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "系统异常,请稍后重试!")
Expand Down
22 changes: 5 additions & 17 deletions app/controllers/funcControllers/zfController/zfController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions app/services/funnelServices/funnelServices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/services/userCenterServices/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 18 additions & 15 deletions app/services/userServices/setUser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,21 +59,23 @@ func SetDeviceID(user *models.User, deviceID string) {
database.DB.Save(user)
}

func DelPassword(user *models.User, passwordType string) {
switch passwordType {
case "ZF":
{
user.ZFPassword = ""
}
case "OAUTH":
{
user.OauthPassword = ""
}
case "Library":
{
user.LibPassword = ""
func DelPassword(err error, user *models.User, passwordType string) {
if err == apiException.NoThatPasswordOrWrong || err == apiException.OAuthNotUpdate {
switch passwordType {
case "ZF":
{
user.ZFPassword = ""
}
case "OAUTH":
{
user.OauthPassword = ""
}
case "Library":
{
user.LibPassword = ""
}
}
EncryptUserKeyInfo(user)
database.DB.Save(user)
}
EncryptUserKeyInfo(user)
database.DB.Save(user)
}

0 comments on commit 32b4032

Please sign in to comment.