home.go 1.8 KB

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