Norberto Montalvo García commited on
Commit
b5cf713
·
unverified ·
2 Parent(s): 3b8f524 c57da1f

Merge pull request #9 from CascoArcilla/HU8

Browse files
cata_system/settings.py CHANGED
@@ -70,7 +70,7 @@ MIDDLEWARE = [
70
 
71
  'django_browser_reload.middleware.BrowserReloadMiddleware',
72
 
73
- 'tecnicas.middlewares.LoginTesterMiddleware'
74
  ]
75
 
76
  ROOT_URLCONF = 'cata_system.urls'
 
70
 
71
  'django_browser_reload.middleware.BrowserReloadMiddleware',
72
 
73
+ 'tecnicas.middlewares.LoginTesterMiddleware',
74
  ]
75
 
76
  ROOT_URLCONF = 'cata_system.urls'
tecnicas/middlewares/login_tester_middleware.py CHANGED
@@ -6,13 +6,19 @@ class LoginTesterMiddleware():
6
  self.get_response = get_response
7
 
8
  def __call__(self, req: HttpRequest):
9
- url_protected = "/cata/testers/"
10
 
11
- if req.path.startswith(url_protected):
12
  if not "cata_username" in req.session:
 
 
 
 
13
  from django.shortcuts import redirect
14
  from django.urls import reverse
15
- return redirect(reverse("cata_system:catador_login"))
 
 
16
 
17
  response = self.get_response(req)
18
 
 
6
  self.get_response = get_response
7
 
8
  def __call__(self, req: HttpRequest):
9
+ base_url_protected = "/cata/testers/"
10
 
11
+ if req.path.startswith(base_url_protected):
12
  if not "cata_username" in req.session:
13
+ id_participacion = req.COOKIES.get("id_participacion")
14
+ if id_participacion:
15
+ from tecnicas.controllers import ParticipacionController
16
+ ParticipacionController.outSession(id_participacion)
17
  from django.shortcuts import redirect
18
  from django.urls import reverse
19
+ response = redirect(reverse("cata_system:catador_login"))
20
+ response.delete_cookie("id_participacion")
21
+ return response
22
 
23
  response = self.get_response(req)
24
 
tecnicas/static/js/actions-form.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ function exit_sesion(styleClass) {
2
+ const form = document.querySelector(`.${styleClass}`);
3
+ const action = form.querySelector(".action-input");
4
+ action.value = "exit_session";
5
+ form.submit();
6
+ }
tecnicas/static/js/created-scale.js CHANGED
@@ -81,6 +81,7 @@ async function sendRating(word) {
81
  addBtnNextWord();
82
  }
83
  } catch (error) {
 
84
  console.log("Error:", error);
85
  }
86
  }
 
81
  addBtnNextWord();
82
  }
83
  } catch (error) {
84
+ addOrRemoveWaitSpin(containerBtn, false, "La sesión ha caducado");
85
  console.log("Error:", error);
86
  }
87
  }
tecnicas/templates/tecnicas/forms_tester/convencional.html CHANGED
@@ -40,12 +40,24 @@
40
  {% block content %}
41
  <article class="w-full flex flex-col justify-center items-center bg-gray-600 mt-10 mb-10 max-sm:">
42
  <article class="flex flex-col gap-8 bg-gray-400 p-10 max-sm:py-10 max-sm:px-3 rounded container-forms">
43
- <header class="text-center flex-row w-full flex justify-around items-center flex-wrap gap-10">
44
  <h1 class="text-white rounded font-bold text-2xl bg-gray-600 p-4 flex-1">
45
- Sesión usando técnica Convencional
46
  </h1>
 
 
 
 
 
47
  </header>
48
 
 
 
 
 
 
 
 
49
  {% if error %}
50
  <hr>
51
  <article class="bg-red-600 p-4 text-white rounded-xl ct-notification-error">
@@ -88,7 +100,8 @@
88
  </section>
89
  </article>
90
 
91
- <article class="scales-container [&>*:not(:last-child)]:mb-5 min-lg:grid min-lg:items-start grid-cols-2 gap-3 flex flex-col items-center justify-center">
 
92
  {% if type_scale == "continua" %}
93
  {% for word in words %}
94
  <form action="" method="post" class="form-rating-{{word}} w-full">
@@ -166,4 +179,5 @@
166
 
167
  {% block extra_js %}
168
  <script src="{% static 'js/created-scale.js' %}"></script>
 
169
  {% endblock %}
 
40
  {% block content %}
