Skip to content

Commit 32b4032

Browse files
committed
fix: 补充统一未更新时的错误响应和统一解绑
1 parent 58fcc5b commit 32b4032

File tree

5 files changed

+28
-33
lines changed

5 files changed

+28
-33
lines changed

app/apiException/apiException.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
NotBorrowingRecord = NewError(http.StatusInternalServerError, 200523, "含有非借用中的记录,请重新选择")
3838
SendVerificationCodeLimit = NewError(http.StatusInternalServerError, 200524, "短信发送超限,请1分钟后再试")
3939
CampusMismatch = NewError(http.StatusInternalServerError, 200525, "暂无该校区绑定信息")
40+
OAuthNotUpdate = NewError(http.StatusInternalServerError, 200526, "统一身份认证密码未更新")
4041
NotInit = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
4142
NotFound = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
4243
Unknown = NewError(http.StatusInternalServerError, 300500, "系统异常,请稍后重试!")

app/controllers/funcControllers/zfController/zfController.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ func GetClassTable(c *gin.Context) {
4242

4343
result, err := funnelServices.GetClassTable(user, postForm.Year, postForm.Term, loginType)
4444
if err != nil {
45-
if err == apiException.NoThatPasswordOrWrong {
46-
userServices.DelPassword(user, loginType)
47-
}
45+
userServices.DelPassword(err, user, loginType)
4846
_ = c.AbortWithError(200, err)
4947
return
5048
}
@@ -73,9 +71,7 @@ func GetScore(c *gin.Context) {
7371

7472
result, err := funnelServices.GetScore(user, postForm.Year, postForm.Term, loginType)
7573
if err != nil {
76-
if err == apiException.NoThatPasswordOrWrong {
77-
userServices.DelPassword(user, loginType)
78-
}
74+
userServices.DelPassword(err, user, loginType)
7975
_ = c.AbortWithError(200, err)
8076
return
8177
}
@@ -104,9 +100,7 @@ func GetMidTermScore(c *gin.Context) {
104100

105101
result, err := funnelServices.GetMidTermScore(user, postForm.Year, postForm.Term, loginType)
106102
if err != nil {
107-
if err == apiException.NoThatPasswordOrWrong {
108-
userServices.DelPassword(user, loginType)
109-
}
103+
userServices.DelPassword(err, user, loginType)
110104
_ = c.AbortWithError(200, err)
111105
return
112106
}
@@ -135,9 +129,7 @@ func GetExam(c *gin.Context) {
135129

136130
result, err := funnelServices.GetExam(user, postForm.Year, postForm.Term, loginType)
137131
if err != nil {
138-
if err == apiException.NoThatPasswordOrWrong {
139-
userServices.DelPassword(user, loginType)
140-
}
132+
userServices.DelPassword(err, user, loginType)
141133
_ = c.AbortWithError(200, err)
142134
return
143135
}
@@ -191,11 +183,7 @@ func GetRoom(c *gin.Context) {
191183

192184
result, err := funnelServices.GetRoom(user, postForm.Year, postForm.Term, postForm.Campus, postForm.Weekday, postForm.Week, postForm.Sections, loginType)
193185
if err != nil {
194-
if err == apiException.NoThatPasswordOrWrong {
195-
userServices.DelPassword(user, loginType)
196-
_ = c.AbortWithError(200, err)
197-
return
198-
}
186+
userServices.DelPassword(err, user, loginType)
199187
_ = c.AbortWithError(200, err)
200188
return
201189
}

app/services/funnelServices/funnelServices.go

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func FetchHandleOfPost(form url.Values, url funnelApi.FunnelApi) (interface{}, e
4646
if rc.Code == 412 {
4747
return rc.Data, apiException.NoThatPasswordOrWrong
4848
}
49+
if rc.Code == 416 {
50+
return rc.Data, apiException.OAuthNotUpdate
51+
}
4952
return rc.Data, nil
5053
}
5154
func FetchHandleOfGet(url funnelApi.FunnelApi) (interface{}, error) {

app/services/userCenterServices/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Login(stu_id string, pass string) error {
2424
}
2525
if resp.Code == 404 {
2626
return apiException.UserNotFind
27-
} else if resp.Code == 405 {
27+
} else if resp.Code == 409 {
2828
return apiException.NoThatPasswordOrWrong
2929
} else if resp.Code == 200 {
3030
return nil

app/services/userServices/setUser.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package userServices
22

33
import (
44
"time"
5+
"wejh-go/app/apiException"
56
"wejh-go/app/models"
67
"wejh-go/app/services/funnelServices"
78
"wejh-go/config/database"
@@ -58,21 +59,23 @@ func SetDeviceID(user *models.User, deviceID string) {
5859
database.DB.Save(user)
5960
}
6061

61-
func DelPassword(user *models.User, passwordType string) {
62-
switch passwordType {
63-
case "ZF":
64-
{
65-
user.ZFPassword = ""
66-
}
67-
case "OAUTH":
68-
{
69-
user.OauthPassword = ""
70-
}
71-
case "Library":
72-
{
73-
user.LibPassword = ""
62+
func DelPassword(err error, user *models.User, passwordType string) {
63+
if err == apiException.NoThatPasswordOrWrong || err == apiException.OAuthNotUpdate {
64+
switch passwordType {
65+
case "ZF":
66+
{
67+
user.ZFPassword = ""
68+
}
69+
case "OAUTH":
70+
{
71+
user.OauthPassword = ""
72+
}
73+
case "Library":
74+
{
75+
user.LibPassword = ""
76+
}
7477
}
78+
EncryptUserKeyInfo(user)
79+
database.DB.Save(user)
7580
}
76-
EncryptUserKeyInfo(user)
77-
database.DB.Save(user)
7881
}

0 commit comments

Comments
 (0)