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.
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
package ui
|
2017-11-22 04:37:47 +01:00
|
|
|
|
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
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
"github.com/miniflux/miniflux/http/handler"
|
|
|
|
"github.com/miniflux/miniflux/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.
|
2018-01-03 07:04:48 +01:00
|
|
|
func (c *Controller) ShowIntegrations(ctx *handler.Context, request *handler.Request, response *handler.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-19 05:52:46 +01:00
|
|
|
WallabagEnabled: integration.WallabagEnabled,
|
|
|
|
WallabagURL: integration.WallabagURL,
|
|
|
|
WallabagClientID: integration.WallabagClientID,
|
|
|
|
WallabagClientSecret: integration.WallabagClientSecret,
|
|
|
|
WallabagUsername: integration.WallabagUsername,
|
|
|
|
WallabagPassword: integration.WallabagPassword,
|
2018-02-25 20:49:08 +01:00
|
|
|
NunuxKeeperEnabled: integration.NunuxKeeperEnabled,
|
|
|
|
NunuxKeeperURL: integration.NunuxKeeperURL,
|
|
|
|
NunuxKeeperAPIKey: integration.NunuxKeeperAPIKey,
|
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.
|
2018-01-03 07:04:48 +01:00
|
|
|
func (c *Controller) UpdateIntegration(ctx *handler.Context, request *handler.Request, response *handler.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
|
|
|
|
}
|
|
|
|
|
|
|
|
integrationForm := form.NewIntegrationForm(request.Request())
|
|
|
|
integrationForm.Merge(integration)
|
|
|
|
|
2017-12-29 23:38:43 +01:00
|
|
|
if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
|
|
|
|
ctx.SetFlashErrorMessage(ctx.Translate("There is already someone else with the same Fever username!"))
|
|
|
|
response.Redirect(ctx.Route("integrations"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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"))
|
|
|
|
}
|