From 523f2e3492872b3f251cbdb45ce93b111332dc7f Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 12 Sep 2014 00:01:51 +0200 Subject: [PATCH] Added first connection form --- Makefile.am | 1 + database/DatabaseHandler.cpp | 4 +-- ui/LmsApplication.cpp | 36 +++++++++++++++++++---- ui/LmsApplication.hpp | 5 ++++ ui/approot/templates.xml | 55 ++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index 731ca6d9..a3d751bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,6 +70,7 @@ lms_SOURCES = \ $(top_srcdir)/ui/settings/SettingsAccountFormView.cpp \ $(top_srcdir)/ui/settings/SettingsAudioFormView.cpp \ $(top_srcdir)/ui/settings/SettingsDatabaseFormView.cpp \ + $(top_srcdir)/ui/settings/SettingsFirstConnectionFormView.cpp \ $(top_srcdir)/ui/settings/SettingsMediaDirectories.cpp \ $(top_srcdir)/ui/settings/SettingsMediaDirectoryFormView.cpp \ $(top_srcdir)/ui/settings/SettingsUserFormView.cpp \ diff --git a/database/DatabaseHandler.cpp b/database/DatabaseHandler.cpp index 8300ddec..a351defb 100644 --- a/database/DatabaseHandler.cpp +++ b/database/DatabaseHandler.cpp @@ -37,8 +37,8 @@ Handler::configureAuth(void) Wt::Auth::PasswordStrengthValidator* strengthValidator = new Wt::Auth::PasswordStrengthValidator(); // Reduce some constraints... - strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::TwoCharClass, 11); - strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::ThreeCharClass, 8 ); + strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::TwoCharClass, 8); + strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::ThreeCharClass, 7 ); strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::FourCharClass, 6 ); passwordService.setStrengthValidator(strengthValidator); diff --git a/ui/LmsApplication.cpp b/ui/LmsApplication.cpp index a1e94544..16ea883c 100644 --- a/ui/LmsApplication.cpp +++ b/ui/LmsApplication.cpp @@ -1,9 +1,16 @@ #include #include "auth/LmsAuth.hpp" + #include "LmsHome.hpp" +#include "settings/SettingsFirstConnectionFormView.hpp" #include "LmsApplication.hpp" +namespace skeletons { + extern const char *AuthStrings_xml1; +} + + namespace UserInterface { Wt::WApplication* @@ -38,17 +45,34 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p setTitle("LMS"); // application title - _sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent); + bool firstConnection; + { + Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession()); - LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler()); + firstConnection = (Database::User::getAll(_sessionData.getDatabaseHandler().getSession()).size() == 0); + } - authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService()); - authWidget->setRegistrationEnabled(false); + // If here is no account in the database, launch the first connection wizard + if (firstConnection) + { + // Hack, use the auth widget builtin strings + builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1); - authWidget->processEnvironment(); + root()->addWidget( new Settings::FirstConnectionFormView(_sessionData)); + } + else + { + _sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent); - root()->addWidget(authWidget); + LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler()); + authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService()); + authWidget->setRegistrationEnabled(false); + + authWidget->processEnvironment(); + + root()->addWidget(authWidget); + } } diff --git a/ui/LmsApplication.hpp b/ui/LmsApplication.hpp index 93ec332f..31ea3d23 100644 --- a/ui/LmsApplication.hpp +++ b/ui/LmsApplication.hpp @@ -1,3 +1,5 @@ +#ifndef LMS_APPLICATION_HPP +#define LMS_APPLICATION_HPP #include @@ -28,3 +30,6 @@ class LmsApplication : public Wt::WApplication } // namespace UserInterface + +#endif + diff --git a/ui/approot/templates.xml b/ui/approot/templates.xml index b0ad9eec..f4feb002 100644 --- a/ui/approot/templates.xml +++ b/ui/approot/templates.xml @@ -2,6 +2,61 @@ + + ${title} +
+
+ +
+ ${name} +
+
+ ${name-info} +
+
+
+ +
+ ${email} +
+
+ ${email-info} +
+
+
+ +
+ ${password} +
+ ${password-info} +
+
+ +
+ ${password-confirm} +
+
+ ${password-confirm-info} +
+
+
+
+ ${save-button} +
+
+ ${apply-info} +
+
+ + ${title}