Nicolasmed26 commited on
Commit
eeaa556
·
verified ·
1 Parent(s): 714c7f2

Deploy MedMembers OFT 2026

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -1
  2. auth/middleware.py +3 -1
  3. static/index.html +9 -9
  4. static/js/auth.js +86 -10
Dockerfile CHANGED
@@ -7,7 +7,7 @@ COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Bust cache for static files (change this value to force rebuild)
10
- ARG CACHE_BUST=20260406v3
11
 
12
  # Copy application code
13
  COPY . .
 
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Bust cache for static files (change this value to force rebuild)
10
+ ARG CACHE_BUST=20260406v4
11
 
12
  # Copy application code
13
  COPY . .
auth/middleware.py CHANGED
@@ -11,8 +11,10 @@ def require_auth(f):
11
  auth_header = request.headers.get('Authorization', '')
12
  if auth_header.startswith('Bearer '):
13
  token = auth_header[7:]
14
- else:
15
  token = request.args.get('token')
 
 
16
 
17
  if not token:
18
  return jsonify({'error': 'Token de autenticação não fornecido'}), 401
 
11
  auth_header = request.headers.get('Authorization', '')
12
  if auth_header.startswith('Bearer '):
13
  token = auth_header[7:]
14
+ if not token:
15
  token = request.args.get('token')
16
+ if not token:
17
+ token = request.cookies.get('mm_token')
18
 
19
  if not token:
20
  return jsonify({'error': 'Token de autenticação não fornecido'}), 401
static/index.html CHANGED
@@ -4,8 +4,8 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>MedMembers OFT 2026 - Banco de Questões</title>
7
- <link rel="stylesheet" href="/static/css/main.css?v=3">
8
- <link rel="stylesheet" href="/static/css/protection.css?v=3">
9
  <meta name="robots" content="noindex, nofollow">
10
  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
11
  </head>
@@ -49,12 +49,12 @@
49
 
50
  <!-- Scripts -->
51
  <script src="/static/js/socket.io.min.js"></script>
52
- <script src="/static/js/auth.js?v=3"></script>
53
- <script src="/static/js/protection.js?v=3"></script>
54
- <script src="/static/js/heartbeat.js?v=3"></script>
55
- <script src="/static/js/questions.js?v=3"></script>
56
- <script src="/static/js/simulado.js?v=3"></script>
57
- <script src="/static/js/admin.js?v=3"></script>
58
- <script src="/static/js/app.js?v=3"></script>
59
  </body>
60
  </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>MedMembers OFT 2026 - Banco de Questões</title>
7
+ <link rel="stylesheet" href="/static/css/main.css?v=4">
8
+ <link rel="stylesheet" href="/static/css/protection.css?v=4">
9
  <meta name="robots" content="noindex, nofollow">
10
  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
11
  </head>
 
49
 
50
  <!-- Scripts -->
51
  <script src="/static/js/socket.io.min.js"></script>
52
+ <script src="/static/js/auth.js?v=4"></script>
53
+ <script src="/static/js/protection.js?v=4"></script>
54
+ <script src="/static/js/heartbeat.js?v=4"></script>
55
+ <script src="/static/js/questions.js?v=4"></script>
56
+ <script src="/static/js/simulado.js?v=4"></script>
57
+ <script src="/static/js/admin.js?v=4"></script>
58
+ <script src="/static/js/app.js?v=4"></script>
59
  </body>
60
  </html>
static/js/auth.js CHANGED
@@ -1,13 +1,75 @@
1
- // ===== Authentication Module =====
 
 
2
 
3
  const Auth = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  getToken() {
5
- return sessionStorage.getItem('mm_token');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  },
7
 
8
  getUser() {
9
- const data = sessionStorage.getItem('mm_user');
10
- return data ? JSON.parse(data) : null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  },
12
 
