mirror of
				https://github.com/aclindsa/moneygo.git
				synced 2025-11-03 18:13:27 -05:00 
			
		
		
		
	sessions: Return deletion errors to user
This commit is contained in:
		@@ -44,13 +44,17 @@ 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) {
 | 
				
			||||||
	bits := make([]byte, 128)
 | 
						bits := make([]byte, 128)
 | 
				
			||||||
@@ -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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user