diff --git a/pkg/context/auth.go b/pkg/context/auth.go index d2bfe6035..9ad5cdd0f 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 1649dc3dd..fa4ed16e4 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 497856747..be0b0572b 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 a1924954c..ecaf7ff6c 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 } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index d4aa8aee9..b54e47b7d 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -34,7 +34,7 @@ func repoAssignment() macaron.Handler { ) // Check if the user is the same as the repository owner. - if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { + if ctx.IsLogged && ctx.User.LowerName == strings.ToLower(userName) { owner = ctx.User } else { owner, err = models.GetUserByName(userName) @@ -63,7 +63,7 @@ func repoAssignment() macaron.Handler { return } - 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.User.ID, repo) @@ -86,7 +86,7 @@ func repoAssignment() macaron.Handler { // Contexter middleware already checks token for user sign in process. func reqToken() macaron.Handler { return func(ctx *context.Context) { - if !ctx.IsSigned { + if !ctx.IsLogged { ctx.Error(401) return } @@ -104,7 +104,7 @@ func reqBasicAuth() macaron.Handler { func reqAdmin() macaron.Handler { return func(ctx *context.Context) { - if !ctx.IsSigned || !ctx.User.IsAdmin { + if !ctx.IsLogged || !ctx.User.IsAdmin { ctx.Error(403) return } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index e095954aa..fdb3e7a59 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -28,7 +28,7 @@ func Search(ctx *context.APIContext) { } // Check visibility. - if ctx.IsSigned && opts.OwnerID > 0 { + if ctx.IsLogged && opts.OwnerID > 0 { if ctx.User.ID == opts.OwnerID { opts.Private = true } else { diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index d797c650b..11c3b8bbf 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -41,7 +41,7 @@ func Search(ctx *context.APIContext) { AvatarUrl: users[i].AvatarLink(), FullName: users[i].FullName, } - if ctx.IsSigned { + if ctx.IsLogged { results[i].Email = users[i].Email } } @@ -64,7 +64,7 @@ func GetInfo(ctx *context.APIContext) { } // Hide user e-mail when API caller isn't signed in. - if !ctx.IsSigned { + if !ctx.IsLogged { u.Email = "" } ctx.JSON(200, u.APIFormat()) diff --git a/routers/home.go b/routers/home.go index eaf338155..7d9ee27b7 100644 --- a/routers/home.go +++ b/routers/home.go @@ -21,7 +21,7 @@ const ( ) func Home(ctx *context.Context) { - if ctx.IsSigned { + if ctx.IsLogged { if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { ctx.Data["Title"] = ctx.Tr("auth.active_your_account") ctx.HTML(200, user.ACTIVATE) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 61401b435..72b1a3882 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -70,7 +70,7 @@ func MustAllowPulls(ctx *context.Context) { } // User can send pull request if owns a forked repository. - if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) { + if ctx.IsLogged && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) { ctx.Repo.PullRequest.Allowed = true ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName } @@ -115,7 +115,7 @@ func issues(ctx *context.Context, isPullList bool) { } // Must sign in to see issues about you. - if viewType != "all" && !ctx.IsSigned { + if viewType != "all" && !ctx.IsLogged { ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL) ctx.Redirect(setting.AppSubURL + "/user/login") return @@ -138,7 +138,7 @@ func issues(ctx *context.Context, isPullList bool) { } var uid int64 = -1 - if ctx.IsSigned { + if ctx.IsLogged { uid = ctx.User.ID } @@ -197,7 +197,7 @@ func issues(ctx *context.Context, isPullList bool) { // Get posters. for i := range issues { - if !ctx.IsSigned { + if !ctx.IsLogged { issues[i].IsRead = true continue } @@ -587,7 +587,7 @@ func viewIssue(ctx *context.Context, isPullList bool) { } } - if ctx.IsSigned { + if ctx.IsLogged { // Update issue-user. if err = issue.ReadBy(ctx.User.ID); err != nil { ctx.Handle(500, "ReadBy", err) @@ -652,7 +652,7 @@ func viewIssue(ctx *context.Context, isPullList bool) { ctx.Data["Participants"] = participants ctx.Data["NumParticipants"] = len(participants) ctx.Data["Issue"] = issue - ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID)) + ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsLogged && issue.IsPoster(ctx.User.ID)) ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string) ctx.HTML(200, ISSUE_VIEW) } @@ -687,7 +687,7 @@ func UpdateIssueTitle(ctx *context.Context) { return } - if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) { + if !ctx.IsLogged || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) { ctx.Error(403) return } @@ -714,7 +714,7 @@ func UpdateIssueContent(ctx *context.Context) { return } - if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) { + if !ctx.IsLogged || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) { ctx.Error(403) return } @@ -843,7 +843,7 @@ func NewComment(ctx *context.Context, f form.CreateComment) { var comment *models.Comment defer func() { // Check if issue admin/poster changes the status of issue. - if (ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) && + if (ctx.Repo.IsWriter() || (ctx.IsLogged && issue.IsPoster(ctx.User.ID))) && (f.Status == "reopen" || f.Status == "close") && !(issue.IsPull && issue.PullRequest.HasMerged) { diff --git a/routers/repo/pull.go b/routers/repo/pull.go index b88500e81..15e283d13 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -153,7 +153,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue { return nil } - if ctx.IsSigned { + if ctx.IsLogged { // Update issue-user. if err = issue.ReadBy(ctx.User.ID); err != nil { ctx.Handle(500, "ReadBy", err) diff --git a/routers/user/home.go b/routers/user/home.go index 745c2afac..431c196dd 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -379,7 +379,7 @@ func showOrgProfile(ctx *context.Context) { count int64 err error ) - if ctx.IsSigned && !ctx.User.IsAdmin { + if ctx.IsLogged && !ctx.User.IsAdmin { repos, count, err = org.GetUserRepositories(ctx.User.ID, page, setting.UI.User.RepoPagingNum) if err != nil { ctx.Handle(500, "GetUserRepositories", err) @@ -387,7 +387,7 @@ func showOrgProfile(ctx *context.Context) { } ctx.Data["Repos"] = repos } else { - showPrivate := ctx.IsSigned && ctx.User.IsAdmin + showPrivate := ctx.IsLogged && ctx.User.IsAdmin repos, err = models.GetUserRepositories(&models.UserRepoOptions{ UserID: org.ID, Private: showPrivate, diff --git a/routers/user/profile.go b/routers/user/profile.go index baf9a9412..649814f05 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -73,7 +73,7 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsUserProfile"] = true ctx.Data["Owner"] = ctxUser - orgs, err := models.GetOrgsByUserID(ctxUser.ID, ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID)) + orgs, err := models.GetOrgsByUserID(ctxUser.ID, ctx.IsLogged && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID)) if err != nil { ctx.Handle(500, "GetOrgsByUserIDDesc", err) return @@ -95,7 +95,7 @@ func Profile(ctx *context.Context) { page = 1 } - showPrivate := ctx.IsSigned && (ctxUser.ID == ctx.User.ID || ctx.User.IsAdmin) + showPrivate := ctx.IsLogged && (ctxUser.ID == ctx.User.ID || ctx.User.IsAdmin) ctx.Data["Repos"], err = models.GetUserRepositories(&models.UserRepoOptions{ UserID: ctxUser.ID, Private: showPrivate, diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 33a58eae7..71551ac7a 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -90,7 +90,7 @@ - {{if .IsSigned}} + {{if .IsLogged}} {{.i18n.Tr "dashboard"}} {{.i18n.Tr "issues"}} {{.i18n.Tr "pull_requests"}} @@ -106,7 +106,7 @@ */}} - {{if .IsSigned}} + {{if .IsLogged}}