+void Core::processClientInit(QTcpSocket *socket, const QVariantMap &msg) {
+ // Auth
+ QVariantMap reply;
+ UserId uid = storage->validateUser(msg["User"].toString(), msg["Password"].toString()); // throws exception if this failed
+ reply["StartWizard"] = false;
+ reply["Reply"] = initSession(uid);
+ disconnect(socket, 0, this, 0);
+ sessions[uid]->addClient(socket);
+ qDebug() << "Client initialized successfully.";
+ writeDataToDevice(socket, reply);
+}
+
+void Core::processCoreSetup(QTcpSocket *socket, QVariantMap &msg) {
+ if(msg["HasSettings"].toBool()) {
+ QVariantMap auth;
+ auth["User"] = msg["User"];
+ auth["Password"] = msg["Password"];
+ msg.remove("User");
+ msg.remove("Password");
+ qDebug() << "Initializing storage provider" << msg["Type"].toString();
+ QString hname = msg["Type"].toString().toLower();
+ hname[0] = hname[0].toUpper();
+ hname = "initStorage" + hname;
+ if (!QMetaObject::invokeMethod(this, hname.toAscii(), Q_RETURN_ARG(bool, configured), Q_ARG(QVariantMap, msg), Q_ARG(bool, true))) {
+ qWarning("No database backend configured.");
+ }
+ if (!configured) {
+ // notify client to start wizard again
+ qWarning("Core is currently not configured!");
+ QVariantMap reply;
+ reply["StartWizard"] = true;
+ reply["StorageProviders"] = availableStorageProviders();
+ writeDataToDevice(socket, reply);
+ } else {
+ // write coresettings
+ CoreSettings s;
+ s.setDatabaseSettings(msg);
+ // write admin user to database & make the core listen again to connections
+ storage->addUser(auth["User"].toString(), auth["Password"].toString());
+ startListening();
+ // continue the normal procedure
+ processClientInit(socket, auth);
+ }
+ } else {
+ // notify client to start wizard
+ QVariantMap reply;
+ reply["StartWizard"] = true;
+ reply["StorageProviders"] = availableStorageProviders();
+ writeDataToDevice(socket, reply);