You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

home.go 1.9 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.CountRepositories()), 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. }