mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-04 10:58:48 +00:00
Use cookies for session storage
Remove the server side session storage and store all the session related data in the client side cookies. This decreases the exposure of the auth tokens. It also simplifies the installation process as bloat no longer requires write access to the filesystem. This is a breaking change, all the existing sessions will stop working.
This commit is contained in:
parent
b4ccde54a7
commit
887ed241d6
14 changed files with 225 additions and 495 deletions
21
model/app.go
21
model/app.go
|
@ -1,21 +0,0 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrAppNotFound = errors.New("app not found")
|
||||
)
|
||||
|
||||
type App struct {
|
||||
InstanceDomain string `json:"instance_domain"`
|
||||
InstanceURL string `json:"instance_url"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
}
|
||||
|
||||
type AppRepo interface {
|
||||
Add(app App) (err error)
|
||||
Get(instanceDomain string) (app App, err error)
|
||||
}
|
|
@ -1,28 +1,48 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrSessionNotFound = errors.New("session not found")
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
InstanceDomain string `json:"instance_domain"`
|
||||
AccessToken string `json:"access_token"`
|
||||
CSRFToken string `json:"csrf_token"`
|
||||
Settings Settings `json:"settings"`
|
||||
}
|
||||
|
||||
type SessionRepo interface {
|
||||
Add(session Session) (err error)
|
||||
Get(sessionID string) (session Session, err error)
|
||||
Remove(sessionID string)
|
||||
ID string `json:"id,omitempty"`
|
||||
UserID string `json:"uid,omitempty"`
|
||||
Instance string `json:"ins,omitempty"`
|
||||
ClientID string `json:"cid,omitempty"`
|
||||
ClientSecret string `json:"cs,omitempty"`
|
||||
AccessToken string `json:"at,omitempty"`
|
||||
CSRFToken string `json:"csrf,omitempty"`
|
||||
Settings Settings `json:"sett,omitempty"`
|
||||
}
|
||||
|
||||
func (s Session) IsLoggedIn() bool {
|
||||
return len(s.AccessToken) > 0
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
DefaultVisibility string `json:"dv,omitempty"`
|
||||
DefaultFormat string `json:"df,omitempty"`
|
||||
CopyScope bool `json:"cs,omitempty"`
|
||||
ThreadInNewTab bool `json:"tnt,omitempty"`
|
||||
HideAttachments bool `json:"ha,omitempty"`
|
||||
MaskNSFW bool `json:"mn,omitempty"`
|
||||
NotificationInterval int `json:"ni,omitempty"`
|
||||
FluorideMode bool `json:"fm,omitempty"`
|
||||
DarkMode bool `json:"dm,omitempty"`
|
||||
AntiDopamineMode bool `json:"adm,omitempty"`
|
||||
HideUnsupportedNotifs bool `json:"hun,omitempty"`
|
||||
CSS string `json:"css,omitempty"`
|
||||
}
|
||||
|
||||
func NewSettings() *Settings {
|
||||
return &Settings{
|
||||
DefaultVisibility: "public",
|
||||
DefaultFormat: "",
|
||||
CopyScope: true,
|
||||
ThreadInNewTab: false,
|
||||
HideAttachments: false,
|
||||
MaskNSFW: true,
|
||||
NotificationInterval: 0,
|
||||
FluorideMode: false,
|
||||
DarkMode: false,
|
||||
AntiDopamineMode: false,
|
||||
HideUnsupportedNotifs: false,
|
||||
CSS: "",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package model
|
||||
|
||||
type Settings struct {
|
||||
DefaultVisibility string `json:"default_visibility"`
|
||||
DefaultFormat string `json:"default_format"`
|
||||
CopyScope bool `json:"copy_scope"`
|
||||
ThreadInNewTab bool `json:"thread_in_new_tab"`
|
||||
HideAttachments bool `json:"hide_attachments"`
|
||||
MaskNSFW bool `json:"mask_nfsw"`
|
||||
NotificationInterval int `json:"notifications_interval"`
|
||||
FluorideMode bool `json:"fluoride_mode"`
|
||||
DarkMode bool `json:"dark_mode"`
|
||||
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
||||
HideUnsupportedNotifs bool `json:"hide_unsupported_notifs"`
|
||||
CSS string `json:"css"`
|
||||
}
|
||||
|
||||
func NewSettings() *Settings {
|
||||
return &Settings{
|
||||
DefaultVisibility: "public",
|
||||
DefaultFormat: "",
|
||||
CopyScope: true,
|
||||
ThreadInNewTab: false,
|
||||
HideAttachments: false,
|
||||
MaskNSFW: true,
|
||||
NotificationInterval: 0,
|
||||
FluorideMode: false,
|
||||
DarkMode: false,
|
||||
AntiDopamineMode: false,
|
||||
HideUnsupportedNotifs: false,
|
||||
CSS: "",
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue