2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-12-17 03:07:53 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package model // import "miniflux.app/v2/internal/model"
|
2017-12-17 03:07:53 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SessionData represents the data attached to the session.
|
|
|
|
type SessionData struct {
|
2018-05-21 00:29:14 +02:00
|
|
|
CSRF string `json:"csrf"`
|
|
|
|
OAuth2State string `json:"oauth2_state"`
|
2023-09-03 06:35:10 +02:00
|
|
|
OAuth2CodeVerifier string `json:"oauth2_code_verifier"`
|
2018-05-21 00:29:14 +02:00
|
|
|
FlashMessage string `json:"flash_message"`
|
|
|
|
FlashErrorMessage string `json:"flash_error_message"`
|
|
|
|
Language string `json:"language"`
|
2019-01-22 05:21:05 +01:00
|
|
|
Theme string `json:"theme"`
|
2018-05-21 00:29:14 +02:00
|
|
|
PocketRequestToken string `json:"pocket_request_token"`
|
2017-12-17 03:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s SessionData) String() string {
|
2023-09-03 06:35:10 +02:00
|
|
|
return fmt.Sprintf(`CSRF=%q, OAuth2State=%q, OAuth2CodeVerifier=%q, FlashMsg=%q, FlashErrMsg=%q, Lang=%q, Theme=%q, PocketTkn=%q`,
|
|
|
|
s.CSRF, s.OAuth2State, s.OAuth2CodeVerifier, s.FlashMessage, s.FlashErrorMessage, s.Language, s.Theme, s.PocketRequestToken)
|
2017-12-17 03:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value converts the session data to JSON.
|
|
|
|
func (s SessionData) Value() (driver.Value, error) {
|
|
|
|
j, err := json.Marshal(s)
|
|
|
|
return j, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan converts raw JSON data.
|
|
|
|
func (s *SessionData) Scan(src interface{}) error {
|
|
|
|
source, ok := src.([]byte)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("session: unable to assert type of src")
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(source, s)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("session: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Session represents a session in the system.
|
|
|
|
type Session struct {
|
|
|
|
ID string
|
|
|
|
Data *SessionData
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) String() string {
|
2018-01-19 06:53:31 +01:00
|
|
|
return fmt.Sprintf(`ID="%s", Data={%v}`, s.ID, s.Data)
|
2017-12-17 03:07:53 +01:00
|
|
|
}
|