integrations.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 controller
  5. import (
  6. "crypto/md5"
  7. "fmt"
  8. "github.com/miniflux/miniflux/server/core"
  9. "github.com/miniflux/miniflux/server/ui/form"
  10. )
  11. // ShowIntegrations renders the page with all external integrations.
  12. func (c *Controller) ShowIntegrations(ctx *core.Context, request *core.Request, response *core.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. },
  44. }))
  45. }
  46. // UpdateIntegration updates integration settings.
  47. func (c *Controller) UpdateIntegration(ctx *core.Context, request *core.Request, response *core.Response) {
  48. user := ctx.LoggedUser()
  49. integration, err := c.store.Integration(user.ID)
  50. if err != nil {
  51. response.HTML().ServerError(err)
  52. return
  53. }
  54. integrationForm := form.NewIntegrationForm(request.Request())
  55. integrationForm.Merge(integration)
  56. if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
  57. ctx.SetFlashErrorMessage(ctx.Translate("There is already someone else with the same Fever username!"))
  58. response.Redirect(ctx.Route("integrations"))
  59. return
  60. }
  61. if integration.FeverEnabled {
  62. integration.FeverToken = fmt.Sprintf("%x", md5.Sum([]byte(integration.FeverUsername+":"+integration.FeverPassword)))
  63. } else {
  64. integration.FeverToken = ""
  65. }
  66. err = c.store.UpdateIntegration(integration)
  67. if err != nil {
  68. response.HTML().ServerError(err)
  69. return
  70. }
  71. response.Redirect(ctx.Route("integrations"))
  72. }