From 0460846daccb4cc45397a9dd33b89f547c894cb6 Mon Sep 17 00:00:00 2001 From: Valery Petrov Date: Sat, 30 May 2026 01:35:49 +0300 Subject: [PATCH] issues/27: cabinet patient registration on test --- assets/components/helper.js | 12 +++ assets/components/loader.js | 9 ++ assets/components/testSdk.js | 115 ++++++++++++++++++++++++++ templates/security/register.html.twig | 4 +- 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 assets/components/testSdk.js diff --git a/assets/components/helper.js b/assets/components/helper.js index e631ef0..9b482d4 100644 --- a/assets/components/helper.js +++ b/assets/components/helper.js @@ -207,7 +207,15 @@ function countDown(options) { }; } +function isTestContour() { + return /\.sova\.local$/i.test(location.hostname); +} + function getApiHostname() { + if (isTestContour()) { + return 'http://api.test.sova.local'; + } + if (/sovamed\.ru/m.test(location.hostname)) { return 'https://api.sovamed.ru'; } @@ -216,6 +224,10 @@ function getApiHostname() { } function getHostname() { + if (isTestContour()) { + return location.origin; + } + if (/sovamed\.ru/m.test(location.hostname)) { return 'https://cabinet.sovamed.ru'; } diff --git a/assets/components/loader.js b/assets/components/loader.js index efab07d..0441be0 100644 --- a/assets/components/loader.js +++ b/assets/components/loader.js @@ -1,4 +1,5 @@ const helper = require("./helper.js"); +const testSdk = require("./testSdk.js"); function esia() { if (document.location.search == '?esia=true') { @@ -39,6 +40,14 @@ function esia() { function loadSDK(controller) { return new Promise(function(resolve, reject) { + if (testSdk.install()) { + console.log(controller + ' - test sdk (sova.local)'); + window.webSDK = new WrSDK(); + esia(); + resolve(window.webSDK); + return; + } + var script = document.getElementById('sdk-infoclinica'); if (script == null) { diff --git a/assets/components/testSdk.js b/assets/components/testSdk.js new file mode 100644 index 0000000..6c7165b --- /dev/null +++ b/assets/components/testSdk.js @@ -0,0 +1,115 @@ +/** + * Test-contour shim for the MIS webSDK (WrSDK) and Yandex SmartCaptcha. + * + * Production keeps loading the real SDK from widget.sovamed.ru / widget.wmtmed.ru + * and the real captcha from smartcaptcha.yandexcloud.net. Those hosts are not + * reachable from the isolated *.sova.local test contour and their captcha sitekey + * is bound to production domains, so patient registration cannot complete there. + * + * This module is a no-op unless the page is served from a *.sova.local host. + */ + +function isTestContour() { + return typeof location !== 'undefined' && /\.sova\.local$/i.test(location.hostname); +} + +function resolveLater(value, ms) { + return new Promise(function(resolve) { + setTimeout(function() { resolve(value); }, ms || 150); + }); +} + +function rejectLater(value, ms) { + return new Promise(function(_, reject) { + setTimeout(function() { reject(value); }, ms || 150); + }); +} + +function TestWrSDK() { + this.data = { user: { authenticated: false } }; + this.sdkOrigin = location.origin; +} + +TestWrSDK.prototype.on = function(event, callback) { + if (typeof callback === 'function') { + setTimeout(callback, 0); + } + return this; +}; + +TestWrSDK.prototype.isLoggedIn = function() { + return resolveLater({ authenticated: false }); +}; + +// New patient: report "not found" so the UI switches to the registration form. +TestWrSDK.prototype.recoveryInit = function() { + return rejectLater({ data: { message: 'Пользователь не найден в базе данных (тестовый контур)' } }); +}; + +TestWrSDK.prototype.registerInit = function() { + return resolveLater({ data: { rToken: 'test-rtoken-' + Date.now(), email: 'false' } }); +}; + +TestWrSDK.prototype.registerComplete = function() { + return resolveLater({ data: { text: 'Тестовый контур: аккаунт создан. Код подтверждения — любой.' } }); +}; + +TestWrSDK.prototype.recoveryComplete = function() { + return resolveLater({ data: { message: 'Тестовый контур: пароль установлен.' } }); +}; + +TestWrSDK.prototype.changeTempPassword = function() { + return resolveLater({ data: { success: 'Тестовый контур: пароль изменён.' } }); +}; + +TestWrSDK.prototype.loadLoginView = function() {}; + +TestWrSDK.prototype.loginClient = function() { + return rejectLater({ data: { message: 'Вход в тестовом контуре недоступен: МИС замокана.' } }); +}; + +function installSmartCaptcha() { + if (window.smartCaptcha && window.smartCaptcha.__test) { + return; + } + + window.smartCaptcha = { + __test: true, + render: function(container) { + if (container) { + container.innerHTML = + '
' + + 'Тестовый контур: проверка капчи отключена
'; + } + return 'test-captcha-widget'; + }, + getResponse: function() { return 'test-captcha-token'; }, + subscribe: function(widgetId, event, callback) { + if (event === 'success' && typeof callback === 'function') { + setTimeout(callback, 0); + } + }, + reset: function() {}, + execute: function() {} + }; +} + +function install() { + if (!isTestContour()) { + return false; + } + + window.WrSDK = TestWrSDK; + installSmartCaptcha(); + + return true; +} + +if (isTestContour()) { + installSmartCaptcha(); +} + +module.exports = { + isTestContour: isTestContour, + install: install +}; diff --git a/templates/security/register.html.twig b/templates/security/register.html.twig index 7d76de9..bdadef7 100644 --- a/templates/security/register.html.twig +++ b/templates/security/register.html.twig @@ -3,7 +3,9 @@ {% block title %}Регистрация пациента{% endblock %} {% block js %} - + {% if 'sova.local' not in app.request.host %} + + {% endif %} {% endblock %} {% block top %}