2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package session // import "miniflux.app/v2/internal/ui/session"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
2023-10-20 18:12:02 -04:00
|
|
|
"time"
|
|
|
|
|
2023-11-05 12:57:35 -05:00
|
|
|
"miniflux.app/v2/internal/model"
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/storage"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Session handles session data.
|
|
|
|
type Session struct {
|
2018-09-03 17:26:40 -04:00
|
|
|
store *storage.Storage
|
|
|
|
sessionID string
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
// New returns a new session handler.
|
|
|
|
func New(store *storage.Storage, sessionID string) *Session {
|
|
|
|
return &Session{store, sessionID}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) SetLastForceRefresh() {
|
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "last_force_refresh", time.Now().UTC().Unix())
|
|
|
|
}
|
|
|
|
|
2023-09-03 00:35:10 -04:00
|
|
|
func (s *Session) SetOAuth2State(state string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "oauth2_state", state)
|
2023-09-03 00:35:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) SetOAuth2CodeVerifier(codeVerfier string) {
|
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "oauth2_code_verifier", codeVerfier)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewFlashMessage creates a new flash message.
|
|
|
|
func (s *Session) NewFlashMessage(message string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_message", message)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FlashMessage returns the current flash message if any.
|
2018-09-03 17:26:40 -04:00
|
|
|
func (s *Session) FlashMessage(message string) string {
|
2018-04-29 19:35:04 -04:00
|
|
|
if message != "" {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_message", "")
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFlashErrorMessage creates a new flash error message.
|
|
|
|
func (s *Session) NewFlashErrorMessage(message string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_error_message", message)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FlashErrorMessage returns the last flash error message if any.
|
2018-09-03 17:26:40 -04:00
|
|
|
func (s *Session) FlashErrorMessage(message string) string {
|
2018-04-29 19:35:04 -04:00
|
|
|
if message != "" {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "flash_error_message", "")
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
2018-07-19 01:30:05 -04:00
|
|
|
// SetLanguage updates the language field in session.
|
2018-04-29 19:35:04 -04:00
|
|
|
func (s *Session) SetLanguage(language string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "language", language)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2018-07-19 01:30:05 -04:00
|
|
|
// SetTheme updates the theme field in session.
|
|
|
|
func (s *Session) SetTheme(theme string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "theme", theme)
|
2018-07-19 01:30:05 -04:00
|
|
|
}
|
|
|
|
|
2018-05-20 18:29:14 -04:00
|
|
|
// SetPocketRequestToken updates Pocket Request Token.
|
|
|
|
func (s *Session) SetPocketRequestToken(requestToken string) {
|
2019-01-21 23:21:05 -05:00
|
|
|
s.store.UpdateAppSessionField(s.sessionID, "pocket_request_token", requestToken)
|
2018-05-20 18:29:14 -04:00
|
|
|
}
|
2023-11-05 12:57:35 -05:00
|
|
|
|
|
|
|
func (s *Session) SetWebAuthnSessionData(sessionData *model.WebAuthnSession) {
|
|
|
|
s.store.UpdateAppSessionObjectField(s.sessionID, "webauthn_session_data", sessionData)
|
|
|
|
}
|