|
@@ -18,7 +18,10 @@ const int ColIndexOpBtn = 8;
|
|
|
const int ColIndexBlasterDev = 1;
|
|
|
|
|
|
BlastOpePage::BlastOpePage(QWidget *parent)
|
|
|
- : QWidget(parent), ui(new Ui::BlastOpePage), dao(DatabaseManager::getInstance().getDatabase()) {
|
|
|
+ : QWidget(parent),
|
|
|
+ ui(new Ui::BlastOpePage),
|
|
|
+ dao(DatabaseManager::getInstance().getDatabase()),
|
|
|
+ m_faceVerification(nullptr) {
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
|
|
|
|
bool isAllSafetyInspectorConfirmed = true;
|
|
@@ -39,7 +42,7 @@ BlastOpePage::BlastOpePage(QWidget *parent)
|
|
|
}
|
|
|
}
|
|
|
if (isFaceVerificationEnabled) {
|
|
|
- InitFace();
|
|
|
+ initFaceVerification();
|
|
|
} else {
|
|
|
ui->setupUi(this);
|
|
|
initPagination();
|
|
@@ -64,193 +67,33 @@ void BlastOpePage::showCountDownWidget(QString uuid, const QString &topic, const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void BlastOpePage::InitFace() {
|
|
|
- Logger::getInstance().info("start init face verification");
|
|
|
- LoadingWidget::showLoading(this, "请求创建人脸识别...");
|
|
|
+void BlastOpePage::initFaceVerification() {
|
|
|
+ m_faceVerification = new FaceVerification(this);
|
|
|
|
|
|
- layout = new QVBoxLayout(this);
|
|
|
- // TODO: relase the qwebengineview when not successfully verified
|
|
|
- view = new QWebEngineView(this);
|
|
|
- view->setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
+ connect(m_faceVerification, &FaceVerification::verificationSuccessful, this,
|
|
|
+ &BlastOpePage::onFaceVerificationSuccess);
|
|
|
+ connect(m_faceVerification, &FaceVerification::verificationFailed, this, &BlastOpePage::onFaceVerificationFailed);
|
|
|
|
|
|
- QWebEnginePage *page = view->page();
|
|
|
-
|
|
|
- QJsonObject metaInfo = getMetaInfo();
|
|
|
- if (metaInfo["certName"] == "" || metaInfo["certNo"] == "") {
|
|
|
- QMessageBox::information(nullptr, "获取用户信息错误", "未获得用户的身份证信息,请联系管理员");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QObject::connect(page, &QWebEnginePage::featurePermissionRequested,
|
|
|
- [this, page](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
|
|
|
- handleFeaturePermission(page, securityOrigin, feature);
|
|
|
- });
|
|
|
-
|
|
|
- Logger::getInstance().info("FaceVerification: connect");
|
|
|
- QUrl postUrl(apiBackendUrl.resolved(QUrl("h-face-verify/pc")));
|
|
|
- QJsonObject response = sendPostRequest(postUrl, metaInfo);
|
|
|
- QString certifyUrl;
|
|
|
- if (response["code"] != 200) {
|
|
|
- Logger::getInstance().error(
|
|
|
- QString("创建人脸识别请求服务器返回错误: userName: %1. response: %2")
|
|
|
- .arg(metaInfo["certName"].toString(), QString::fromUtf8(QJsonDocument(response).toJson())));
|
|
|
- QMessageBox::critical(nullptr, "错误", "无法创建人脸识别,请确认后台录入的身份信息正确");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (response.contains("data") && response["data"].isObject()) {
|
|
|
- LoadingWidget::showLoading(this, "人脸识别请求已创建...");
|
|
|
- QJsonObject dataObject = response["data"].toObject();
|
|
|
- if (dataObject.contains("ResultObject") && dataObject["ResultObject"].isObject()) {
|
|
|
- QJsonObject resultObject = dataObject["ResultObject"].toObject();
|
|
|
- if (resultObject.contains("CertifyId") && resultObject["CertifyId"].isString()) {
|
|
|
- certifyId = resultObject["CertifyId"].toString();
|
|
|
- }
|
|
|
- if (resultObject.contains("CertifyUrl") && resultObject["CertifyUrl"].isString()) {
|
|
|
- certifyUrl = resultObject["CertifyUrl"].toString();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!certifyUrl.isEmpty()) {
|
|
|
- view->load(QUrl(certifyUrl));
|
|
|
-
|
|
|
- layout->addWidget(view);
|
|
|
-
|
|
|
- layout->setStretchFactor(view, 1);
|
|
|
-
|
|
|
- QObject::connect(page, &QWebEnginePage::urlChanged, this, &BlastOpePage::onUrlChanged);
|
|
|
- } else {
|
|
|
- QMessageBox::information(nullptr, "提示", "人脸识别请求失败");
|
|
|
- Logger::getInstance().error("FaceVerificationInit: Failed to get certifyUrl");
|
|
|
- LoadingWidget::hideLoading();
|
|
|
- }
|
|
|
+ m_faceVerification->initFaceVerification();
|
|
|
}
|
|
|
|
|
|
-void BlastOpePage::closeWebViewAndRestoreUI() {
|
|
|
- if (view) {
|
|
|
- layout->removeWidget(view);
|
|
|
- delete view;
|
|
|
- view = nullptr;
|
|
|
- }
|
|
|
- if (layout) {
|
|
|
- delete layout;
|
|
|
- layout = nullptr;
|
|
|
- }
|
|
|
+void BlastOpePage::onFaceVerificationSuccess() {
|
|
|
+ ui->setupUi(this);
|
|
|
+ initPagination();
|
|
|
}
|
|
|
|
|
|
-// 槽函数:处理 URL 改变事件
|
|
|
-void BlastOpePage::onUrlChanged(const QUrl &newUrl) {
|
|
|
- LoadingWidget::showLoading(this, "查询验证结果...");
|
|
|
- if (newUrl.host() == "www.integrateblaster.com") {
|
|
|
- closeWebViewAndRestoreUI();
|
|
|
- QNetworkAccessManager manager;
|
|
|
- QUrl requestUrl(apiBackendUrl.resolved(QUrl(QString("h-face-verify/certifyId/%1").arg(certifyId))));
|
|
|
- QNetworkRequest request(requestUrl);
|
|
|
- QNetworkReply *reply = manager.get(request);
|
|
|
- QEventLoop loop;
|
|
|
- QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
|
- loop.exec();
|
|
|
-
|
|
|
- if (reply->error() == QNetworkReply::NoError) {
|
|
|
- QByteArray responseData = reply->readAll();
|
|
|
- QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
|
|
- if (!jsonDoc.isNull() && jsonDoc.isObject()) {
|
|
|
- QJsonObject rootObj = jsonDoc.object();
|
|
|
- QJsonObject dataObj = rootObj["data"].toObject();
|
|
|
- QString message = dataObj["Message"].toString();
|
|
|
- QJsonObject resultObj = dataObj["ResultObject"].toObject();
|
|
|
- if (resultObj.isEmpty()) {
|
|
|
- Logger::getInstance().error(QString("获取认证初始化数据失败. message: %1.").arg(message));
|
|
|
- int ret = QMessageBox::information(nullptr, "认证失败", message + " ,请重新认证!");
|
|
|
- if (ret == QMessageBox::Ok) {
|
|
|
- InitFace();
|
|
|
- }
|
|
|
- } else {
|
|
|
- QString passed = resultObj["Passed"].toString();
|
|
|
- if (passed == "T") {
|
|
|
- ui->setupUi(this);
|
|
|
- initPagination();
|
|
|
- Logger::getInstance().info(QString("进入认证界面"));
|
|
|
- LoadingWidget::hideLoading();
|
|
|
- } else if (passed == "F") {
|
|
|
- int ret = QMessageBox::critical(nullptr, "提示", "操作失败,请重新认证!");
|
|
|
- if (ret == QMessageBox::Ok) {
|
|
|
- InitFace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- qDebug() << "Request failed:" << reply->errorString();
|
|
|
- Logger::getInstance().error(
|
|
|
- QString("InitFaseVerification request failed. error message: %1").arg(reply->errorString()));
|
|
|
- }
|
|
|
-
|
|
|
- reply->deleteLater();
|
|
|
- LoadingWidget::hideLoading();
|
|
|
- }
|
|
|
- LoadingWidget::hideLoading();
|
|
|
+void BlastOpePage::onFaceVerificationFailed(const QString &message) {
|
|
|
+ // Handle face verification failure
|
|
|
+ // The FaceVerification class already shows appropriate error messages
|
|
|
+ Q_UNUSED(message)
|
|
|
}
|
|
|
|
|
|
BlastOpePage::~BlastOpePage() {
|
|
|
delete ui;
|
|
|
|
|
|
- if (view) {
|
|
|
- delete view;
|
|
|
- }
|
|
|
- if (layout) {
|
|
|
- delete layout;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-QJsonObject BlastOpePage::sendPostRequest(const QUrl &url, const QJsonObject &data) {
|
|
|
- QNetworkAccessManager manager;
|
|
|
- QNetworkRequest request(url);
|
|
|
- request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
-
|
|
|
- QJsonDocument doc(data);
|
|
|
- QByteArray postData = doc.toJson();
|
|
|
-
|
|
|
- QNetworkReply *reply = manager.post(request, postData);
|
|
|
-
|
|
|
- QEventLoop loop;
|
|
|
- QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
|
- loop.exec();
|
|
|
-
|
|
|
- QJsonObject responseJson;
|
|
|
- if (reply->error() == QNetworkReply::NoError) {
|
|
|
- QByteArray responseData = reply->readAll();
|
|
|
- QJsonDocument responseDoc = QJsonDocument::fromJson(responseData);
|
|
|
- if (!responseDoc.isNull() && responseDoc.isObject()) {
|
|
|
- responseJson = responseDoc.object();
|
|
|
- }
|
|
|
- } else {
|
|
|
- qDebug() << "Error fetching content: " << reply->errorString();
|
|
|
+ if (m_faceVerification) {
|
|
|
+ delete m_faceVerification;
|
|
|
}
|
|
|
- reply->deleteLater();
|
|
|
- return responseJson;
|
|
|
-}
|
|
|
-
|
|
|
-void BlastOpePage::handleFeaturePermission(QWebEnginePage *page, const QUrl &securityOrigin,
|
|
|
- QWebEnginePage::Feature feature) {
|
|
|
- if (feature == QWebEnginePage::MediaAudioCapture || feature == QWebEnginePage::MediaAudioVideoCapture ||
|
|
|
- feature == QWebEnginePage::MediaVideoCapture) {
|
|
|
- page->setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
|
|
|
- } else {
|
|
|
- page->setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-QJsonObject BlastOpePage::getMetaInfo() {
|
|
|
- QJsonObject metaInfo;
|
|
|
- QString certName;
|
|
|
- QString certNo;
|
|
|
-
|
|
|
- QMap<QString, QString> userInfo = RegistryManager::instance()->getCurentLoginUser();
|
|
|
- certName = userInfo.value("certName", "");
|
|
|
- certNo = userInfo.value("identity", "");
|
|
|
- metaInfo["certName"] = certName;
|
|
|
- metaInfo["certNo"] = certNo;
|
|
|
- return metaInfo;
|
|
|
}
|
|
|
|
|
|
void BlastOpePage::initPagination() {
|