-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/1.2.0/img' into test
- Loading branch information
Showing
10 changed files
with
111 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/answerdev/answer/internal/base/constant" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
// VisitAuth when user visit the site image, check visit token. This only for private mode. | ||
func (am *AuthUserMiddleware) VisitAuth() gin.HandlerFunc { | ||
return func(ctx *gin.Context) { | ||
siteLogin, err := am.siteInfoCommonService.GetSiteLogin(ctx) | ||
if err != nil { | ||
return | ||
} | ||
if !siteLogin.LoginRequired { | ||
ctx.Next() | ||
return | ||
} | ||
|
||
visitToken, err := ctx.Cookie(constant.UserVisitCookiesCacheKey) | ||
if err != nil || len(visitToken) == 0 { | ||
ctx.Abort() | ||
ctx.Redirect(http.StatusFound, "/403") | ||
return | ||
} | ||
|
||
if !am.authService.CheckUserVisitToken(ctx, visitToken) { | ||
ctx.Abort() | ||
ctx.Redirect(http.StatusFound, "/403") | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters