Merge patch and add useredit template...

Patch from: https://git.freesoftwareextremist.com/bloat/commit/?id=887ed241d64ba5db3fd3d87194fb5595e5ad7d73
Patch description:
Use cookies for session
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:
localhost_frssoft 2022-11-12 01:20:49 +03:00
parent 42badedeeb
commit f9702f81a9
15 changed files with 285 additions and 506 deletions

View file

@ -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)
}

View file

@ -1,28 +1,52 @@
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"`
InstanceEmojiFilter string `json:"iemojfilter,omitempty"`
AddReactionsFilter string `json:"reactionfilter,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,
InstanceEmojiFilter: "",
AddReactionsFilter: "",
CSS: "",
}
}

View file

@ -1,37 +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"`
InstanceEmojiFilter string `json:"instance_emoji_filter"`
AddReactionsFilter string `json:"add_reactions_filter"`
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,
InstanceEmojiFilter: "",
AddReactionsFilter: "",
CSS: "",
}
}