mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Refactor HTTP context handling
This commit is contained in:
parent
88e81d4d80
commit
eee1f31903
76 changed files with 434 additions and 587 deletions
|
@ -6,67 +6,64 @@ package session // import "miniflux.app/ui/session"
|
|||
|
||||
import (
|
||||
"miniflux.app/crypto"
|
||||
"miniflux.app/http/context"
|
||||
"miniflux.app/storage"
|
||||
)
|
||||
|
||||
// Session handles session data.
|
||||
type Session struct {
|
||||
store *storage.Storage
|
||||
ctx *context.Context
|
||||
store *storage.Storage
|
||||
sessionID string
|
||||
}
|
||||
|
||||
// NewOAuth2State generates a new OAuth2 state and stores the value into the database.
|
||||
func (s *Session) NewOAuth2State() string {
|
||||
state := crypto.GenerateRandomString(32)
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "oauth2_state", state)
|
||||
s.store.UpdateSessionField(s.sessionID, "oauth2_state", state)
|
||||
return state
|
||||
}
|
||||
|
||||
// NewFlashMessage creates a new flash message.
|
||||
func (s *Session) NewFlashMessage(message string) {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "flash_message", message)
|
||||
s.store.UpdateSessionField(s.sessionID, "flash_message", message)
|
||||
}
|
||||
|
||||
// FlashMessage returns the current flash message if any.
|
||||
func (s *Session) FlashMessage() string {
|
||||
message := s.ctx.FlashMessage()
|
||||
func (s *Session) FlashMessage(message string) string {
|
||||
if message != "" {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "flash_message", "")
|
||||
s.store.UpdateSessionField(s.sessionID, "flash_message", "")
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
// NewFlashErrorMessage creates a new flash error message.
|
||||
func (s *Session) NewFlashErrorMessage(message string) {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "flash_error_message", message)
|
||||
s.store.UpdateSessionField(s.sessionID, "flash_error_message", message)
|
||||
}
|
||||
|
||||
// FlashErrorMessage returns the last flash error message if any.
|
||||
func (s *Session) FlashErrorMessage() string {
|
||||
message := s.ctx.FlashErrorMessage()
|
||||
func (s *Session) FlashErrorMessage(message string) string {
|
||||
if message != "" {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "flash_error_message", "")
|
||||
s.store.UpdateSessionField(s.sessionID, "flash_error_message", "")
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
// SetLanguage updates the language field in session.
|
||||
func (s *Session) SetLanguage(language string) {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "language", language)
|
||||
s.store.UpdateSessionField(s.sessionID, "language", language)
|
||||
}
|
||||
|
||||
// SetTheme updates the theme field in session.
|
||||
func (s *Session) SetTheme(theme string) {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "theme", theme)
|
||||
s.store.UpdateSessionField(s.sessionID, "theme", theme)
|
||||
}
|
||||
|
||||
// SetPocketRequestToken updates Pocket Request Token.
|
||||
func (s *Session) SetPocketRequestToken(requestToken string) {
|
||||
s.store.UpdateSessionField(s.ctx.SessionID(), "pocket_request_token", requestToken)
|
||||
s.store.UpdateSessionField(s.sessionID, "pocket_request_token", requestToken)
|
||||
}
|
||||
|
||||
// New returns a new session handler.
|
||||
func New(store *storage.Storage, ctx *context.Context) *Session {
|
||||
return &Session{store, ctx}
|
||||
func New(store *storage.Storage, sessionID string) *Session {
|
||||
return &Session{store, sessionID}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue