home.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/middleware"
  10. "github.com/gogits/gogs/modules/setting"
  11. "github.com/gogits/gogs/routers/user"
  12. )
  13. const (
  14. HOME base.TplName = "home"
  15. EXPLORE_REPOS base.TplName = "explore/repos"
  16. HELP base.TplName = "help"
  17. ABOUT base.TplName = "about"
  18. TOS base.TplName = "tos"
  19. OUTAGES base.TplName = "outages"
  20. )
  21. func Home(ctx *middleware.Context) {
  22. if ctx.IsSigned {
  23. if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
  24. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  25. ctx.HTML(200, user.ACTIVATE)
  26. } else {
  27. user.Dashboard(ctx)
  28. }
  29. return
  30. }
  31. // Check auto-login.
  32. uname := ctx.GetCookie(setting.CookieUserName)
  33. if len(uname) != 0 {
  34. ctx.Redirect(setting.AppSubUrl + "/user/login")
  35. return
  36. }
  37. if setting.OauthService != nil {
  38. ctx.Data["OauthEnabled"] = true
  39. ctx.Data["OauthService"] = setting.OauthService
  40. }
  41. ctx.Data["PageIsHome"] = true
  42. ctx.HTML(200, HOME)
  43. }
  44. func Explore(ctx *middleware.Context) {
  45. ctx.Data["Title"] = ctx.Tr("explore")
  46. ctx.Data["PageIsExploreRepositories"] = true
  47. repos, err := models.GetRecentUpdatedRepositories(20)
  48. if err != nil {
  49. ctx.Handle(500, "GetRecentUpdatedRepositories", err)
  50. return
  51. }
  52. for _, repo := range repos {
  53. if err = repo.GetOwner(); err != nil {
  54. ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.Id, err))
  55. return
  56. }
  57. }
  58. ctx.Data["Repos"] = repos
  59. ctx.HTML(200, EXPLORE_REPOS)
  60. }
  61. func Help(ctx *middleware.Context) {
  62. ctx.Data["Title"] = ctx.Tr("help")
  63. ctx.HTML(200, HELP)
  64. }
  65. func About(ctx *middleware.Context) {
  66. ctx.Data["Title"] = ctx.Tr("about")
  67. ctx.HTML(200, ABOUT)
  68. }
  69. func Tos(ctx *middleware.Context) {
  70. ctx.Data["Title"] = ctx.Tr("tos")
  71. ctx.HTML(200, TOS)
  72. }
  73. func Outages(ctx *middleware.Context) {
  74. ctx.Data["Title"] = ctx.Tr("outages")
  75. ctx.HTML(200, OUTAGES)
  76. }
  77. func NotFound(ctx *middleware.Context) {
  78. ctx.Data["Title"] = "Page Not Found"
  79. ctx.Handle(404, "home.NotFound", nil)
  80. }