mirror of
https://github.com/go-gitea/gitea.git
synced 2025-05-02 13:45:28 +00:00
parent
7794ff0874
commit
8fa3925874
@ -1635,7 +1635,7 @@ func registerRoutes(m *web.Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
|
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
|
||||||
ctx := context.GetWebContext(req)
|
ctx := context.GetWebContext(req.Context())
|
||||||
routing.UpdateFuncInfo(ctx, routing.GetFuncInfo(ctx.NotFound, "WebNotFound"))
|
routing.UpdateFuncInfo(ctx, routing.GetFuncInfo(ctx.NotFound, "WebNotFound"))
|
||||||
ctx.NotFound("", nil)
|
ctx.NotFound("", nil)
|
||||||
})
|
})
|
||||||
|
@ -104,7 +104,7 @@ func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore
|
|||||||
middleware.SetLocaleCookie(resp, user.Language, 0)
|
middleware.SetLocaleCookie(resp, user.Language, 0)
|
||||||
|
|
||||||
// force to generate a new CSRF token
|
// force to generate a new CSRF token
|
||||||
if ctx := gitea_context.GetWebContext(req); ctx != nil {
|
if ctx := gitea_context.GetWebContext(req.Context()); ctx != nil {
|
||||||
ctx.Csrf.PrepareForSessionUser(ctx)
|
ctx.Csrf.PrepareForSessionUser(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore,
|
|||||||
store.GetData()["EnableSSPI"] = true
|
store.GetData()["EnableSSPI"] = true
|
||||||
// in this case, the Verify function is called in Gitea's web context
|
// in this case, the Verify function is called in Gitea's web context
|
||||||
// FIXME: it doesn't look good to render the page here, why not redirect?
|
// FIXME: it doesn't look good to render the page here, why not redirect?
|
||||||
gitea_context.GetWebContext(req).HTML(http.StatusUnauthorized, tplSignIn)
|
gitea_context.GetWebContext(req.Context()).HTML(http.StatusUnauthorized, tplSignIn)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if outToken != "" {
|
if outToken != "" {
|
||||||
|
@ -77,9 +77,9 @@ type webContextKeyType struct{}
|
|||||||
|
|
||||||
var WebContextKey = webContextKeyType{}
|
var WebContextKey = webContextKeyType{}
|
||||||
|
|
||||||
func GetWebContext(req *http.Request) *Context {
|
func GetWebContext(ctx context.Context) *Context {
|
||||||
ctx, _ := req.Context().Value(WebContextKey).(*Context)
|
webCtx, _ := ctx.Value(WebContextKey).(*Context)
|
||||||
return ctx
|
return webCtx
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.
|
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.
|
||||||
@ -133,6 +133,7 @@ func NewWebContext(base *Base, render Render, session session.Store) *Context {
|
|||||||
}
|
}
|
||||||
ctx.TemplateContext = NewTemplateContextForWeb(ctx)
|
ctx.TemplateContext = NewTemplateContextForWeb(ctx)
|
||||||
ctx.Flash = &middleware.Flash{DataStore: ctx, Values: url.Values{}}
|
ctx.Flash = &middleware.Flash{DataStore: ctx, Values: url.Values{}}
|
||||||
|
ctx.AppendContextValue(WebContextKey, ctx)
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ func ProcessorHelper() *markup.RenderHelperFuncs {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
giteaCtx, ok := ctx.(*gitea_context.Context)
|
giteaCtx := gitea_context.GetWebContext(ctx)
|
||||||
if !ok {
|
if giteaCtx == nil {
|
||||||
// when using general context, use user's visibility to check
|
// when using general context, use user's visibility to check
|
||||||
return mentionedUser.Visibility.IsPublic()
|
return mentionedUser.Visibility.IsPublic()
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
webCtx, ok := ctx.Value(gitea_context.WebContextKey).(*gitea_context.Context)
|
webCtx := gitea_context.GetWebContext(ctx)
|
||||||
if !ok {
|
if webCtx == nil {
|
||||||
return "", fmt.Errorf("context is not a web context")
|
return "", fmt.Errorf("context is not a web context")
|
||||||
}
|
}
|
||||||
doer := webCtx.Doer
|
doer := webCtx.Doer
|
||||||
|
Loading…
Reference in New Issue
Block a user