Skip to content

Commit

Permalink
chore: 追加一处错误打印
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Aug 19, 2023
1 parent fb24469 commit 62600d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
24 changes: 12 additions & 12 deletions internal/api/controllers/public/login/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func VerifyMfa(c *gin.Context) {
return
}

claims, e := jwt.ParseMfaToken(f.Token)
if e != nil {
callback.Error(c, callback.ErrUnauthorized)
claims, err := jwt.ParseMfaToken(f.Token)
if err != nil {
callback.Error(c, callback.ErrUnauthorized, err)
return
}

Expand All @@ -28,24 +28,24 @@ func VerifyMfa(c *gin.Context) {
return
}

valid, e := tools.VerifyMfa(f.Code, claims.Mfa)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
valid, err := tools.VerifyMfa(f.Code, claims.Mfa)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
} else if !valid {
callback.Error(c, callback.ErrMfaCode)
return
}

token, e := jwt.GenerateLoginToken(claims.LoginTokenClaims)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
token, err := jwt.GenerateLoginToken(claims.LoginTokenClaims)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

callbackUrl, e := tools.GenCallback(claims.AppCallback, token)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
callbackUrl, err := tools.GenCallback(claims.AppCallback, token)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

Expand Down
56 changes: 28 additions & 28 deletions internal/api/controllers/public/login/thirdPartyLogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func callThirdPartyLoginResult(c *gin.Context, info ThirdPartyLoginContext) {
}

if info.User.MFA == "" {
token, e := jwt.GenerateLoginToken(claims)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
token, err := jwt.GenerateLoginToken(claims)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

callbackUrl, e := tools.GenCallback(info.AppInfo.Callback, token)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
callbackUrl, err := tools.GenCallback(info.AppInfo.Callback, token)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

Expand All @@ -114,9 +114,9 @@ func callThirdPartyLoginResult(c *gin.Context, info ThirdPartyLoginContext) {
Callback: callbackUrl,
})
} else {
token, e := jwt.GenerateMfaToken(claims, info.User.MFA, info.AppInfo.Callback)
if e != nil {
callback.Error(c, callback.ErrUnexpected, e)
token, err := jwt.GenerateMfaToken(claims, info.User.MFA, info.AppInfo.Callback)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

Expand Down Expand Up @@ -174,11 +174,11 @@ func ThirdPartyLogin(c *gin.Context) {

appCode := c.Param("appCode")

if ok, e := service.App.CheckAppCode(appCode); e != nil {
callback.Error(c, callback.ErrDBOperation, e)
if ok, err := service.App.CheckAppCode(appCode); err != nil {
callback.Error(c, callback.ErrDBOperation, err)
return
} else if !ok {
callback.Error(c, callback.ErrAppCodeNotFound, e)
callback.Error(c, callback.ErrAppCodeNotFound, err)
return
}

Expand All @@ -190,37 +190,37 @@ func ThirdPartyLogin(c *gin.Context) {
return
}

appInfo, e := service.App.FirstAppByAppCode(appCode)
if e != nil {
callback.Error(c, callback.ErrDBOperation, e)
appInfo, err := service.App.FirstAppByAppCode(appCode)
if err != nil {
callback.Error(c, callback.ErrDBOperation, err)
return
}

user, e := service.User.UserInfo(userIdentity.Phone)
if e != nil {
callback.Error(c, callback.ErrDBOperation, e)
user, err := service.User.UserInfo(userIdentity.Phone)
if err != nil {
callback.Error(c, callback.ErrDBOperation, err)
return
}

var groups []string
isCenterMember, e := service.UserGroups.IsCenterMember(user.ID)
if e != nil {
callback.Error(c, callback.ErrDBOperation, e)
isCenterMember, err := service.UserGroups.IsCenterMember(user.ID)
if err != nil {
callback.Error(c, callback.ErrDBOperation, err)
return
} else if isCenterMember {
groups, e = service.UserGroups.GetForUser(user.ID)
if e != nil {
callback.Error(c, callback.ErrDBOperation, e)
groups, err = service.UserGroups.GetForUser(user.ID)
if err != nil {
callback.Error(c, callback.ErrDBOperation, err)
return
}
} else {
groups, e = service.UserGroups.GetForAppCode(user.ID, appCode)
if e != nil {
if errors.Is(e, gorm.ErrRecordNotFound) {
groups, err = service.UserGroups.GetForAppCode(user.ID, appCode)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
callback.ErrorWithTip(c, callback.ErrUnauthorized, "没有找到角色,请尝试使用其他登录方式或联系管理员")
return
}
callback.Error(c, callback.ErrDBOperation, e)
callback.Error(c, callback.ErrDBOperation, err)
return
}

Expand Down

0 comments on commit 62600d8

Please sign in to comment.