Added back some of the stuff lost in prior reverts

- Galleries code was removed along with images.
- Images were fixed with the last commit, fixing galleries this commit.
- Tried to add the error message for the session login
- But didn't get the syntax right, so removed it, but there are a couple of
formatting changes for readability in it.
Made a bunch of fixes

Grabbed stuff from the class master

Added a constraint to user_id in galleries table

Added a bunch of scoping to ensure access to stuff is only allowed for the owner.