WIP. User authentication on user interface
This commit is contained in:
+37
-52
@@ -1,13 +1,6 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WBreak>
|
||||
#include <Wt/WLabel>
|
||||
#include <Wt/WBootstrapTheme>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WMenu>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WPopupMenuItem>
|
||||
#include "LmsAuth.hpp"
|
||||
#include "LmsHome.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
@@ -32,65 +25,57 @@ LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPa
|
||||
*/
|
||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath)
|
||||
: Wt::WApplication(env),
|
||||
_sessionData(dbPath)
|
||||
_sessionData(dbPath),
|
||||
_home(nullptr)
|
||||
{
|
||||
|
||||
setTheme(new Wt::WBootstrapTheme());
|
||||
|
||||
setTitle("LMS"); // application title
|
||||
|
||||
Wt::WContainerWidget* container (new Wt::WContainerWidget(root()));
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar(container);
|
||||
navigation->setTitle("LMS");
|
||||
navigation->setResponsive(true);
|
||||
LmsAuth *authWidget = new LmsAuth(Database::Handler::getAuthService(),
|
||||
_sessionData.getDatabaseHandler().getUserDatabase(),
|
||||
_sessionData.getDatabaseHandler().getLogin());
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(container);
|
||||
contentsStack->addStyleClass("contents");
|
||||
authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService());
|
||||
authWidget->setRegistrationEnabled(true);
|
||||
|
||||
// Setup a Left-aligned menu.
|
||||
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container);
|
||||
navigation->addMenu(leftMenu);
|
||||
authWidget->processEnvironment();
|
||||
|
||||
_audioWidget = new AudioWidget(_sessionData);
|
||||
_videoWidget = new VideoWidget(_sessionData);
|
||||
|
||||
leftMenu->addItem("Audio", _audioWidget);
|
||||
leftMenu->addItem("Video", _videoWidget);
|
||||
|
||||
// Setup a Right-aligned menu.
|
||||
Wt::WMenu *rightMenu = new Wt::WMenu();
|
||||
navigation->addMenu(rightMenu, Wt::AlignRight);
|
||||
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Parameters");
|
||||
popup->addSeparator();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem("User");
|
||||
item->setMenu(popup);
|
||||
rightMenu->addItem(item);
|
||||
|
||||
// Add a Search control.
|
||||
_searchEdit = new Wt::WLineEdit();
|
||||
_searchEdit->setEmptyText("Search...");
|
||||
|
||||
_searchEdit->keyWentUp().connect(this, &LmsApplication::handleSearch);
|
||||
|
||||
navigation->addSearch(_searchEdit, Wt::AlignLeft);
|
||||
|
||||
container->addWidget(contentsStack);
|
||||
root()->addWidget(authWidget);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
LmsApplication::handleSearch(void)
|
||||
LmsApplication::handleAuthEvent(void)
|
||||
{
|
||||
// Check currently selected menu item and search it
|
||||
_audioWidget->search( _searchEdit->text().toUTF8() );
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
if (_sessionData.getDatabaseHandler().getLogin().loggedIn())
|
||||
{
|
||||
if (_home == nullptr) {
|
||||
_home = new LmsHome(_sessionData );
|
||||
root()->addWidget( _home );
|
||||
}
|
||||
else
|
||||
std::cerr << "Already logged in??" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "user log out" << std::endl;
|
||||
if (_home != nullptr) {
|
||||
std::cerr << "Deleting home pointer..." << std::endl;
|
||||
delete _home;
|
||||
_home = nullptr;
|
||||
}
|
||||
else
|
||||
std::cerr << "Already logged out??" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace DatabaseHandler
|
||||
} // namespace UserInterface
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user