diff --git a/internal/base/middleware/auth.go b/internal/base/middleware/auth.go index c3fd6dc0..ccf40dda 100644 --- a/internal/base/middleware/auth.go +++ b/internal/base/middleware/auth.go @@ -3,7 +3,6 @@ package middleware import ( "strings" - "github.com/davecgh/go-spew/spew" "github.com/segmentfault/answer/internal/schema" "github.com/gin-gonic/gin" @@ -39,20 +38,13 @@ func (am *AuthUserMiddleware) Auth() gin.HandlerFunc { ctx.Next() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 Auth", userInfo) + userInfo, err := am.authService.GetUserCacheInfo(ctx, token) + if err != nil { + ctx.Next() + return + } + if userInfo != nil { ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetUserCacheInfo(ctx, token) - if err != nil { - ctx.Next() - return - } - if userInfo != nil { - ctx.Set(ctxUuidKey, userInfo) - } } ctx.Next() } @@ -67,38 +59,30 @@ func (am *AuthUserMiddleware) MustAuth() gin.HandlerFunc { ctx.Abort() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 MustAuth", userInfo) - ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetUserCacheInfo(ctx, token) - spew.Dump(userInfo, err) - if err != nil || userInfo == nil { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - if userInfo.EmailStatus != entity.EmailStatusAvailable { - handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified), - &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive}) - ctx.Abort() - return - } - if userInfo.UserStatus == entity.UserStatusSuspended { - handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), - &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) - ctx.Abort() - return - } - if userInfo.UserStatus == entity.UserStatusDeleted { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - ctx.Set(ctxUuidKey, userInfo) + userInfo, err := am.authService.GetUserCacheInfo(ctx, token) + if err != nil || userInfo == nil { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return } + if userInfo.EmailStatus != entity.EmailStatusAvailable { + handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified), + &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive}) + ctx.Abort() + return + } + if userInfo.UserStatus == entity.UserStatusSuspended { + handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), + &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) + ctx.Abort() + return + } + if userInfo.UserStatus == entity.UserStatusDeleted { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return + } + ctx.Set(ctxUuidKey, userInfo) ctx.Next() } } @@ -111,26 +95,19 @@ func (am *AuthUserMiddleware) CmsAuth() gin.HandlerFunc { ctx.Abort() return } - if token == "888" { - userInfo := &entity.UserCacheInfo{} - userInfo.UserID = "2" - spew.Dump("开发环境 CmsAuth", userInfo) - ctx.Set(ctxUuidKey, userInfo) - } else { - userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token) - if err != nil { + userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token) + if err != nil { + handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) + ctx.Abort() + return + } + if userInfo != nil { + if userInfo.UserStatus == entity.UserStatusDeleted { handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) ctx.Abort() return } - if userInfo != nil { - if userInfo.UserStatus == entity.UserStatusDeleted { - handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) - ctx.Abort() - return - } - ctx.Set(ctxUuidKey, userInfo) - } + ctx.Set(ctxUuidKey, userInfo) } ctx.Next() } diff --git a/internal/repo/question_repo.go b/internal/repo/question_repo.go index 986a34e5..9514d6b7 100644 --- a/internal/repo/question_repo.go +++ b/internal/repo/question_repo.go @@ -218,7 +218,6 @@ func (qr *questionRepo) SearchList(ctx context.Context, search *schema.QuestionS session = session.Limit(search.PageSize, offset) session = session.Select("question.id,question.user_id,question.title,question.original_text,question.parsed_text,question.status,question.view_count,question.unique_view_count,question.vote_count,question.answer_count,question.collection_count,question.follow_count,question.accepted_answer_id,question.last_answer_id,question.created_at,question.updated_at,question.post_update_time,question.revision_id") count, err = session.FindAndCount(&rows) - //spew.Dump("search", err, count, rows) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() return rows, count, err diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index e51c0a93..38a9938f 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -3,7 +3,6 @@ package schema import ( "encoding/json" - "github.com/davecgh/go-spew/spew" "github.com/jinzhu/copier" "github.com/segmentfault/answer/internal/base/validator" "github.com/segmentfault/answer/internal/entity" @@ -133,7 +132,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User if ok { r.Status = statusShow } - spew.Dump(userInfo) if userInfo.MailStatus == entity.EmailStatusToBeVerified { statusMsgShow, ok := UserStatusShowMsg[11] if ok { @@ -146,8 +144,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User } } - spew.Dump(r) - } const (