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.

109 lines
2.9 KiB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 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 setting
  6. import (
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. const (
  13. tplSettingsSecurity base.TplName = "user/settings/security"
  14. tplSettingsTwofaEnroll base.TplName = "user/settings/twofa_enroll"
  15. )
  16. // Security render change user's password page and 2FA
  17. func Security(ctx *context.Context) {
  18. ctx.Data["Title"] = ctx.Tr("settings")
  19. ctx.Data["PageIsSettingsSecurity"] = true
  20. if ctx.Query("openid.return_to") != "" {
  21. settingsOpenIDVerify(ctx)
  22. return
  23. }
  24. loadSecurityData(ctx)
  25. ctx.HTML(200, tplSettingsSecurity)
  26. }
  27. // DeleteAccountLink delete a single account link
  28. func DeleteAccountLink(ctx *context.Context) {
  29. id := ctx.QueryInt64("id")
  30. if id <= 0 {
  31. ctx.Flash.Error("Account link id is not given")
  32. } else {
  33. if _, err := models.RemoveAccountLink(ctx.User, id); err != nil {
  34. ctx.Flash.Error("RemoveAccountLink: " + err.Error())
  35. } else {
  36. ctx.Flash.Success(ctx.Tr("settings.remove_account_link_success"))
  37. }
  38. }
  39. ctx.JSON(200, map[string]interface{}{
  40. "redirect": setting.AppSubURL + "/user/settings/security",
  41. })
  42. }
  43. func loadSecurityData(ctx *context.Context) {
  44. enrolled := true
  45. _, err := models.GetTwoFactorByUID(ctx.User.ID)
  46. if err != nil {
  47. if models.IsErrTwoFactorNotEnrolled(err) {
  48. enrolled = false
  49. } else {
  50. ctx.ServerError("SettingsTwoFactor", err)
  51. return
  52. }
  53. }
  54. ctx.Data["TwofaEnrolled"] = enrolled
  55. if enrolled {
  56. ctx.Data["U2FRegistrations"], err = models.GetU2FRegistrationsByUID(ctx.User.ID)
  57. if err != nil {
  58. ctx.ServerError("GetU2FRegistrationsByUID", err)
  59. return
  60. }
  61. ctx.Data["RequireU2F"] = true
  62. }
  63. tokens, err := models.ListAccessTokens(ctx.User.ID, models.ListOptions{})
  64. if err != nil {
  65. ctx.ServerError("ListAccessTokens", err)
  66. return
  67. }
  68. ctx.Data["Tokens"] = tokens
  69. accountLinks, err := models.ListAccountLinks(ctx.User)
  70. if err != nil {
  71. ctx.ServerError("ListAccountLinks", err)
  72. return
  73. }
  74. // map the provider display name with the LoginSource
  75. sources := make(map[*models.LoginSource]string)
  76. for _, externalAccount := range accountLinks {
  77. if loginSource, err := models.GetLoginSourceByID(externalAccount.LoginSourceID); err == nil {
  78. var providerDisplayName string
  79. if loginSource.IsOAuth2() {
  80. providerTechnicalName := loginSource.OAuth2().Provider
  81. providerDisplayName = models.OAuth2Providers[providerTechnicalName].DisplayName
  82. } else {
  83. providerDisplayName = loginSource.Name
  84. }
  85. sources[loginSource] = providerDisplayName
  86. }
  87. }
  88. ctx.Data["AccountLinks"] = sources
  89. openid, err := models.GetUserOpenIDs(ctx.User.ID)
  90. if err != nil {
  91. ctx.ServerError("GetUserOpenIDs", err)
  92. return
  93. }
  94. ctx.Data["OpenIDs"] = openid
  95. }