iatoolkit 0.63.1__py3-none-any.whl → 0.69.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of iatoolkit might be problematic. Click here for more details.

Files changed (83) hide show
  1. iatoolkit/__init__.py +0 -2
  2. iatoolkit/base_company.py +1 -26
  3. iatoolkit/common/routes.py +11 -2
  4. iatoolkit/common/session_manager.py +2 -0
  5. iatoolkit/common/util.py +17 -0
  6. iatoolkit/company_registry.py +1 -2
  7. iatoolkit/iatoolkit.py +39 -6
  8. iatoolkit/locales/en.yaml +167 -0
  9. iatoolkit/locales/es.yaml +163 -0
  10. iatoolkit/repositories/database_manager.py +8 -3
  11. iatoolkit/repositories/document_repo.py +1 -1
  12. iatoolkit/repositories/models.py +1 -4
  13. iatoolkit/repositories/profile_repo.py +0 -4
  14. iatoolkit/services/auth_service.py +14 -9
  15. iatoolkit/services/branding_service.py +36 -24
  16. iatoolkit/services/company_context_service.py +145 -0
  17. iatoolkit/services/configuration_service.py +133 -0
  18. iatoolkit/services/dispatcher_service.py +51 -48
  19. iatoolkit/services/document_service.py +5 -2
  20. iatoolkit/services/excel_service.py +15 -11
  21. iatoolkit/services/file_processor_service.py +4 -12
  22. iatoolkit/services/history_service.py +8 -7
  23. iatoolkit/services/i18n_service.py +104 -0
  24. iatoolkit/services/jwt_service.py +7 -9
  25. iatoolkit/services/language_service.py +83 -0
  26. iatoolkit/services/load_documents_service.py +4 -4
  27. iatoolkit/services/mail_service.py +9 -4
  28. iatoolkit/services/profile_service.py +61 -38
  29. iatoolkit/services/prompt_manager_service.py +20 -16
  30. iatoolkit/services/query_service.py +19 -15
  31. iatoolkit/services/search_service.py +11 -4
  32. iatoolkit/services/sql_service.py +55 -25
  33. iatoolkit/services/user_feedback_service.py +16 -14
  34. iatoolkit/static/js/chat_feedback_button.js +57 -87
  35. iatoolkit/static/js/chat_help_content.js +124 -0
  36. iatoolkit/static/js/chat_history_button.js +48 -65
  37. iatoolkit/static/js/chat_main.js +27 -24
  38. iatoolkit/static/js/chat_onboarding_button.js +6 -0
  39. iatoolkit/static/js/chat_reload_button.js +28 -45
  40. iatoolkit/static/styles/chat_iatoolkit.css +223 -315
  41. iatoolkit/static/styles/chat_modal.css +63 -97
  42. iatoolkit/static/styles/chat_public.css +107 -0
  43. iatoolkit/static/styles/landing_page.css +0 -1
  44. iatoolkit/static/styles/onboarding.css +7 -0
  45. iatoolkit/templates/_company_header.html +6 -2
  46. iatoolkit/templates/_login_widget.html +42 -0
  47. iatoolkit/templates/base.html +34 -19
  48. iatoolkit/templates/change_password.html +22 -20
  49. iatoolkit/templates/chat.html +59 -27
  50. iatoolkit/templates/chat_modals.html +114 -74
  51. iatoolkit/templates/error.html +12 -13
  52. iatoolkit/templates/forgot_password.html +11 -7
  53. iatoolkit/templates/index.html +8 -3
  54. iatoolkit/templates/login_simulation.html +17 -6
  55. iatoolkit/templates/onboarding_shell.html +4 -2
  56. iatoolkit/templates/signup.html +14 -14
  57. iatoolkit/views/base_login_view.py +19 -9
  58. iatoolkit/views/change_password_view.py +50 -35
  59. iatoolkit/views/external_login_view.py +1 -1
  60. iatoolkit/views/forgot_password_view.py +21 -22
  61. iatoolkit/views/help_content_api_view.py +54 -0
  62. iatoolkit/views/history_api_view.py +13 -9
  63. iatoolkit/views/home_view.py +30 -39
  64. iatoolkit/views/init_context_api_view.py +16 -11
  65. iatoolkit/views/llmquery_api_view.py +38 -26
  66. iatoolkit/views/login_simulation_view.py +14 -2
  67. iatoolkit/views/login_view.py +52 -40
  68. iatoolkit/views/logout_api_view.py +26 -22
  69. iatoolkit/views/profile_api_view.py +46 -0
  70. iatoolkit/views/prompt_api_view.py +6 -6
  71. iatoolkit/views/signup_view.py +27 -27
  72. iatoolkit/views/user_feedback_api_view.py +19 -18
  73. iatoolkit/views/verify_user_view.py +29 -30
  74. {iatoolkit-0.63.1.dist-info → iatoolkit-0.69.0.dist-info}/METADATA +40 -22
  75. iatoolkit-0.69.0.dist-info/RECORD +120 -0
  76. iatoolkit-0.69.0.dist-info/licenses/LICENSE +21 -0
  77. iatoolkit/services/onboarding_service.py +0 -43
  78. iatoolkit/static/styles/chat_info.css +0 -53
  79. iatoolkit/templates/header.html +0 -31
  80. iatoolkit/templates/test.html +0 -9
  81. iatoolkit-0.63.1.dist-info/RECORD +0 -112
  82. {iatoolkit-0.63.1.dist-info → iatoolkit-0.69.0.dist-info}/WHEEL +0 -0
  83. {iatoolkit-0.63.1.dist-info → iatoolkit-0.69.0.dist-info}/top_level.txt +0 -0
