integrations.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "crypto/md5"
  7. "fmt"
  8. "github.com/miniflux/miniflux/http/handler"
  9. "github.com/miniflux/miniflux/ui/form"
  10. )
  11. // ShowIntegrations renders the page with all external integrations.
  12. func (c *Controller) ShowIntegrations(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  13. user := ctx.LoggedUser()
  14. integration, err := c.store.Integration(user.ID)
  15. if err != nil {
  16. response.HTML().ServerError(err)
  17. return
  18. }
  19. args, err := c.getCommonTemplateArgs(ctx)
  20. if err != nil {
  21. response.HTML().ServerError(err)
  22. return
  23. }
  24. response.HTML().Render("integrations", args.Merge(tplParams{
  25. "menu": "settings",
  26. "form": form.IntegrationForm{
  27. PinboardEnabled: integration.PinboardEnabled,
  28. PinboardToken: integration.PinboardToken,
  29. PinboardTags: integration.PinboardTags,
  30. PinboardMarkAsUnread: integration.PinboardMarkAsUnread,
  31. InstapaperEnabled: integration.InstapaperEnabled,
  32. InstapaperUsername: integration.InstapaperUsername,
  33. InstapaperPassword: integration.InstapaperPassword,
  34. FeverEnabled: integration.FeverEnabled,
  35. FeverUsername: integration.FeverUsername,
  36. FeverPassword: integration.FeverPassword,
  37. WallabagEnabled: integration.WallabagEnabled,
  38. WallabagURL: integration.WallabagURL,
  39. WallabagClientID: integration.WallabagClientID,
  40. WallabagClientSecret: integration.WallabagClientSecret,
  41. WallabagUsername: integration.WallabagUsername,
  42. WallabagPassword: integration.WallabagPassword,
  43. NunuxKeeperEnabled: integration.NunuxKeeperEnabled,
  44. NunuxKeeperURL: integration.NunuxKeeperURL,
  45. NunuxKeeperAPIKey: integration.NunuxKeeperAPIKey,
  46. },
  47. }))
  48. }
  49. // UpdateIntegration updates integration settings.
  50. func (c *Controller) UpdateIntegration(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  51. user := ctx.LoggedUser()
  52. integration, err := c.store.Integration(user.ID)
  53. if err != nil {
  54. response.HTML().ServerError(err)
  55. return
  56. }
  57. integrationForm := form.NewIntegrationForm(request.Request())
  58. integrationForm.Merge(integration)
  59. if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
  60. ctx.SetFlashErrorMessage(ctx.Translate("There is already someone else with the same Fever username!"))
  61. response.Redirect(ctx.Route("integrations"))
  62. return
  63. }
  64. if integration.FeverEnabled {
  65. integration.FeverToken = fmt.Sprintf("%x", md5.Sum([]byte(integration.FeverUsername+":"+integration.FeverPassword)))
  66. } else {
  67. integration.FeverToken = ""
  68. }
  69. err = c.store.UpdateIntegration(integration)
  70. if err != nil {
  71. response.HTML().ServerError(err)
  72. return
  73. }
  74. response.Redirect(ctx.Route("integrations"))
  75. }