diff --git a/HEADS b/HEADS index 9fcf904..6e71e1c 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"master": "594ab744c52b4697464a49bf09f9895d97eb8723"}} \ No newline at end of file +{"engine": {"master": "8e4bb75bcb12fcab39b4fd874fb279b7620bfaab"}} \ No newline at end of file diff --git a/app/mourne_application.cpp b/app/mourne_application.cpp index 087b624..27ef565 100644 --- a/app/mourne_application.cpp +++ b/app/mourne_application.cpp @@ -17,7 +17,20 @@ #include "modules/users/user.h" #include "modules/users/user_controller.h" +bool MourneApplication::ensure_login(Request *request) { + Ref u = request->reference_data["user"]; + + if (!u.is_valid()) { + request->send_redirect("/user/login"); + return false; + } + + return true; +} + void MourneApplication::index(Object *instance, Request *request) { + ENSURE_LOGIN(request); + add_menu(request, MENUENTRY_NEWS); /* @@ -45,12 +58,6 @@ void MourneApplication::index(Object *instance, Request *request) { } void MourneApplication::session_middleware_func(Object *instance, Request *request) { - std::cout << "test: session_middleware_func called" << std::endl; - - //if fail - //request->send(); in middleware - - request->next_stage(); } void MourneApplication::add_menu(Request *request, const MenuEntries index) { diff --git a/app/mourne_application.h b/app/mourne_application.h index eb4692a..8b6fc3b 100644 --- a/app/mourne_application.h +++ b/app/mourne_application.h @@ -10,6 +10,11 @@ #include "modules/paged_article/paged_article.h" #include "modules/paged_list/paged_list.h" +#define ENSURE_LOGIN(request) \ + if (!ensure_login(request)) { \ + return;\ + } + class MourneApplication : public DWebApplication { public: enum MenuEntries { @@ -29,6 +34,8 @@ public: }; public: + static bool ensure_login(Request *request); + static void index(Object *instance, Request *request); static void session_middleware_func(Object *instance, Request *request);