Refactor context_app

Moved code out of the intializer of context and moved it into
context_app with everything else.
correctly logging in and setting cookie now.