2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/locale"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
"miniflux.app/v2/internal/ui/form"
|
|
|
|
"miniflux.app/v2/internal/ui/session"
|
|
|
|
"miniflux.app/v2/internal/ui/view"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) showSettingsPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settingsForm := form.SettingsForm{
|
2022-10-26 05:00:56 +02:00
|
|
|
Username: user.Username,
|
|
|
|
Theme: user.Theme,
|
|
|
|
Language: user.Language,
|
|
|
|
Timezone: user.Timezone,
|
|
|
|
EntryDirection: user.EntryDirection,
|
|
|
|
EntryOrder: user.EntryOrder,
|
|
|
|
EntriesPerPage: user.EntriesPerPage,
|
|
|
|
KeyboardShortcuts: user.KeyboardShortcuts,
|
|
|
|
ShowReadingTime: user.ShowReadingTime,
|
|
|
|
CustomCSS: user.Stylesheet,
|
|
|
|
EntrySwipe: user.EntrySwipe,
|
2022-09-30 07:37:57 +02:00
|
|
|
GestureNav: user.GestureNav,
|
2022-10-26 05:00:56 +02:00
|
|
|
DisplayMode: user.DisplayMode,
|
|
|
|
DefaultReadingSpeed: user.DefaultReadingSpeed,
|
|
|
|
CJKReadingSpeed: user.CJKReadingSpeed,
|
|
|
|
DefaultHomePage: user.DefaultHomePage,
|
|
|
|
CategoriesSortingOrder: user.CategoriesSortingOrder,
|
2023-03-17 14:56:17 +01:00
|
|
|
MarkReadOnView: user.MarkReadOnView,
|
2024-03-16 14:20:02 +01:00
|
|
|
MediaPlaybackRate: user.MediaPlaybackRate,
|
2024-07-03 06:03:49 +02:00
|
|
|
BlockFilterEntryRules: user.BlockFilterEntryRules,
|
|
|
|
KeepFilterEntryRules: user.KeepFilterEntryRules,
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
timezones, err := h.store.Timezones()
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-05 18:57:35 +01:00
|
|
|
creds, err := h.store.WebAuthnCredentialsByUserID(user.ID)
|
|
|
|
if err != nil {
|
|
|
|
html.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-04 00:32:16 +01:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-30 01:35:04 +02:00
|
|
|
view.Set("form", settingsForm)
|
|
|
|
view.Set("themes", model.Themes())
|
|
|
|
view.Set("languages", locale.AvailableLanguages())
|
|
|
|
view.Set("timezones", timezones)
|
|
|
|
view.Set("menu", "settings")
|
|
|
|
view.Set("user", user)
|
2018-11-11 20:28:29 +01:00
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
2020-09-28 01:01:06 +02:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2022-07-20 22:07:55 +02:00
|
|
|
view.Set("default_home_pages", model.HomePages())
|
2022-10-26 05:00:56 +02:00
|
|
|
view.Set("categories_sorting_options", model.CategoriesSortingOptions())
|
2023-11-05 18:57:35 +01:00
|
|
|
view.Set("countWebAuthnCerts", h.store.CountWebAuthnCredentialsByUserID(user.ID))
|
|
|
|
view.Set("webAuthnCerts", creds)
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2018-07-07 05:39:28 +02:00
|
|
|
html.OK(w, r, view.Render("settings"))
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|