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.

77 lines
1.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package routers
  5. import (
  6. "fmt"
  7. "github.com/Unknwon/paginater"
  8. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/middleware"
  11. "github.com/gogits/gogs/modules/setting"
  12. "github.com/gogits/gogs/routers/user"
  13. )
  14. const (
  15. HOME base.TplName = "home"
  16. EXPLORE_REPOS base.TplName = "explore/repos"
  17. )
  18. func Home(ctx *middleware.Context) {
  19. if ctx.IsSigned {
  20. if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
  21. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  22. ctx.HTML(200, user.ACTIVATE)
  23. } else {
  24. user.Dashboard(ctx)
  25. }
  26. return
  27. }
  28. // Check auto-login.
  29. uname := ctx.GetCookie(setting.CookieUserName)
  30. if len(uname) != 0 {
  31. ctx.Redirect(setting.AppSubUrl + "/user/login")
  32. return
  33. }
  34. ctx.Data["PageIsHome"] = true
  35. ctx.HTML(200, HOME)
  36. }
  37. func Explore(ctx *middleware.Context) {
  38. ctx.Data["Title"] = ctx.Tr("explore")
  39. ctx.Data["PageIsExplore"] = true
  40. ctx.Data["PageIsExploreRepositories"] = true
  41. page := ctx.QueryInt("page")
  42. if page <= 1 {
  43. page = 1
  44. }
  45. ctx.Data["Page"] = paginater.New(int(models.CountPublicRepositories()), setting.ExplorePagingNum, page, 5)
  46. repos, err := models.GetRecentUpdatedRepositories(page)
  47. if err != nil {
  48. ctx.Handle(500, "GetRecentUpdatedRepositories", err)
  49. return
  50. }
  51. for _, repo := range repos {
  52. if err = repo.GetOwner(); err != nil {
  53. ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
  54. return
  55. }
  56. }
  57. ctx.Data["Repos"] = repos
  58. ctx.HTML(200, EXPLORE_REPOS)
  59. }
  60. func NotFound(ctx *middleware.Context) {
  61. ctx.Data["Title"] = "Page Not Found"
  62. ctx.Handle(404, "home.NotFound", nil)
  63. }