|
|
@@ -3,12 +3,10 @@ package user
|
|
|
import (
|
|
|
"fmt"
|
|
|
"gitote/gitote/models"
|
|
|
- "gitote/gitote/models/errors"
|
|
|
"gitote/gitote/pkg/context"
|
|
|
"gitote/gitote/pkg/setting"
|
|
|
"gitote/gitote/pkg/tool"
|
|
|
"gitote/gitote/routes/repo"
|
|
|
- "path"
|
|
|
"strings"
|
|
|
|
|
|
"gitlab.com/yoginth/paginater"
|
|
|
@@ -19,59 +17,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
|
|
|
}
|
|
|
|
|
|
@@ -81,7 +50,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
|
|
|
}
|
|
|
@@ -91,68 +60,55 @@ 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)
|
|
|
}
|
|
|
- if ctxUser.Suspended == true {
|
|
|
+ if puser.Suspended == true {
|
|
|
c.Handle(404, "Suspended", err)
|
|
|
} else {
|
|
|
- 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 {
|
|
|
@@ -162,7 +118,7 @@ func Action(c *context.Context) {
|
|
|
|
|
|
redirectTo := c.Query("redirect_to")
|
|
|
if !tool.IsSameSiteURLPath(redirectTo) {
|
|
|
- redirectTo = u.HomeLink()
|
|
|
+ redirectTo = puser.HomeLink()
|
|
|
}
|
|
|
c.Redirect(redirectTo)
|
|
|
}
|