aboutsummaryrefslogtreecommitdiff
path: root/routes/user/profile.go
diff options
context:
space:
mode:
Diffstat (limited to 'routes/user/profile.go')
-rw-r--r--routes/user/profile.go102
1 files changed, 29 insertions, 73 deletions
diff --git a/routes/user/profile.go b/routes/user/profile.go
index dfdc80d5..3d96f4cb 100644
--- a/routes/user/profile.go
+++ b/routes/user/profile.go
@@ -6,13 +6,11 @@ package user
import (
"fmt"
- "path"
"strings"
"github.com/Unknwon/paginater"
"github.com/gogs/gogs/models"
- "github.com/gogs/gogs/models/errors"
"github.com/gogs/gogs/pkg/context"
"github.com/gogs/gogs/pkg/setting"
"github.com/gogs/gogs/pkg/tool"
@@ -24,59 +22,30 @@ const (
STARS = "user/meta/stars"
)
-func GetUserByName(c *context.Context, name string) *models.User {
- user, err := models.GetUserByName(name)
- if err != nil {
- c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
- return nil
- }
- return user
-}
-
-// GetUserByParams returns user whose name is presented in URL paramenter.
-func GetUserByParams(c *context.Context) *models.User {
- return GetUserByName(c, c.Params(":username"))
-}
-
-func Profile(c *context.Context) {
- uname := c.Params(":username")
- // Special handle for FireFox requests favicon.ico.
- if uname == "favicon.ico" {
- c.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
- return
- } else if strings.HasSuffix(uname, ".png") {
- c.Error(404)
- return
- }
-
+func Profile(c *context.Context, puser *context.ParamsUser) {
isShowKeys := false
- if strings.HasSuffix(uname, ".keys") {
+ if strings.HasSuffix(c.Params(":username"), ".keys") {
isShowKeys = true
}
- ctxUser := GetUserByName(c, strings.TrimSuffix(uname, ".keys"))
- if c.Written() {
- return
- }
-
// Show SSH keys.
if isShowKeys {
- ShowSSHKeys(c, ctxUser.ID)
+ ShowSSHKeys(c, puser.ID)
return
}
- if ctxUser.IsOrganization() {
+ if puser.IsOrganization() {
showOrgProfile(c)
return
}
- c.Data["Title"] = ctxUser.DisplayName()
- c.Data["PageIsUserProfile"] = true
- c.Data["Owner"] = ctxUser
+ c.Title(puser.DisplayName())
+ c.PageIs("UserProfile")
+ c.Data["Owner"] = puser
- orgs, err := models.GetOrgsByUserID(ctxUser.ID, c.IsLogged && (c.User.IsAdmin || c.User.ID == ctxUser.ID))
+ orgs, err := models.GetOrgsByUserID(puser.ID, c.IsLogged && (c.User.IsAdmin || c.User.ID == puser.ID))
if err != nil {
- c.Handle(500, "GetOrgsByUserIDDesc", err)
+ c.ServerError("GetOrgsByUserIDDesc", err)
return
}
@@ -86,7 +55,7 @@ func Profile(c *context.Context) {
c.Data["TabName"] = tab
switch tab {
case "activity":
- retrieveFeeds(c, ctxUser, -1, true)
+ retrieveFeeds(c, puser.User, -1, true)
if c.Written() {
return
}
@@ -96,65 +65,52 @@ func Profile(c *context.Context) {
page = 1
}
- showPrivate := c.IsLogged && (ctxUser.ID == c.User.ID || c.User.IsAdmin)
+ showPrivate := c.IsLogged && (puser.ID == c.User.ID || c.User.IsAdmin)
c.Data["Repos"], err = models.GetUserRepositories(&models.UserRepoOptions{
- UserID: ctxUser.ID,
+ UserID: puser.ID,
Private: showPrivate,
Page: page,
PageSize: setting.UI.User.RepoPagingNum,
})
if err != nil {
- c.Handle(500, "GetRepositories", err)
+ c.ServerError("GetRepositories", err)
return
}
- count := models.CountUserRepositories(ctxUser.ID, showPrivate)
+ count := models.CountUserRepositories(puser.ID, showPrivate)
c.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5)
}
- c.HTML(200, PROFILE)
+ c.Success(PROFILE)
}
-func Followers(c *context.Context) {
- u := GetUserByParams(c)
- if c.Written() {
- return
- }
- c.Data["Title"] = u.DisplayName()
+func Followers(c *context.Context, puser *context.ParamsUser) {
+ c.Title(puser.DisplayName())
+ c.PageIs("Followers")
c.Data["CardsTitle"] = c.Tr("user.followers")
- c.Data["PageIsFollowers"] = true
- c.Data["Owner"] = u
- repo.RenderUserCards(c, u.NumFollowers, u.GetFollowers, FOLLOWERS)
+ c.Data["Owner"] = puser
+ repo.RenderUserCards(c, puser.NumFollowers, puser.GetFollowers, FOLLOWERS)
}
-func Following(c *context.Context) {
- u := GetUserByParams(c)
- if c.Written() {
- return
- }
- c.Data["Title"] = u.DisplayName()
+func Following(c *context.Context, puser *context.ParamsUser) {
+ c.Title(puser.DisplayName())
+ c.PageIs("Following")
c.Data["CardsTitle"] = c.Tr("user.following")
- c.Data["PageIsFollowing"] = true
- c.Data["Owner"] = u
- repo.RenderUserCards(c, u.NumFollowing, u.GetFollowing, FOLLOWERS)
+ c.Data["Owner"] = puser
+ repo.RenderUserCards(c, puser.NumFollowing, puser.GetFollowing, FOLLOWERS)
}
func Stars(c *context.Context) {
}
-func Action(c *context.Context) {
- u := GetUserByParams(c)
- if c.Written() {
- return
- }
-
+func Action(c *context.Context, puser *context.ParamsUser) {
var err error
switch c.Params(":action") {
case "follow":
- err = models.FollowUser(c.User.ID, u.ID)
+ err = models.FollowUser(c.UserID(), puser.ID)
case "unfollow":
- err = models.UnfollowUser(c.User.ID, u.ID)
+ err = models.UnfollowUser(c.UserID(), puser.ID)
}
if err != nil {
@@ -164,7 +120,7 @@ func Action(c *context.Context) {
redirectTo := c.Query("redirect_to")
if !tool.IsSameSiteURLPath(redirectTo) {
- redirectTo = u.HomeLink()
+ redirectTo = puser.HomeLink()
}
c.Redirect(redirectTo)
}