WIP - Move authentication to separate class.

This involves moving functions out of the controller, and allowing the database connection to be opened when needed instead of on object creation.