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 session // import "miniflux.app/v2/internal/ui/session"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/storage"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Session handles session data.
|
|
|
|
type Session struct {
|
2018-09-03 23:26:40 +02:00
|
|
|
store *storage.Storage
|
|
|
|
sessionID string
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2023-09-03 06:35:10 +02:00
|
|
|
func (s *Session) SetOAuth2State(state string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "oauth2_state", state)
|
2023-09-03 06:35:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) SetOAuth2CodeVerifier(codeVerfier string) {
|
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "oauth2_code_verifier", codeVerfier)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewFlashMessage creates a new flash message.
|
|
|
|
func (s *Session) NewFlashMessage(message string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_message", message)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FlashMessage returns the current flash message if any.
|
2018-09-03 23:26:40 +02:00
|
|
|
func (s *Session) FlashMessage(message string) string {
|
2018-04-30 01:35:04 +02:00
|
|
|
if message != "" {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_message", "")
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFlashErrorMessage creates a new flash error message.
|
|
|
|
func (s *Session) NewFlashErrorMessage(message string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_error_message", message)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FlashErrorMessage returns the last flash error message if any.
|
2018-09-03 23:26:40 +02:00
|
|
|
func (s *Session) FlashErrorMessage(message string) string {
|
2018-04-30 01:35:04 +02:00
|
|
|
if message != "" {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_error_message", "")
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
2018-07-19 07:30:05 +02:00
|
|
|
// SetLanguage updates the language field in session.
|
2018-04-30 01:35:04 +02:00
|
|
|
func (s *Session) SetLanguage(language string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "language", language)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-07-19 07:30:05 +02:00
|
|
|
// SetTheme updates the theme field in session.
|
|
|
|
func (s *Session) SetTheme(theme string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "theme", theme)
|
2018-07-19 07:30:05 +02:00
|
|
|
}
|
|
|
|
|
2018-05-21 00:29:14 +02:00
|
|
|
// SetPocketRequestToken updates Pocket Request Token.
|
|
|
|
func (s *Session) SetPocketRequestToken(requestToken string) {
|
2019-01-22 05:21:05 +01:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "pocket_request_token", requestToken)
|
2018-05-21 00:29:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
// New returns a new session handler.
|
2018-09-03 23:26:40 +02:00
|
|
|
func New(store *storage.Storage, sessionID string) *Session {
|
|
|
|
return &Session{store, sessionID}
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|