forked from forgejo/forgejo
move templateFuncs to one file, add middleware context.
This commit is contained in:
parent
06deed820d
commit
fa5ad1e465
10 changed files with 173 additions and 95 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"reflect"
|
||||
|
||||
"github.com/codegangsta/martini"
|
||||
"github.com/martini-contrib/render"
|
||||
"github.com/martini-contrib/sessions"
|
||||
|
||||
"github.com/gogits/binding"
|
||||
|
@ -62,39 +61,6 @@ func IsSignedIn(session sessions.Session) bool {
|
|||
return SignedInId(session) > 0
|
||||
}
|
||||
|
||||
// SignInRequire checks user status from session.
|
||||
// It will assign correspoding values to
|
||||
// template data map if user has signed in.
|
||||
func SignInRequire(redirect bool) martini.Handler {
|
||||
return func(r render.Render, data base.TmplData, session sessions.Session) {
|
||||
if !IsSignedIn(session) {
|
||||
if redirect {
|
||||
r.Redirect("/")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
user := SignedInUser(session)
|
||||
if user == nil {
|
||||
r.Redirect("/")
|
||||
return
|
||||
}
|
||||
|
||||
data["IsSigned"] = true
|
||||
data["SignedUser"] = user
|
||||
data["SignedUserId"] = user.Id
|
||||
data["SignedUserName"] = user.LowerName
|
||||
}
|
||||
}
|
||||
|
||||
func SignOutRequire() martini.Handler {
|
||||
return func(r render.Render, session sessions.Session) {
|
||||
if IsSignedIn(session) {
|
||||
r.Redirect("/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type FeedsForm struct {
|
||||
UserId int64 `form:"userid" binding:"Required"`
|
||||
Offset int64 `form:"offset"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue