diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/context/auth.go | 10 | ||||
-rw-r--r-- | pkg/context/context.go | 26 | ||||
-rw-r--r-- | pkg/context/org.go | 4 | ||||
-rw-r--r-- | pkg/context/repo.go | 12 |
4 files changed, 27 insertions, 25 deletions
diff --git a/pkg/context/auth.go b/pkg/context/auth.go index d2bfe603..9ad5cdd0 100644 --- a/pkg/context/auth.go +++ b/pkg/context/auth.go @@ -30,20 +30,20 @@ func Toggle(options *ToggleOptions) macaron.Handler { } // Check prohibit login users. - if ctx.IsSigned && ctx.User.ProhibitLogin { + if ctx.IsLogged && ctx.User.ProhibitLogin { ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") ctx.HTML(200, "user/auth/prohibit_login") return } // Check non-logged users landing page. - if !ctx.IsSigned && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME { + if !ctx.IsLogged && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME { ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL)) return } // Redirect to dashboard if user tries to visit any non-login page. - if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" { + if options.SignOutRequired && ctx.IsLogged && ctx.Req.RequestURI != "/" { ctx.Redirect(setting.AppSubURL + "/") return } @@ -56,7 +56,7 @@ func Toggle(options *ToggleOptions) macaron.Handler { } if options.SignInRequired { - if !ctx.IsSigned { + if !ctx.IsLogged { // Restrict API calls with error message. if auth.IsAPIPath(ctx.Req.URL.Path) { ctx.JSON(403, map[string]string{ @@ -76,7 +76,7 @@ func Toggle(options *ToggleOptions) macaron.Handler { } // Redirect to log in page if auto-signin info is provided and has not signed in. - if !options.SignOutRequired && !ctx.IsSigned && !auth.IsAPIPath(ctx.Req.URL.Path) && + if !options.SignOutRequired && !ctx.IsLogged && !auth.IsAPIPath(ctx.Req.URL.Path) && len(ctx.GetCookie(setting.CookieUserName)) > 0 { ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL) ctx.Redirect(setting.AppSubURL + "/user/login") diff --git a/pkg/context/context.go b/pkg/context/context.go index 1649dc3d..fa4ed16e 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -34,18 +34,20 @@ type Context struct { Session session.Store User *models.User - IsSigned bool + IsLogged bool IsBasicAuth bool Repo *Repository Org *Organization } -func (ctx *Context) UserID() int64 { - if !ctx.IsSigned { +// UserID returns ID of current logged in user. +// It returns 0 if visitor is anonymous. +func (c *Context) UserID() int64 { + if !c.IsLogged { return 0 } - return ctx.User.ID + return c.User.ID } // HasError returns true if error occurs in form validation. @@ -112,7 +114,7 @@ func (ctx *Context) Handle(status int, title string, err error) { case http.StatusInternalServerError: ctx.Data["Title"] = "Internal Server Error" log.Error(2, "%s: %v", title, err) - if !setting.ProdMode || (ctx.IsSigned && ctx.User.IsAdmin) { + if !setting.ProdMode || (ctx.IsLogged && ctx.User.IsAdmin) { ctx.Data["ErrorMsg"] = err } } @@ -193,15 +195,15 @@ func Contexter() macaron.Handler { ctx.User, ctx.IsBasicAuth = auth.SignedInUser(ctx.Context, ctx.Session) if ctx.User != nil { - ctx.IsSigned = true - ctx.Data["IsSigned"] = ctx.IsSigned - ctx.Data["SignedUser"] = ctx.User - ctx.Data["SignedUserID"] = ctx.User.ID - ctx.Data["SignedUserName"] = ctx.User.Name + ctx.IsLogged = true + ctx.Data["IsLogged"] = ctx.IsLogged + ctx.Data["LoggedUser"] = ctx.User + ctx.Data["LoggedUserID"] = ctx.User.ID + ctx.Data["LoggedUserName"] = ctx.User.Name ctx.Data["IsAdmin"] = ctx.User.IsAdmin } else { - ctx.Data["SignedUserID"] = 0 - ctx.Data["SignedUserName"] = "" + ctx.Data["LoggedUserID"] = 0 + ctx.Data["LoggedUserName"] = "" } // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid. diff --git a/pkg/context/org.go b/pkg/context/org.go index 49785674..be0b0572 100644 --- a/pkg/context/org.go +++ b/pkg/context/org.go @@ -63,12 +63,12 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { } // Admin has super access. - if ctx.IsSigned && ctx.User.IsAdmin { + if ctx.IsLogged && ctx.User.IsAdmin { ctx.Org.IsOwner = true ctx.Org.IsMember = true ctx.Org.IsTeamMember = true ctx.Org.IsTeamAdmin = true - } else if ctx.IsSigned { + } else if ctx.IsLogged { ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.ID) if ctx.Org.IsOwner { ctx.Org.IsMember = true diff --git a/pkg/context/repo.go b/pkg/context/repo.go index a1924954..ecaf7ff6 100644 --- a/pkg/context/repo.go +++ b/pkg/context/repo.go @@ -151,7 +151,7 @@ func RepoAssignment(pages ...bool) macaron.Handler { } // Check if the user is the same as the repository owner - if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(ownerName) { + if ctx.IsLogged && ctx.User.LowerName == strings.ToLower(ownerName) { owner = ctx.User } else { owner, err = models.GetUserByName(ownerName) @@ -194,7 +194,7 @@ func RepoAssignment(pages ...bool) macaron.Handler { ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name // Admin has super access. - if ctx.IsSigned && ctx.User.IsAdmin { + if ctx.IsLogged && ctx.User.IsAdmin { ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER } else { mode, err := models.AccessLevel(ctx.UserID(), repo) @@ -278,7 +278,7 @@ func RepoAssignment(pages ...bool) macaron.Handler { ctx.Data["CloneLink"] = repo.CloneLink() ctx.Data["WikiCloneLink"] = repo.WikiCloneLink() - if ctx.IsSigned { + if ctx.IsLogged { ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID) ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID) } @@ -424,7 +424,7 @@ func RepoRef() macaron.Handler { ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit // People who have push access or have fored repository can propose a new pull request. - if ctx.Repo.IsWriter() || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) { + if ctx.Repo.IsWriter() || (ctx.IsLogged && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) { // Pull request is allowed if this is a fork repository // and base repository accepts pull requests. if ctx.Repo.Repository.BaseRepo != nil { @@ -459,7 +459,7 @@ func RepoRef() macaron.Handler { func RequireRepoAdmin() macaron.Handler { return func(ctx *Context) { - if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) { + if !ctx.IsLogged || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) { ctx.NotFound() return } @@ -468,7 +468,7 @@ func RequireRepoAdmin() macaron.Handler { func RequireRepoWriter() macaron.Handler { return func(ctx *Context) { - if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) { + if !ctx.IsLogged || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) { ctx.NotFound() return } |