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,13 +44,17 @@ func GetSession(db *DB, r *http.Request) (*Session, error) {
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func DeleteSessionIfExists(db *DB, r *http.Request) {
|
||||
func DeleteSessionIfExists(db *DB, r *http.Request) error {
|
||||
// TODO do this in one transaction
|
||||
session, err := GetSession(db, r)
|
||||
if err == nil {
|
||||
db.Delete(session)
|
||||
_, err := db.Delete(session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSessionCookie() (string, error) {
|
||||
bits := make([]byte, 128)
|
||||
@ -116,7 +120,12 @@ func SessionHandler(w http.ResponseWriter, r *http.Request, db *DB) {
|
||||
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)
|
||||
if err != nil {
|
||||
@ -139,7 +148,12 @@ func SessionHandler(w http.ResponseWriter, r *http.Request, db *DB) {
|
||||
|
||||
s.Write(w)
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user