@@ -1,15 +1,25 @@
1
1
  {% extends "base.html" %}
2
2
 
3
- {% block title %}Prueba de Login para {{ company_short_name }}{% endblock %}
3
+ {% block title %}Login Test - {{ branding.name }}{% endblock %}
4
+ {% block styles %}
5
+ <style>
6
+ {{ branding.css_variables | safe }}
7
+ </style>
8
+ <link rel="stylesheet" href="{{ url_for('static', filename='styles/chat_public.css') }}">
9
+ {% endblock %}
4
10
 
5
11
  {% block content %}
12
+ <div class="container mt-4">
13
+
14
+ {% include '_company_header.html' %}
15
+
6
16
  <div class="container-fluid">
7
17
  <div class="row flex-fill mt-5 justify-content-center">
8
18
  <div class="col-12 col-lg-6">
9
- <div class="border rounded p-4 p-md-5 shadow-sm bg-light">
10
- <h3 class="text-muted fw-semibold text-start mb-3">
11
- Login Externo para <span style="color:#0d6efd;">{{ company_short_name }}</span>
12
- </h3>
19
+ <div class="branded-form-container">
20
+ <h4 class="branded-form-title">
21
+ Login Externo para {{ company_short_name }}
22
+ </h4>
13
23
  <div class="text-center mb-4">
14
24
  <p class="text-muted widget-intro-text">
15
25
  Este formulario simula el inicio de una sesión externa. Al enviar, serás redirigido a la URL de login final.
@@ -22,7 +32,7 @@
22
32
  <label for="external_user_id" class="form-label d-block">External user ID</label>
23
33
  <input type="text" id="external_user_id" name="external_user_id" class="form-control" required>
24
34
  </div>
25
- <button type="submit" class="btn btn-primary">
35
+ <button type="submit" class="btn btn-branded-primary">
26
36
  Redirigir a External Login
27
37
  </button>
28
38
  </form>
@@ -30,5 +40,6 @@
30
40
  </div>
31
41
  </div>
32
42
  </div>
43
+ </div>
33
44
  {% endblock %}
34
45
 
@@ -1,6 +1,6 @@
1
1
  {% extends "base.html" %}
2
2
 
3
- {% block title %}Iniciando {{ branding.name | default('IAToolkit') }} IA...{% endblock %}
3
+ {% block title %}Iniciando {{ branding.name }} IA...{% endblock %}
4
4
 
5
5
  {% block styles %}
6
6
  {% endblock %}
@@ -11,7 +11,6 @@
11
11
  <link rel="stylesheet" href="{{ url_for('static', filename='styles/onboarding.css', _external=True) }}?v=6">
