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.

82 lines
1.9 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. if setting.OauthService != nil {
  35. ctx.Data["OauthEnabled"] = true
  36. ctx.Data["OauthService"] = setting.OauthService
  37. }
  38. ctx.Data["PageIsHome"] = true
  39. ctx.HTML(200, HOME)
  40. }
  41. func Explore(ctx *middleware.Context) {
  42. ctx.Data["Title"] = ctx.Tr("explore")
  43. ctx.Data["PageIsExplore"] = true
  44. ctx.Data["PageIsExploreRepositories"] = true
  45. page := ctx.QueryInt("page")
  46. if page <= 1 {
  47. page = 1
  48. }
  49. ctx.Data["Page"] = paginater.New(int(models.CountPublicRepositories()), setting.ExplorePagingNum, page, 5)
  50. repos, err := models.GetRecentUpdatedRepositories(page)
  51. if err != nil {
  52. ctx.Handle(500, "GetRecentUpdatedRepositories", err)
  53. return
  54. }
  55. for _, repo := range repos {
  56. if err = repo.GetOwner(); err != nil {
  57. ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
  58. return
  59. }
  60. }
  61. ctx.Data["Repos"] = repos
  62. ctx.HTML(200, EXPLORE_REPOS)
  63. }
  64. func NotFound(ctx *middleware.Context) {
  65. ctx.Data["Title"] = "Page Not Found"
  66. ctx.Handle(404, "home.NotFound", nil)
  67. }