mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-01-31 01:48:55 -05:00
sessions: Return deletion errors to user
This commit is contained in:
parent
3c5e726f93
commit
e781e9861b
@ -44,12 +44,16 @@ func GetSession(db *DB, r *http.Request) (*Session, error) {
|
|||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteSessionIfExists(db *DB, r *http.Request) {
|
func DeleteSessionIfExists(db *DB, r *http.Request) error {
|
||||||
// TODO do this in one transaction
|
// TODO do this in one transaction
|
||||||
session, err := GetSession(db, r)
|
session, err := GetSession(db, r)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
db.Delete(session)
|
_, err := db.Delete(session)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSessionCookie() (string, error) {
|
func NewSessionCookie() (string, error) {
|
||||||
@ -116,7 +120,12 @@ func SessionHandler(w http.ResponseWriter, r *http.Request, db *DB) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteSessionIfExists(db, r)
|
err = DeleteSessionIfExists(db, r)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
session, err := NewSession(db, w, r, dbuser.UserId)
|
session, err := NewSession(db, w, r, dbuser.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -139,7 +148,12 @@ func SessionHandler(w http.ResponseWriter, r *http.Request, db *DB) {
|
|||||||
|
|
||||||
s.Write(w)
|
s.Write(w)
|
||||||
} else if r.Method == "DELETE" {
|
} else if r.Method == "DELETE" {
|
||||||
DeleteSessionIfExists(db, r)
|
err := DeleteSessionIfExists(db, r)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
WriteSuccess(w)
|
WriteSuccess(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user