Authenticate::Authenticate(std::map<std::string, std::string> config, QObject *parent) :
	QObject(parent)
{
	QSettings settings;
	authorized = settings.value("authorized").toStringList();

	QJSEngine engine;

	QJSValue eventEngineValue = engine.newQObject(this);
	engine.globalObject().setProperty("auth", eventEngineValue);

	QString str = config["authSettings"].c_str();

	QFile file(str);
	if(!file.open(QIODevice::ReadOnly))
	{
		qDebug()<<"failed to open config file: "<<str;
		return;
	}

	QString script = file.readAll();

	file.close();

	engine.evaluate(script);

}
Example #2
0
void QJSWorkerThread::run() {

    qDebug() << "1 Locker is now" << v8::Locker::IsActive();
    v8::Locker locker(mIsolate);
    qDebug() << "2 Locker is now" << v8::Locker::IsActive();

    mIsolate->Enter();

    v8::Persistent<v8::Context> context = v8::Context::New();

    qDebug() << "Locker is:" << v8::Locker::IsActive();

    QJSValue workerModule = mEngine->newQObject(mModule);

    context->Enter();

    /* The handle scope's destructor must run before the isolation is exited. */
    {
        v8::HandleScope handleScope;

        v8::Handle<v8::Value> value = *QJSValuePrivate::get(mFunction);
        v8::Local<v8::Function> function(v8::Function::Cast(*value));

        v8::Handle<v8::Value> arg = *QJSValuePrivate::get(workerModule);

        v8::Handle<v8::Object> object = *QJSValuePrivate::get(mFunction);
        function->Call(object, 1, &arg);

        if (mEngine->hasUncaughtException()) {
            qDebug() << "Uncaught Exception for Worker: " << mEngine->uncaughtException().toString();
        }

        qDebug() << handleScope.NumberOfHandles();
    }

    context->Exit();

    mIsolate->Exit();

}
void JsonDatabase::onQueryFinished()
{
    QJsonDbReadRequest *request = qobject_cast<QJsonDbReadRequest *>(sender());
    if (listCallbacks.contains(request)) {
        QJSValue callback = listCallbacks[request];
        QJSEngine *engine = callback.engine();
        QJSValueList args;
        args << QJSValue(QJSValue::UndefinedValue);
        QList<QJsonObject> objects = request->takeResults();
        int count = objects.count();
        if (count) {
            QJSValue response = engine->newArray(count);
            for (int i = 0; i < count; ++i) {
                QString partitionName = objects[i].value(QStringLiteral("name")).toString();
                response.setProperty(i, engine->newQObject(partition(partitionName)));
            }
            args << response;
        } else {
            args << engine->newArray();
        }
        callback.call(args);
        listCallbacks.remove(request);
    }
}