mirror of
https://git.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 03:51:28 +00:00
Remove session details on signout
This commit is contained in:
parent
35a8c247d9
commit
911c9b7993
2
go.mod
2
go.mod
|
@ -4,3 +4,5 @@ require (
|
||||||
github.com/gorilla/mux v1.7.3
|
github.com/gorilla/mux v1.7.3
|
||||||
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
|
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Session struct {
|
||||||
type SessionRepo interface {
|
type SessionRepo interface {
|
||||||
Add(session Session) (err error)
|
Add(session Session) (err error)
|
||||||
Get(sessionID string) (session Session, err error)
|
Get(sessionID string) (session Session, err error)
|
||||||
|
Remove(sessionID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Session) IsLoggedIn() bool {
|
func (s Session) IsLoggedIn() bool {
|
||||||
|
|
|
@ -40,3 +40,8 @@ func (repo *sessionRepo) Get(id string) (s model.Session, err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *sessionRepo) Remove(id string) {
|
||||||
|
repo.db.Remove(id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -204,6 +204,19 @@ func (s *as) Signin(ctx context.Context, c *model.Client, sessionID string,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *as) Signout(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = checkCSRF(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Service.Signout(ctx, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (s *as) Post(ctx context.Context, c *model.Client, content string,
|
func (s *as) Post(ctx context.Context, c *model.Client, content string,
|
||||||
replyToID string, format string, visibility string, isNSFW bool,
|
replyToID string, format string, visibility string, isNSFW bool,
|
||||||
files []*multipart.FileHeader) (id string, err error) {
|
files []*multipart.FileHeader) (id string, err error) {
|
||||||
|
|
|
@ -162,6 +162,14 @@ func (s *ls) Signin(ctx context.Context, c *model.Client, sessionID string,
|
||||||
return s.Service.Signin(ctx, c, sessionID, code)
|
return s.Service.Signin(ctx, c, sessionID, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ls) Signout(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"Signout", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.Signout(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ls) Post(ctx context.Context, c *model.Client, content string,
|
func (s *ls) Post(ctx context.Context, c *model.Client, content string,
|
||||||
replyToID string, format string, visibility string, isNSFW bool,
|
replyToID string, format string, visibility string, isNSFW bool,
|
||||||
files []*multipart.FileHeader) (id string, err error) {
|
files []*multipart.FileHeader) (id string, err error) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ type Service interface {
|
||||||
NewSession(ctx context.Context, instance string) (redirectUrl string, sessionID string, err error)
|
NewSession(ctx context.Context, instance string) (redirectUrl string, sessionID string, err error)
|
||||||
Signin(ctx context.Context, c *model.Client, sessionID string,
|
Signin(ctx context.Context, c *model.Client, sessionID string,
|
||||||
code string) (token string, userID string, err error)
|
code string) (token string, userID string, err error)
|
||||||
|
Signout(ctx context.Context, c *model.Client) (err error)
|
||||||
Post(ctx context.Context, c *model.Client, content string, replyToID string, format string,
|
Post(ctx context.Context, c *model.Client, content string, replyToID string, format string,
|
||||||
visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error)
|
visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error)
|
||||||
Like(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
Like(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
||||||
|
@ -722,6 +723,11 @@ func (svc *service) Signin(ctx context.Context, c *model.Client,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *service) Signout(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
svc.sessionRepo.Remove(c.Session.ID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *service) Post(ctx context.Context, c *model.Client, content string,
|
func (svc *service) Post(ctx context.Context, c *model.Client, content string,
|
||||||
replyToID string, format string, visibility string, isNSFW bool,
|
replyToID string, format string, visibility string, isNSFW bool,
|
||||||
files []*multipart.FileHeader) (id string, err error) {
|
files []*multipart.FileHeader) (id string, err error) {
|
||||||
|
|
|
@ -646,12 +646,16 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
signout := func(w http.ResponseWriter, req *http.Request) {
|
signout := func(w http.ResponseWriter, req *http.Request) {
|
||||||
// TODO remove session from database
|
c := newClient(w)
|
||||||
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
|
||||||
|
s.Signout(ctx, c)
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "session_id",
|
Name: "session_id",
|
||||||
Value: "",
|
Value: "",
|
||||||
Expires: time.Now(),
|
Expires: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
w.Header().Add("Location", "/")
|
w.Header().Add("Location", "/")
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
|
@ -763,7 +767,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/delete/{id}", delete).Methods(http.MethodPost)
|
r.HandleFunc("/delete/{id}", delete).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/signout", signout).Methods(http.MethodGet)
|
r.HandleFunc("/signout", signout).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/retweet/{id}", fRetweet).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/retweet/{id}", fRetweet).Methods(http.MethodPost)
|
||||||
|
|
|
@ -477,6 +477,10 @@ a:hover,
|
||||||
margin: 12px 0;
|
margin: 12px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.signout {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
background-color: #222222;
|
background-color: #222222;
|
||||||
background-image: none;
|
background-image: none;
|
||||||
|
|
|
@ -23,7 +23,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a class="nav-link" href="/settings" target="_top">settings</a>
|
<a class="nav-link" href="/settings" target="_top">settings</a>
|
||||||
<a class="nav-link" href="/signout" target="_top">sign out</a>
|
<form class="signout" action="/signout" method="post" target="_top">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="submit" value="signout" class="btn-link nav-link">
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue