()
| 178 | } |
| 179 | |
| 180 | func (am *AuthUserMiddleware) AdminAuth() gin.HandlerFunc { |
| 181 | return func(ctx *gin.Context) { |
| 182 | token := ExtractToken(ctx) |
| 183 | if len(token) == 0 { |
| 184 | handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) |
| 185 | ctx.Abort() |
| 186 | return |
| 187 | } |
| 188 | userInfo, err := am.authService.GetAdminUserCacheInfo(ctx, token) |
| 189 | if err != nil || userInfo == nil { |
| 190 | handler.HandleResponse(ctx, errors.Forbidden(reason.UnauthorizedError), nil) |
| 191 | ctx.Abort() |
| 192 | return |
| 193 | } |
| 194 | if userInfo != nil { |
| 195 | if userInfo.EmailStatus == entity.EmailStatusToBeVerified { |
| 196 | _ = am.authService.RemoveAdminUserCacheInfo(ctx, token) |
| 197 | handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified), |
| 198 | &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive}) |
| 199 | ctx.Abort() |
| 200 | return |
| 201 | } |
| 202 | if userInfo.UserStatus == entity.UserStatusSuspended { |
| 203 | _ = am.authService.RemoveAdminUserCacheInfo(ctx, token) |
| 204 | handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), |
| 205 | &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) |
| 206 | ctx.Abort() |
| 207 | return |
| 208 | } |
| 209 | if userInfo.UserStatus == entity.UserStatusDeleted { |
| 210 | _ = am.authService.RemoveAdminUserCacheInfo(ctx, token) |
| 211 | handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil) |
| 212 | ctx.Abort() |
| 213 | return |
| 214 | } |
| 215 | ctx.Set(ctxUUIDKey, userInfo) |
| 216 | } |
| 217 | ctx.Next() |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | func (am *AuthUserMiddleware) CheckPrivateMode() gin.HandlerFunc { |
| 222 | return func(ctx *gin.Context) { |
no test coverage detected