41
  <article class="w-full flex flex-col justify-center items-center bg-gray-600 mt-10 mb-10 max-sm:">
42
  <article class="flex flex-col gap-8 bg-gray-400 p-10 max-sm:py-10 max-sm:px-3 rounded container-forms">
43
+ <header class="text-center flex-row w-full items-stretch flex justify-around flex-wrap gap-2">
44
  <h1 class="text-white rounded font-bold text-2xl bg-gray-600 p-4 flex-1">
45
+ Sesión usando <br>técnica Convencional
46
  </h1>
47
+ <button
48
+ class="text-lg font-bold tracking-wider p-2 px-8 border-b-4 active:border-b-0 active:border-t-2 active:border-blue-500 border-blue-800 transition-all rounded-xl bg-blue-500 text-gray-300"
49
+ onclick="exit_sesion('form-actions')">
50
+ Salir de la sesión
51
+ </button>
52
  </header>
53
 
54
+ <article class="hidden">
55
+ <form action="{% url 'cata_system:catador_main' %}" method="post" class="form-actions">
56
+ {% csrf_token %}
57
+ <input type="hidden" name="action" class="action-input">
58
+ </form>
59
+ </article>
60
+
61
  {% if error %}
62
  <hr>
63
  <article class="bg-red-600 p-4 text-white rounded-xl ct-notification-error">
 
100
  </section>
101
  </article>
102
 
103
+ <article
104
+ class="scales-container [&>*:not(:last-child)]:mb-5 min-lg:grid min-lg:items-start grid-cols-2 gap-3 flex flex-col items-center justify-center">
105
  {% if type_scale == "continua" %}
106
  {% for word in words %}
107
  <form action="" method="post" class="form-rating-{{word}} w-full">
 
179
 
180
  {% block extra_js %}
181
  <script src="{% static 'js/created-scale.js' %}"></script>
182
+ <script src="{% static 'js/actions-form.js' %}"></script>
183
  {% endblock %}
tecnicas/views/login_tester.py CHANGED
@@ -21,7 +21,7 @@ def testerLogin(req: HttpRequest):
21
  if isinstance(existCredentials, dict):
22
  context = {"error": existCredentials["error"]}
23
  return render(req, "tecnicas/cata-login.html", context)
24
-
25
  tester = existCredentials[0]
26
  session = existCredentials[1]
27
 
@@ -36,7 +36,11 @@ def testerLogin(req: HttpRequest):
36
  req.session["id_techniqe"] = session.tecnica.id
37
  req.session["id_participation"] = taster_participation.id
38
 
39
- req.session.set_expiry(20*60)
40
- return redirect(reverse("cata_system:catador_main"))
 
 
 
 
41
  else:
42
  return render(req, "tecnicas/cata-login.html")
 
21
  if isinstance(existCredentials, dict):
22
  context = {"error": existCredentials["error"]}
23
  return render(req, "tecnicas/cata-login.html", context)
24
+
25
  tester = existCredentials[0]
26
  session = existCredentials[1]
27
 
 
36
  req.session["id_techniqe"] = session.tecnica.id
37
  req.session["id_participation"] = taster_participation.id
38
 
39
+ req.session.set_expiry(15*60)
40
+
41
+ response = redirect(reverse("cata_system:catador_main"))
42
+ response.set_cookie('id_participacion',
43
+ taster_participation.id, max_age=60*60*24)
44
+ return response
45
  else:
46
  return render(req, "tecnicas/cata-login.html")
tecnicas/views/tester_forms/main_tester_form.py CHANGED
@@ -51,6 +51,12 @@ def mainTesterForm(req: HttpRequest):
51
  elif req.POST["action"] == "close_session":
52
  req.session.flush()
53
  return redirect(reverse("cata_system:catador_login"))
 
 
 
 
 
 
54
  else:
55
  context["error"] = "Acción sin especificar"
56
  return render(req, "tecnicas/forms_tester/main_tester.html", context)
 
51
  elif req.POST["action"] == "close_session":
52
  req.session.flush()
53
  return redirect(reverse("cata_system:catador_login"))
54
+ elif req.POST["action"] == "exit_session":
55
+ response = ParticipacionController.outSession(
56
+ req.session["id_participation"])
57
+ if isinstance(response, dict):
58
+ context["error"] = response["error"]
59
+ return render(req, "tecnicas/forms_tester/main_tester.html", context)
60
  else:
61
  context["error"] = "Acción sin especificar"
62
  return render(req, "tecnicas/forms_tester/main_tester.html", context)