Skip to content

Commit

Permalink
Merge pull request zjutjh#88 from Penryn/main
Browse files Browse the repository at this point in the history
fix: 补充统一未更新时的错误响应和统一解绑
  • Loading branch information
XiMo-210 authored Dec 17, 2024
2 parents 58fcc5b + 20125b3 commit 248950d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 36 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
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)
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)
}

0 comments on commit 248950d

Please sign in to comment.