Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 补充统一未更新时的错误响应和统一解绑 #88

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能不能把这一块的err处理抽成一个函数,反复写五遍不太好看,抽成一个,或者将判断的逻辑弄到del里去处理,避免重复的判断,如果后续还要变更又要改五个

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
21 changes: 9 additions & 12 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,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)
}
Loading