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.

home.go 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package web
  6. import (
  7. "net/http"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. "code.gitea.io/gitea/modules/web/middleware"
  13. "code.gitea.io/gitea/routers/web/user"
  14. )
  15. const (
  16. // tplHome home page template
  17. tplHome base.TplName = "home"
  18. )
  19. // Home render home page
  20. func Home(ctx *context.Context) {
  21. if ctx.IsSigned {
  22. if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
  23. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  24. ctx.HTML(http.StatusOK, user.TplActivate)
  25. } else if !ctx.User.IsActive || ctx.User.ProhibitLogin {
  26. log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
  27. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  28. ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
  29. } else if ctx.User.MustChangePassword {
  30. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  31. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
  32. middleware.SetRedirectToCookie(ctx.Resp, setting.AppSubURL+ctx.Req.URL.RequestURI())
  33. ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
  34. } else {
  35. user.Dashboard(ctx)
  36. }
  37. return
  38. // Check non-logged users landing page.
  39. } else if setting.LandingPageURL != setting.LandingPageHome {
  40. ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
  41. return
  42. }
  43. // Check auto-login.
  44. uname := ctx.GetCookie(setting.CookieUserName)
  45. if len(uname) != 0 {
  46. ctx.Redirect(setting.AppSubURL + "/user/login")
  47. return
  48. }
  49. ctx.Data["PageIsHome"] = true
  50. ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
  51. ctx.HTML(http.StatusOK, tplHome)
  52. }
  53. // NotFound render 404 page
  54. func NotFound(ctx *context.Context) {
  55. ctx.Data["Title"] = "Page Not Found"
  56. ctx.NotFound("home.NotFound", nil)
  57. }