13
  isAdmin() {
@@ -16,13 +78,27 @@ const Auth = {
16
  },
17
 
18
  setSession(token, user) {
19
- sessionStorage.setItem('mm_token', token);
20
- sessionStorage.setItem('mm_user', JSON.stringify(user));
 
 
 
 
 
 
 
 
21
  },
22
 
23
  clearSession() {
24
- sessionStorage.removeItem('mm_token');
25
- sessionStorage.removeItem('mm_user');
 
 
 
 
 
 
26
  },
27
 
28
  async login(email, password) {
@@ -42,7 +118,7 @@ const Auth = {
42
  await fetch('/api/auth/logout', {
43
  method: 'POST',
44
  headers: {
45
- 'Authorization': `Bearer ${this.getToken()}`,
46
  'Content-Type': 'application/json'
47
  }
48
  });
@@ -54,7 +130,7 @@ const Auth = {
54
 
55
  headers() {
56
  return {
57
- 'Authorization': `Bearer ${this.getToken()}`,
58
  'Content-Type': 'application/json'
59
  };
60
  }
 
1
+ // ===== Authentication Module (v3 - cookie + storage fallback) =====
2
+ // Uses cookies as primary storage (works in HF Spaces iframe)
3
+ // Falls back to sessionStorage if available
4
 
5
  const Auth = {
6
+ _memoryToken: null,
7
+ _memoryUser: null,
8
+
9
+ _setCookie(name, value, days) {
10
+ let expires = '';
11
+ if (days) {
12
+ const date = new Date();
13
+ date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
14
+ expires = '; expires=' + date.toUTCString();
15
+ }
16
+ document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/; SameSite=Lax';
17
+ },
18
+
19
+ _getCookie(name) {
20
+ const nameEQ = name + '=';
21
+ const ca = document.cookie.split(';');
22
+ for (let i = 0; i < ca.length; i++) {
23
+ let c = ca[i].trim();
24
+ if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length));
25
+ }
26
+ return null;
27
+ },
28
+
29
+ _deleteCookie(name) {
30
+ document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
31
+ },
32
+
33
  getToken() {
34
+ // Try memory first (fastest)
35
+ if (this._memoryToken) return this._memoryToken;
36
+ // Try cookie
37
+ const cookieToken = this._getCookie('mm_token');
38
+ if (cookieToken) {
39
+ this._memoryToken = cookieToken;
40
+ return cookieToken;
41
+ }
42
+ // Try sessionStorage as fallback
43
+ try {
44
+ const ssToken = sessionStorage.getItem('mm_token');
45
+ if (ssToken) {
46
+ this._memoryToken = ssToken;
47
+ return ssToken;
48
+ }
49
+ } catch(e) {}
50
+ return null;
51
  },
52
 
53
  getUser() {
54
+ // Try memory first
55
+ if (this._memoryUser) return this._memoryUser;
56
+ // Try cookie
57
+ const cookieUser = this._getCookie('mm_user');
58
+ if (cookieUser) {
59
+ try {
60
+ this._memoryUser = JSON.parse(cookieUser);
61
+ return this._memoryUser;
62
+ } catch(e) {}
63
+ }
64
+ // Try sessionStorage as fallback
65
+ try {
66
+ const data = sessionStorage.getItem('mm_user');
67
+ if (data) {
68
+ this._memoryUser = JSON.parse(data);
69
+ return this._memoryUser;
70
+ }
71
+ } catch(e) {}
72
+ return null;
73
  },
74
 
75
  isAdmin() {
 
78
  },
79
 
80
  setSession(token, user) {
81
+ this._memoryToken = token;
82
+ this._memoryUser = user;
83
+ // Save to cookie (1 day expiry)
84
+ this._setCookie('mm_token', token, 1);
85
+ this._setCookie('mm_user', JSON.stringify(user), 1);
86
+ // Also try sessionStorage
87
+ try {
88
+ sessionStorage.setItem('mm_token', token);
89
+ sessionStorage.setItem('mm_user', JSON.stringify(user));
90
+ } catch(e) {}
91
  },
92
 
93
  clearSession() {
94
+ this._memoryToken = null;
95
+ this._memoryUser = null;
96
+ this._deleteCookie('mm_token');
97
+ this._deleteCookie('mm_user');
98
+ try {
99
+ sessionStorage.removeItem('mm_token');
100
+ sessionStorage.removeItem('mm_user');
101
+ } catch(e) {}
102
  },
103
 
104
  async login(email, password) {
 
118
  await fetch('/api/auth/logout', {
119
  method: 'POST',
120
  headers: {
121
+ 'Authorization': 'Bearer ' + this.getToken(),
122
  'Content-Type': 'application/json'
123
  }
124
  });
 
130
 
131
  headers() {
132
  return {
133
+ 'Authorization': 'Bearer ' + this.getToken(),
134
  'Content-Type': 'application/json'
135
  };
136
  }