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.

55 lines
1.2 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
10 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. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/base"
  8. "github.com/gogits/gogs/modules/middleware"
  9. "github.com/gogits/gogs/modules/setting"
  10. "github.com/gogits/gogs/routers/user"
  11. )
  12. const (
  13. HOME base.TplName = "home"
  14. )
  15. func Home(ctx *middleware.Context) {
  16. if ctx.IsSigned {
  17. user.Dashboard(ctx)
  18. return
  19. }
  20. // Check auto-login.
  21. userName := ctx.GetCookie(setting.CookieUserName)
  22. if len(userName) != 0 {
  23. ctx.Redirect("/user/login")
  24. return
  25. }
  26. ctx.Data["PageIsHome"] = true
  27. // Show recent updated repositories for new visitors.
  28. repos, err := models.GetRecentUpdatedRepositories()
  29. if err != nil {
  30. ctx.Handle(500, "dashboard.Home(GetRecentUpdatedRepositories)", err)
  31. return
  32. }
  33. for _, repo := range repos {
  34. if err = repo.GetOwner(); err != nil {
  35. ctx.Handle(500, "dashboard.Home(GetOwner)", err)
  36. return
  37. }
  38. }
  39. ctx.Data["Repos"] = repos
  40. ctx.HTML(200, HOME)
  41. }
  42. func NotFound(ctx *middleware.Context) {
  43. ctx.Data["Title"] = "Page Not Found"
  44. ctx.Data["PageIsNotFound"] = true
  45. ctx.Handle(404, "home.NotFound", nil)
  46. }