Pass the session to the 404 page

This commit is contained in:
Las Zenow 2013-06-01 20:51:21 +02:00
parent 3da8cae762
commit e72fd6e4d4
5 changed files with 33 additions and 30 deletions

View file

@ -133,14 +133,14 @@ func readStartHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
id := mux.Vars(r)["id"]
e, _ := openReadEpub(w, r, sess)
if e == nil {
notFound(w)
notFound(w, r)
return
}
defer e.Close()
it, err := e.Spine()
if err != nil {
notFound(w)
notFound(w, r)
return
}
http.Redirect(w, r, "/read/"+id+"/"+it.Url(), http.StatusTemporaryRedirect)
@ -151,7 +151,7 @@ func readHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
file := mux.Vars(r)["file"]
e, book := openReadEpub(w, r, sess)
if e == nil {
notFound(w)
notFound(w, r)
return
}
defer e.Close()
@ -200,32 +200,32 @@ func contentHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
id := vars["id"]
file := vars["file"]
if file == "" || !bson.IsObjectIdHex(id) {
notFound(w)
notFound(w, r)
return
}
books, _, err := db.GetBooks(bson.M{"_id": bson.ObjectIdHex(id)})
if err != nil || len(books) == 0 {
notFound(w)
notFound(w, r)
return
}
book := books[0]
if !book.Active {
if sess.User == "" {
notFound(w)
notFound(w, r)
return
}
}
e, err := OpenBook(book.File)
if err != nil {
notFound(w)
notFound(w, r)
return
}
defer e.Close()
html, err := e.OpenFile(file)
if err != nil {
notFound(w)
notFound(w, r)
return
}
defer html.Close()