miniflux/server/ui/controller/integrations.go

73 lines
2.1 KiB
Go
Raw Normal View History

2017-11-22 04:37:47 +01:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package controller
2017-12-03 04:32:14 +01:00
import (
2017-12-04 02:44:27 +01:00
"crypto/md5"
"fmt"
2017-12-03 04:32:14 +01:00
2017-12-13 06:48:13 +01:00
"github.com/miniflux/miniflux/server/core"
"github.com/miniflux/miniflux/server/ui/form"
2017-12-03 04:32:14 +01:00
)
2017-11-22 04:37:47 +01:00
// ShowIntegrations renders the page with all external integrations.
func (c *Controller) ShowIntegrations(ctx *core.Context, request *core.Request, response *core.Response) {
2017-12-03 04:32:14 +01:00
user := ctx.LoggedUser()
integration, err := c.store.Integration(user.ID)
if err != nil {
response.HTML().ServerError(err)
return
}
2017-11-22 04:37:47 +01:00
args, err := c.getCommonTemplateArgs(ctx)
if err != nil {
response.HTML().ServerError(err)
return
}
response.HTML().Render("integrations", args.Merge(tplParams{
"menu": "settings",
2017-12-03 04:32:14 +01:00
"form": form.IntegrationForm{
PinboardEnabled: integration.PinboardEnabled,
PinboardToken: integration.PinboardToken,
PinboardTags: integration.PinboardTags,
PinboardMarkAsUnread: integration.PinboardMarkAsUnread,
2017-12-03 06:12:03 +01:00
InstapaperEnabled: integration.InstapaperEnabled,
InstapaperUsername: integration.InstapaperUsername,
InstapaperPassword: integration.InstapaperPassword,
2017-12-04 02:44:27 +01:00
FeverEnabled: integration.FeverEnabled,
FeverUsername: integration.FeverUsername,
FeverPassword: integration.FeverPassword,
2017-12-03 04:32:14 +01:00
},
2017-11-22 04:37:47 +01:00
}))
}
2017-12-03 04:32:14 +01:00
// UpdateIntegration updates integration settings.
func (c *Controller) UpdateIntegration(ctx *core.Context, request *core.Request, response *core.Response) {
user := ctx.LoggedUser()
integration, err := c.store.Integration(user.ID)
if err != nil {
response.HTML().ServerError(err)
return
}
integrationForm := form.NewIntegrationForm(request.Request())
integrationForm.Merge(integration)
2017-12-04 02:44:27 +01:00
if integration.FeverEnabled {
integration.FeverToken = fmt.Sprintf("%x", md5.Sum([]byte(integration.FeverUsername+":"+integration.FeverPassword)))
} else {
integration.FeverToken = ""
}
2017-12-03 04:32:14 +01:00
err = c.store.UpdateIntegration(integration)
if err != nil {
response.HTML().ServerError(err)
return
}
response.Redirect(ctx.Route("integrations"))
}