mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
3.7 KiB
164 lines
3.7 KiB
11 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
8 years ago
|
package routes
|
||
11 years ago
|
|
||
11 years ago
|
import (
|
||
9 years ago
|
"github.com/Unknwon/paginater"
|
||
|
|
||
10 years ago
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
|
"github.com/gogits/gogs/pkg/setting"
|
||
8 years ago
|
"github.com/gogits/gogs/routes/user"
|
||
11 years ago
|
)
|
||
|
|
||
11 years ago
|
const (
|
||
8 years ago
|
HOME = "home"
|
||
|
EXPLORE_REPOS = "explore/repos"
|
||
|
EXPLORE_USERS = "explore/users"
|
||
|
EXPLORE_ORGANIZATIONS = "explore/organizations"
|
||
11 years ago
|
)
|
||
|
|
||
8 years ago
|
func Home(c *context.Context) {
|
||
|
if c.IsLogged {
|
||
|
if !c.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||
|
c.Data["Title"] = c.Tr("auth.active_your_account")
|
||
|
c.HTML(200, user.ACTIVATE)
|
||
10 years ago
|
} else {
|
||
8 years ago
|
user.Dashboard(c)
|
||
10 years ago
|
}
|
||
11 years ago
|
return
|
||
|
}
|
||
11 years ago
|
|
||
|
// Check auto-login.
|
||
8 years ago
|
uname := c.GetCookie(setting.CookieUserName)
|
||
10 years ago
|
if len(uname) != 0 {
|
||
8 years ago
|
c.Redirect(setting.AppSubURL + "/user/login")
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.Data["PageIsHome"] = true
|
||
|
c.HTML(200, HOME)
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
8 years ago
|
func ExploreRepos(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("explore")
|
||
|
c.Data["PageIsExplore"] = true
|
||
|
c.Data["PageIsExploreRepositories"] = true
|
||
9 years ago
|
|
||
8 years ago
|
page := c.QueryInt("page")
|
||
8 years ago
|
if page <= 0 {
|
||
9 years ago
|
page = 1
|
||
|
}
|
||
|
|
||
8 years ago
|
keyword := c.Query("q")
|
||
8 years ago
|
repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||
|
Keyword: keyword,
|
||
8 years ago
|
UserID: c.UserID(),
|
||
8 years ago
|
OrderBy: "updated_unix DESC",
|
||
|
Page: page,
|
||
|
PageSize: setting.UI.ExplorePagingNum,
|
||
|
})
|
||
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "SearchRepositoryByName", err)
|
||
8 years ago
|
return
|
||
10 years ago
|
}
|
||
8 years ago
|
c.Data["Keyword"] = keyword
|
||
|
c.Data["Total"] = count
|
||
|
c.Data["Page"] = paginater.New(int(count), setting.UI.ExplorePagingNum, page, 5)
|
||
9 years ago
|
|
||
8 years ago
|
if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
|
||
8 years ago
|
c.Handle(500, "LoadAttributes", err)
|
||
8 years ago
|
return
|
||
10 years ago
|
}
|
||
8 years ago
|
c.Data["Repos"] = repos
|
||
10 years ago
|
|
||
8 years ago
|
c.HTML(200, EXPLORE_REPOS)
|
||
9 years ago
|
}
|
||
|
|
||
|
type UserSearchOptions struct {
|
||
|
Type models.UserType
|
||
|
Counter func() int64
|
||
|
Ranger func(int, int) ([]*models.User, error)
|
||
|
PageSize int
|
||
|
OrderBy string
|
||
8 years ago
|
TplName string
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func RenderUserSearch(c *context.Context, opts *UserSearchOptions) {
|
||
|
page := c.QueryInt("page")
|
||
9 years ago
|
if page <= 1 {
|
||
|
page = 1
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
users []*models.User
|
||
|
count int64
|
||
|
err error
|
||
|
)
|
||
|
|
||
8 years ago
|
keyword := c.Query("q")
|
||
9 years ago
|
if len(keyword) == 0 {
|
||
9 years ago
|
users, err = opts.Ranger(page, opts.PageSize)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "opts.Ranger", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
9 years ago
|
count = opts.Counter()
|
||
9 years ago
|
} else {
|
||
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
|
||
|
Keyword: keyword,
|
||
9 years ago
|
Type: opts.Type,
|
||
|
OrderBy: opts.OrderBy,
|
||
9 years ago
|
Page: page,
|
||
9 years ago
|
PageSize: opts.PageSize,
|
||
9 years ago
|
})
|
||
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "SearchUserByName", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
}
|
||
8 years ago
|
c.Data["Keyword"] = keyword
|
||
|
c.Data["Total"] = count
|
||
|
c.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
|
||
|
c.Data["Users"] = users
|
||
9 years ago
|
|
||
8 years ago
|
c.HTML(200, opts.TplName)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ExploreUsers(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("explore")
|
||
|
c.Data["PageIsExplore"] = true
|
||
|
c.Data["PageIsExploreUsers"] = true
|
||
9 years ago
|
|
||
8 years ago
|
RenderUserSearch(c, &UserSearchOptions{
|
||
9 years ago
|
Type: models.USER_TYPE_INDIVIDUAL,
|
||
|
Counter: models.CountUsers,
|
||
|
Ranger: models.Users,
|
||
8 years ago
|
PageSize: setting.UI.ExplorePagingNum,
|
||
9 years ago
|
OrderBy: "updated_unix DESC",
|
||
|
TplName: EXPLORE_USERS,
|
||
|
})
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
func ExploreOrganizations(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("explore")
|
||
|
c.Data["PageIsExplore"] = true
|
||
|
c.Data["PageIsExploreOrganizations"] = true
|
||
8 years ago
|
|
||
8 years ago
|
RenderUserSearch(c, &UserSearchOptions{
|
||
8 years ago
|
Type: models.USER_TYPE_ORGANIZATION,
|
||
|
Counter: models.CountOrganizations,
|
||
|
Ranger: models.Organizations,
|
||
|
PageSize: setting.UI.ExplorePagingNum,
|
||
|
OrderBy: "updated_unix DESC",
|
||
|
TplName: EXPLORE_ORGANIZATIONS,
|
||
|
})
|
||
|
}
|
||
|
|
||
8 years ago
|
func NotFound(c *context.Context) {
|
||
|
c.Data["Title"] = "Page Not Found"
|
||
|
c.NotFound()
|
||
11 years ago
|
}
|