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
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WLineEdit>
|
||||
|
||||
#include "audio/AudioWidget.hpp"
|
||||
#include "video/VideoWidget.hpp"
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
#include "LmsHome.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
@@ -18,13 +18,11 @@ class LmsApplication : public Wt::WApplication
|
||||
|
||||
private:
|
||||
|
||||
void handleSearch();
|
||||
void handleAuthEvent(void);
|
||||
|
||||
SessionData _sessionData;
|
||||
|
||||
Wt::WLineEdit* _searchEdit;
|
||||
AudioWidget* _audioWidget;
|
||||
VideoWidget* _videoWidget;
|
||||
LmsHome* _home;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <Wt/Auth/AuthService>
|
||||
#include <Wt/Auth/AbstractUserDatabase>
|
||||
#include <Wt/Auth/Login>
|
||||
#include <Wt/Auth/AuthWidget>
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class LmsAuth : public Wt::Auth::AuthWidget
|
||||
{
|
||||
public:
|
||||
|
||||
LmsAuth(const Wt::Auth::AuthService &baseAuth,
|
||||
Wt::Auth::AbstractUserDatabase &users,
|
||||
Wt::Auth::Login &login,
|
||||
Wt::WContainerWidget *parent=0)
|
||||
: Wt::Auth::AuthWidget(baseAuth, users, login, parent) {}
|
||||
|
||||
// LoggedInView is delegated to LmsHome
|
||||
void createLoggedInView () { hide();}
|
||||
|
||||
void createLoginView () { show(); Wt::Auth::AuthWidget::createLoginView();}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WMenu>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WPopupMenuItem>
|
||||
#include <Wt/Auth/Identity>
|
||||
|
||||
#include "LmsHome.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
LmsHome::LmsHome(SessionData& sessionData)
|
||||
: _sessionData(sessionData)
|
||||
{
|
||||
const Wt::Auth::User& user = sessionData.getDatabaseHandler().getLogin().user();
|
||||
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar(this);
|
||||
navigation->setTitle("LMS");
|
||||
navigation->setResponsive(true);
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(this);
|
||||
contentsStack->addStyleClass("contents");
|
||||
|
||||
// Setup a Left-aligned menu.
|
||||
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, this);
|
||||
navigation->addMenu(leftMenu);
|
||||
|
||||
_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");
|
||||
|
||||
popup->itemSelected().connect(this, &LmsHome::handleUserMenuSelected);
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem( user.identity(Wt::Auth::Identity::LoginName) );
|
||||
item->setMenu(popup);
|
||||
rightMenu->addItem(item);
|
||||
|
||||
// Add a Search control.
|
||||
_searchEdit = new Wt::WLineEdit();
|
||||
_searchEdit->setEmptyText("Search...");
|
||||
|
||||
_searchEdit->keyWentUp().connect(this, &LmsHome::handleSearch);
|
||||
|
||||
navigation->addSearch(_searchEdit, Wt::AlignLeft);
|
||||
|
||||
addWidget(contentsStack);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
LmsHome::handleUserMenuSelected( Wt::WMenuItem* item)
|
||||
{
|
||||
if (item && item->text() == "Logout") {
|
||||
_sessionData.getDatabaseHandler().getLogin().logout();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LmsHome::handleSearch(void)
|
||||
{
|
||||
// TODO Check currently selected menu item and search it
|
||||
_audioWidget->search( _searchEdit->text().toUTF8() );
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef LMS_HOME_HPP
|
||||
#define LMS_HOME_HPP
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WLineEdit>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
#include "audio/AudioWidget.hpp"
|
||||
#include "video/VideoWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class LmsHome : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
LmsHome(SessionData& sessionData);
|
||||
|
||||
private:
|
||||
|
||||
void handleSearch(void);
|
||||
void handleUserMenuSelected( Wt::WMenuItem* item );
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
Wt::WLineEdit* _searchEdit;
|
||||
AudioWidget* _audioWidget;
|
||||
VideoWidget* _videoWidget;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user