integrations.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. },
  38. }))
  39. }
  40. // UpdateIntegration updates integration settings.
  41. func (c *Controller) UpdateIntegration(ctx *core.Context, request *core.Request, response *core.Response) {
  42. user := ctx.LoggedUser()
  43. integration, err := c.store.Integration(user.ID)
  44. if err != nil {
  45. response.HTML().ServerError(err)
  46. return
  47. }
  48. integrationForm := form.NewIntegrationForm(request.Request())
  49. integrationForm.Merge(integration)
  50. if integration.FeverEnabled {
  51. integration.FeverToken = fmt.Sprintf("%x", md5.Sum([]byte(integration.FeverUsername+":"+integration.FeverPassword)))
  52. } else {
  53. integration.FeverToken = ""
  54. }
  55. err = c.store.UpdateIntegration(integration)
  56. if err != nil {
  57. response.HTML().ServerError(err)
  58. return
  59. }
  60. response.Redirect(ctx.Route("integrations"))
  61. }