12
12
 
13
13
  <style>
14
- {# 1. Definimos las variables de la marca PRIMERO #}
15
14
  {% if branding and branding.css_variables %}
16
15
  {{ branding.css_variables|safe }}
17
16
  {% endif %}
@@ -46,6 +45,8 @@
46
45
  <div id="card-icon" class="ob-icon"><i class="fas fa-lightbulb"></i></div>
47
46
  <h3 id="card-title" class="ob-title">Título de la Tarjeta</h3>
48
47
  <p id="card-text" class="ob-text">Descripción de la tarjeta de capacitación.</p>
48
+ <p id="card-example" class="ob-example"></p>
49
+
49
50
  <div class="ob-nav">
50
51
  <button id="prev-card" class="ob-btn btn-branded-primary" aria-label="Anterior">
51
52
  <i class="fas fa-chevron-left"></i>
@@ -89,6 +90,7 @@
89
90
  icon: '#card-icon',
90
91
  title: '#card-title',
91
92
  text: '#card-text',
93
+ example: '#card-example',
92
94
  dots: '#progress-dots',
93
95
  prev: '#prev-card',
94
96
  next: '#next-card',
@@ -1,30 +1,30 @@
1
1
  {% extends "base.html" %}
2
2
 
3
- {% block title %}Crear Cuenta - {{ branding.name }}{% endblock %}
3
+ {% block title %}{{ t('ui.signup.title') }} - {{ branding.name }}{% endblock %}
4
4
 
5
5
  {% block styles %}
6
6
  {# ¡Importante! Añadimos los estilos para el branding #}
7
7
  <style>
8
8
  {{ branding.css_variables | safe }}
9
9
  </style>
10
- <link rel="stylesheet" href="{{ url_for('static', filename='styles/chat_iatoolkit.css') }}">
10
+ <link rel="stylesheet" href="{{ url_for('static', filename='styles/chat_public.css') }}">
11
11
  {% endblock %}
12
12
 
13
13
  {% block content %}
14
- {% include '_company_header.html' %}
14
+ <div class="container mt-4">
15
15
 
16
+ {% include '_company_header.html' %}
16
17
 
17
- <!-- 3. Sección contenedora para centrar el contenido -->
18
18
  <section class="hero-section">
19
19
  <div class="container">
20
20
  <div class="row justify-content-center">
21
21
  <!-- Se ha reducido el ancho de la columna a lg-6 y md-8 -->
22
22
  <div class="col-lg-6 col-md-8">
23
23
  <div class="branded-form-container">
24
- <h4 class="branded-form-title">Crea tu cuenta en {{ company.name }}</h4>
24
+ <h4 class="branded-form-title">{{ t('ui.signup.title') }}</h4>
25
25
  <form action="{{ url_for('signup', company_short_name=company_short_name) }}" method="post">
26
26
  <div class="mb-3">
27
- <label for="email" class="form-label text-secondary">Correo Electrónico</label>
27
+ <label for="email" class="form-label text-secondary">{{ t('ui.signup.email_label') }}</label>
28
28
  <input type="email" autocomplete="off" id="email" name="email"
29
29
  class="form-control" required
30
30
  value="{{ form_data.email if form_data else '' }}">
@@ -32,13 +32,13 @@
32
32
 
33
33
  <div class="row">
34
34
  <div class="col-md-6 mb-3">
35
- <label for="first_name" class="form-label text-secondary">Nombre</label>
35
+ <label for="first_name" class="form-label text-secondary">{{ t('ui.signup.first_name_label') }}</label>
36
36
  <input type="text" id="first_name" name="first_name"
37
37
  class="form-control" required
38
38
  value="{{ form_data.first_name if form_data else '' }}">
39
39
  </div>
40
40
  <div class="col-md-6 mb-3">
41
- <label for="last_name" class="form-label text-secondary">Apellido</label>
41
+ <label for="last_name" class="form-label text-secondary">{{ t('ui.signup.last_name_label') }}</label>
42
42
  <input type="text" id="last_name" name="last_name"
43
43
  class="form-control" required
44
44
  value="{{ form_data.last_name if form_data else '' }}">
@@ -46,31 +46,31 @@
46
46
  </div>
47
47
 
48
48
  <div class="mb-3">
49
- <label for="password" class="form-label text-secondary">Contraseña</label>
49
+ <label for="password" class="form-label text-secondary">{{ t('ui.signup.password_label') }}</label>
50
50
  <input type="password" id="password" name="password" class="form-control" required>
51
- <!-- Bloque de ayuda para la contraseña mejorado -->
52
51
  <div class="d-flex align-items-start text-muted mt-2" style="font-size: 0.8rem;">
53
52
  <i class="bi bi-info-circle me-2" style="font-size: 0.9rem; line-height: 1.4;"></i>
54
- <span>Debe contener al menos 8 caracteres, mayúscula, minúscula, número y un carácter especial.</span>
53
+ <span>{{ t('ui.change_password.password_instructions') }}</span>
55
54
  </div>
56
55
  </div>
57
56
 
58
57
  <div class="mb-3">
59
- <label for="confirm_password" class="form-label text-secondary">Confirmar Contraseña</label>
58
+ <label for="confirm_password" class="form-label text-secondary">{{ t('ui.signup.confirm_password_label') }}</label>
60
59
  <input type="password" id="confirm_password" name="confirm_password" class="form-control" required>
61
60
  </div>
62
61
 
63
62
  <!-- Botón actualizado con la clase de branding -->
64
- <button type="submit" class="btn btn-branded-primary w-100 fw-bold py-2 mt-3">Registrarse</button>
63
+ <button type="submit" class="btn btn-branded-primary w-100 fw-bold py-2 mt-3">{{ t('ui.signup.signup_button') }}</button>
65
64
  </form>
66
65
  <!-- Nota de privacidad -->
67
66
  <p class="text-muted small mb-0 text-center mt-4">
68
- 🔒 Valoramos tu privacidad. Tus datos se usarán exclusivamente para el funcionamiento de la plataforma.
67
+ {{ t('ui.signup.disclaimer') }}
69
68
  </p>
70
69
  </div>
71
70
  </div>
72
71
  </div>
73
72
  </div>
74
73
  </section>
74
+ </div>
75
75
 
76
76
  {% endblock %}
@@ -11,8 +11,10 @@ from iatoolkit.services.profile_service import ProfileService
11
11
  from iatoolkit.services.auth_service import AuthService
12
12
  from iatoolkit.services.query_service import QueryService
13
13
  from iatoolkit.services.branding_service import BrandingService
14
- from iatoolkit.services.onboarding_service import OnboardingService
14
+ from iatoolkit.services.configuration_service import ConfigurationService
15
15
  from iatoolkit.services.prompt_manager_service import PromptService
16
+ from iatoolkit.services.i18n_service import I18nService
17
+ from iatoolkit.common.util import Utility
16
18
  from iatoolkit.services.jwt_service import JWTService
17
19
  from iatoolkit.repositories.models import Company
18
20
 
@@ -29,20 +31,24 @@ class BaseLoginView(MethodView):
29
31
  jwt_service: JWTService,
30
32
  branding_service: BrandingService,
31
33
  prompt_service: PromptService,
32
- onboarding_service: OnboardingService,
33
- query_service: QueryService
34
+ config_service: ConfigurationService,
35
+ query_service: QueryService,
36
+ i18n_service: I18nService,
37
+ utility: Utility
34
38
  ):
35
39
  self.profile_service = profile_service
36
40
  self.auth_service = auth_service
37
41
  self.jwt_service = jwt_service
38
42
  self.branding_service = branding_service
39
43
  self.prompt_service = prompt_service
40
- self.onboarding_service = onboarding_service
44
+ self.config_service = config_service
41
45
  self.query_service = query_service
46
+ self.i18n_service = i18n_service
47
+ self.utility = utility
42
48
 
43
49
 
44
50
  def _handle_login_path(self,
45
- company: Company,
51
+ company_short_name: str,
46
52
  user_identifier: str,
47
53
  target_url: str,
48
54
  redeem_token: str = None):
@@ -50,13 +56,12 @@ class BaseLoginView(MethodView):
50
56
  Centralized logic to decide between the fast path and the slow path.
51
57
  """
52
58
  # --- Get the company branding and onboarding_cards
53
- branding_data = self.branding_service.get_company_branding(company)
54
- onboarding_cards = self.onboarding_service.get_onboarding_cards(company)
55
- company_short_name = company.short_name
59
+ branding_data = self.branding_service.get_company_branding(company_short_name)
60
+ onboarding_cards = self.config_service.get_configuration(company_short_name, 'onboarding_cards')
56
61
 
57
62
  # this service decides is the context needs to be rebuilt or not
58
63
  prep_result = self.query_service.prepare_context(
59
- company_short_name=company.short_name, user_identifier=user_identifier
64
+ company_short_name=company_short_name, user_identifier=user_identifier
60
65
  )
61
66
 
62
67
  if prep_result.get('rebuild_needed'):
@@ -70,6 +75,10 @@ class BaseLoginView(MethodView):
70
75
  else:
71
76
  # --- FAST PATH: Render the chat page directly ---
72
77
  prompts = self.prompt_service.get_user_prompts(company_short_name)
78
+
79
+ # Get the entire 'js_messages' block in the correct language.
80
+ js_translations = self.i18n_service.get_translation_block('js_messages')
81
+
73
82
  return render_template(
74
83
  "chat.html",
75
84
  company_short_name=company_short_name,
@@ -77,5 +86,6 @@ class BaseLoginView(MethodView):
77
86
  prompts=prompts,
78
87
  branding=branding_data,
79
88
  onboarding_cards=onboarding_cards,
89
+ js_translations=js_translations,
80
90
  redeem_token=redeem_token
81
91
  )
@@ -4,9 +4,10 @@
4
4
  # IAToolkit is open source software.
5
5
 
6
6
  from flask.views import MethodView
7
- from flask import render_template, request, url_for, session, redirect
7
+ from flask import render_template, request, url_for, session, redirect, flash
8
8
  from iatoolkit.services.profile_service import ProfileService
9
9
  from iatoolkit.services.branding_service import BrandingService
10
+ from iatoolkit.services.i18n_service import I18nService
10
11
  from itsdangerous import URLSafeTimedSerializer, SignatureExpired
11
12
  from flask_bcrypt import Bcrypt
12
13
  from injector import inject
@@ -17,51 +18,65 @@ class ChangePasswordView(MethodView):
17
18
  @inject
18
19
  def __init__(self,
19
20
  profile_service: ProfileService,
20
- branding_service: BrandingService):
21
+ branding_service: BrandingService,
22
+ i18n_service: I18nService):
21
23
  self.profile_service = profile_service
22
- self.branding_service = branding_service # 3. Guardar la instancia
24
+ self.branding_service = branding_service
25
+ self.i18n_service = i18n_service
23
26
 
24
27
  self.serializer = URLSafeTimedSerializer(os.getenv("PASS_RESET_KEY"))
25
28
  self.bcrypt = Bcrypt()
26
29
 
27
30
  def get(self, company_short_name: str, token: str):
28
- # get company info
29
- company = self.profile_service.get_company_by_short_name(company_short_name)
30
- if not company:
31
- return render_template('error.html', message=f"Empresa no encontrada: {company_short_name}"), 404
31
+ try:
32
+ company = self.profile_service.get_company_by_short_name(company_short_name)
33
+ if not company:
34
+ return render_template('error.html',
35
+ message=self.i18n_service.t('errors.templates.company_not_found')), 404
32
36
 
33
- branding_data = self.branding_service.get_company_branding(company)
37
+ branding_data = self.branding_service.get_company_branding(company_short_name)
34
38
 
35
- try:
36
- # Decodificar el token
37
- email = self.serializer.loads(token, salt='password-reset', max_age=3600)
38
- except SignatureExpired as e:
39
- return render_template('forgot_password.html',
40
- branding=branding_data,
41
- alert_message="El enlace de cambio de contraseña ha expirado. Por favor, solicita uno nuevo.")
39
+ try:
40
+ # Decodificar el token
41
+ email = self.serializer.loads(token, salt='password-reset', max_age=3600)
42
+ except SignatureExpired as e:
43
+ flash(self.i18n_service.t('errors.change_password.token_expired'), 'error')
44
+ return render_template('forgot_password.html',
45
+ branding=branding_data)
42
46
 
43
- return render_template('change_password.html',
44
- company_short_name=company_short_name,
45
- company=company,
46
- branding=branding_data,
47
- token=token, email=email)
47
+ return render_template('change_password.html',
48
+ company_short_name=company_short_name,
49
+ company=company,
50
+ branding=branding_data,
51
+ token=token,
52
+ email=email)
53
+ except Exception as e:
54
+ message = self.i18n_service.t('errors.templates.processing_error', error=str(e))
55
+ return render_template(
56
+ "error.html",
57
+ company_short_name=company_short_name,
58
+ branding=branding_data,
59
+ message=message
60
+ ), 500
48
61
 
49
62
  def post(self, company_short_name: str, token: str):
50
63
  # get company info
51
64
  company = self.profile_service.get_company_by_short_name(company_short_name)
52
65
  if not company:
53
- return render_template('error.html', message=f"Empresa no encontrada: {company_short_name}"), 404
66
+ return render_template('error.html',
67
+ message=self.i18n_service.t('errors.templates.company_not_found')), 404
54
68
 
55
- branding_data = self.branding_service.get_company_branding(company)
69
+ branding_data = self.branding_service.get_company_branding(company_short_name)
56
70
  try:
57
71
  # Decodificar el token
58
72
  email = self.serializer.loads(token, salt='password-reset', max_age=3600)
59
73
  except SignatureExpired:
74
+ flash(self.i18n_service.t('errors.change_password.token_expired'), 'error')
75
+
60
76
  return render_template('forgot_password.html',
61
77
  company_short_name=company_short_name,
62
78
  company=company,
63
- branding=branding_data,
64
- alert_message="El enlace de cambio de contraseña ha expirado. Por favor, solicita uno nuevo.")
79
+ branding=branding_data)
65
80
 
66
81
  try:
67
82
  # Obtener datos del formulario
@@ -77,25 +92,25 @@ class ChangePasswordView(MethodView):
77
92
  )
78
93
 
79
94
  if "error" in response:
95
+ flash(response["error"], 'error')
96
+
80
97
  return render_template(
81
98
  'change_password.html',
82
99
  token=token,
83
100
  company_short_name=company_short_name,
84
- company=company,
85
101
  branding=branding_data,
86
102
  form_data={"temp_code": temp_code,
87
103
  "new_password": new_password,
88
- "confirm_password": confirm_password},
89
- alert_message=response["error"]), 400
104
+ "confirm_password": confirm_password}), 400
90
105
 
91
- # Éxito: Guardar mensaje en sesión y redirigir
92
- session['alert_message'] = "Tu contraseña ha sido restablecida exitosamente. Ahora puedes iniciar sesión."
93
- session['alert_icon'] = 'success'
106
+ flash(self.i18n_service.t('flash_messages.password_changed_success'), 'success')
94
107
  return redirect(url_for('home', company_short_name=company_short_name))
95
108
 
96
109
  except Exception as e:
97
- return render_template("error.html",
98
- company=company,
99
- company_short_name=company_short_name,
100
- branding=branding_data,
101
- message=f"Ha ocurrido un error inesperado: {str(e)}"), 500
110
+ message = self.i18n_service.t('errors.templates.processing_error', error=str(e))
111
+ return render_template(
112
+ "error.html",
113
+ company_short_name=company_short_name,
114
+ branding=branding_data,
115
+ message=message
116
+ ), 500
@@ -47,7 +47,7 @@ class ExternalLoginView(BaseLoginView):
47
47
 
48
48
  # 5. Delegate the path decision to the centralized logic.
49
49
  try:
50
- return self._handle_login_path(company, user_identifier, target_url, redeem_token)
50
+ return self._handle_login_path(company_short_name, user_identifier, target_url, redeem_token)
51
51
  except Exception as e:
52
52
  logging.exception(f"Error processing external login path for {company_short_name}/{user_identifier}: {e}")
53
53
  return jsonify({"error": f"Internal server error while starting chat. {str(e)}"}), 500
@@ -4,41 +4,47 @@
4
4
  # IAToolkit is open source software.
5
5
 
6
6
  from flask.views import MethodView
7
- from flask import render_template, request, url_for, redirect, session
7
+ from flask import render_template, request, url_for, redirect, session, flash
8
8
  from injector import inject
9
9
  from iatoolkit.services.profile_service import ProfileService
10
10
  from iatoolkit.services.branding_service import BrandingService
11
+ from iatoolkit.services.i18n_service import I18nService
11
12
  from itsdangerous import URLSafeTimedSerializer
12
13
  import os
13
14
 
14
15
  class ForgotPasswordView(MethodView):
15
16
  @inject
16
17
  def __init__(self, profile_service: ProfileService,
17
- branding_service: BrandingService):
18
+ branding_service: BrandingService,
19
+ i18n_service: I18nService):
18
20
  self.profile_service = profile_service
19
- self.branding_service = branding_service # 3. Guardar la instancia
21
+ self.branding_service = branding_service
22
+ self.i18n_service = i18n_service
23
+
20
24
  self.serializer = URLSafeTimedSerializer(os.getenv("PASS_RESET_KEY"))
21
25
 
22
26
  def get(self, company_short_name: str):
23
27
  # get company info
24
28
  company = self.profile_service.get_company_by_short_name(company_short_name)
25
29
  if not company:
26
- return render_template('error.html', message="Empresa no encontrada"), 404
30
+ return render_template('error.html',
31
+ message=self.i18n_service.t('errors.templates.company_not_found')), 404
27
32
 
28
- branding_data = self.branding_service.get_company_branding(company)
33
+ branding_data = self.branding_service.get_company_branding(company_short_name)
29
34
  return render_template('forgot_password.html',
30
- company=company,
31
35
  company_short_name=company_short_name,
32
36
  branding=branding_data
33
37
  )
34
38
 
35
39
  def post(self, company_short_name: str):
36
- company = self.profile_service.get_company_by_short_name(company_short_name)
37
- if not company:
38
- return render_template('error.html', message="Empresa no encontrada"), 404
39
- branding_data = self.branding_service.get_company_branding(company)
40
40
 
41
41
  try:
42
+ company = self.profile_service.get_company_by_short_name(company_short_name)
43
+ if not company:
44
+ return render_template('error.html',
45
+ message=self.i18n_service.t('errors.templates.company_not_found')), 404
46
+
47
+ branding_data = self.branding_service.get_company_branding(company_short_name)
42
48
  email = request.form.get('email')
43
49
 
44
50
  # create a safe token and url for it
@@ -49,23 +55,16 @@ class ForgotPasswordView(MethodView):
49
55
 
50
56
  response = self.profile_service.forgot_password(email=email, reset_url=reset_url)
51
57
  if "error" in response:
58
+ flash(response["error"], 'error')
52
59
  return render_template(
53
60
  'forgot_password.html',
54
- company=company,
55
61
  company_short_name=company_short_name,
56
62
  branding=branding_data,
57
- form_data={"email": email},
58
- alert_message=response["error"]), 400
63
+ form_data={"email": email}), 400
59
64
 
60
- # Guardamos el mensaje y el icono en la sesión manualmente
61
- session['alert_message'] = "Si tu correo está registrado, recibirás un enlace para restablecer tu contraseña."
62
- session['alert_icon'] = "success"
65
+ flash(self.i18n_service.t('flash_messages.forgot_password_success'), 'success')
63
66
  return redirect(url_for('home', company_short_name=company_short_name))
64
67
 
65
68
  except Exception as e:
66
- return render_template("error.html",
67
- company=company,
68
- company_short_name=company_short_name,
69
- branding=branding_data,
70
- message=f"Ha ocurrido un error inesperado: {str(e)}"), 500
71
-
69
+ flash(self.i18n_service.t('errors.general.unexpected_error'), 'error')
70
+ return redirect(url_for('home', company_short_name=company_short_name))
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2024 Fernando Libedinsky
2
+ # Product: IAToolkit
3
+ #
4
+ # IAToolkit is open source software.
5
+
6
+ from flask import request, jsonify
7
+ from flask.views import MethodView
8
+ from iatoolkit.services.configuration_service import ConfigurationService
9
+ from iatoolkit.services.i18n_service import I18nService
10
+ from iatoolkit.services.auth_service import AuthService
11
+ from injector import inject
12
+ import logging
13
+
14
+
15
+ class HelpContentApiView(MethodView):
16
+ """
17
+ Handles requests from the web UI to fetch a user's query history.
18
+ Authentication is based on the active Flask session.
19
+ """
20
+
21
+ @inject
22
+ def __init__(self,
23
+ auth_service: AuthService,
24
+ config_service: ConfigurationService,
25
+ i18n_service: I18nService):
26
+ self.auth_service = auth_service
27
+ self.config_service = config_service
28
+ self.i18n_service = i18n_service
29
+
30
+ def post(self, company_short_name: str):
31
+ try:
32
+ # 1. Get the authenticated user's
33
+ auth_result = self.auth_service.verify()
34
+ if not auth_result.get("success"):
35
+ return jsonify(auth_result), auth_result.get("status_code")
36
+
37
+ user_identifier = auth_result.get('user_identifier')
38
+
39
+ # 2. Call the config service with the unified identifier.
40
+ response = self.config_service.get_configuration(
41
+ company_short_name=company_short_name,
42
+ content_key='help_content' # specific key for this service
43
+ )
44
+
45
+ if "error" in response:
46
+ # Handle errors reported by the service itself.
47
+ return jsonify({'error_message': response["error"]}), 400
48
+
49
+ return jsonify(response), 200
50
+
51
+ except Exception as e:
52
+ logging.exception(
53
+ f"Unexpected error fetching help_content for {company_short_name}: {e}")
54
+ return jsonify({"error_message": self.i18n_service.t('errors.general.unexpected_error', error=str(e))}), 500
@@ -7,6 +7,7 @@ from flask import request, jsonify
7
7
  from flask.views import MethodView
8
8
  from iatoolkit.services.history_service import HistoryService
9
9
  from iatoolkit.services.auth_service import AuthService
10
+ from iatoolkit.services.i18n_service import I18nService
10
11
  from injector import inject
11
12
  import logging
12
13
 
@@ -20,19 +21,22 @@ class HistoryApiView(MethodView):
20
21
  @inject
21
22
  def __init__(self,
22
23
  auth_service: AuthService,
23
- history_service: HistoryService):
24
+ history_service: HistoryService,
25
+ i18n_service: I18nService):
24
26
  self.auth_service = auth_service
25
27
  self.history_service = history_service
28
+ self.i18n_service = i18n_service
29
+
26
30
 
27
31
  def post(self, company_short_name: str):
28
- # 1. Get the authenticated user's
29
- auth_result = self.auth_service.verify()
30
- if not auth_result.get("success"):
31
- return jsonify(auth_result), auth_result.get("status_code")
32
+ try:
33
+ # 1. Get the authenticated user's
34
+ auth_result = self.auth_service.verify()
35
+ if not auth_result.get("success"):
36
+ return jsonify(auth_result), auth_result.get("status_code")
32
37
 
33
- user_identifier = auth_result.get('user_identifier')
38
+ user_identifier = auth_result.get('user_identifier')
34
39
 
35
- try:
36
40
  # 2. Call the history service with the unified identifier.
37
41
  # The service's signature should now only expect user_identifier.
38
42
  response = self.history_service.get_history(
@@ -48,5 +52,5 @@ class HistoryApiView(MethodView):
48
52
 
49
53
  except Exception as e:
50
54
  logging.exception(
51
- f"Unexpected error fetching history for {company_short_name}/{user_identifier}: {e}")
52
- return jsonify({"error_message": "Ha ocurrido un error inesperado en el servidor."}), 500
55
+ f"Unexpected error: {e}")
56
+ return jsonify({"error_message": self.i18n_service.t('errors.general.unexpected_error', error=str(e))}), 500