File size: 9,941 Bytes
77f6e8e
 
 
 
 
e929229
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e929229
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e929229
 
 
 
 
77f6e8e
e929229
 
 
 
 
 
 
 
77f6e8e
 
e929229
 
 
 
 
 
 
 
 
 
 
 
 
 
77f6e8e
 
 
 
 
 
 
 
 
e929229
77f6e8e
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi Agent Research</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            font-family: 'Roboto', sans-serif;
        }
        #app {
            height: 100%;
            display: flex;
            flex-direction: column;
        }
        .content-wrapper {
            flex-grow: 1;
            position: relative;
            overflow: hidden;
        }
        iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border: none;
        }
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            bottom: 0;
            width: 250px;
            background-color: #2c3e50;
            color: white;
            display: flex;
            flex-direction: column;
            transition: transform 0.3s ease-in-out;
            transform: translateX(-100%);
            overflow-y: auto;
            padding-top: 60px;
            z-index: 1000;
        }
        .sidebar.open {
            transform: translateX(0);
        }
        .sidebar button {
            width: 80%;
            margin: 10px auto;
            padding: 15px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            cursor: pointer;
            text-align: center;
            transition: all 0.3s ease;
            display: block;
        }
        .sidebar button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        .toggle-btn {
            position: fixed;
            left: 10px;
            top: 10px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            cursor: pointer;
            padding: 7px 15px;
            z-index: 1001;
            transition: background-color 0.3s ease;
        }
        .toggle-btn:hover {
            background-color: #2980b9;
        }
        .category {
            width: 100%;
            margin-bottom: 20px;
        }
        .category-title {
            width: 80%;
            margin: 10px auto;
            padding: 10px;
            background-color: #34495e;
            color: white;
            border-radius: 10px;
            font-size: 16px;
            text-align: center;
            cursor: pointer;
        }
        .category-content {
            display: none;
            width: 100%;
        }
        .category-content.show {
            display: block;
        }
        .user-info {
            width: 80%;
            margin: 20px auto;
            text-align: center;
        }
        .user-name {
            margin-bottom: 10px;
            font-weight: bold;
        }
        .logout-btn {
            background-color: #e74c3c;
        }
        .logout-btn:hover {
            background-color: #c0392b;
        }

        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
            }
            .sidebar button, .category-title, .user-info {
                width: 90%;
            }
        }

        @media (max-width: 480px) {
            .sidebar button, .category-title, .user-info {
                width: 95%;
            }
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-if="loading">Loading...</div>
        <div v-else-if="error">{{ error }}</div>
        <div v-else class="content-wrapper">
            <div class="sidebar" :class="{ 'open': sidebarOpen }" id="sidebar">
                <div v-for="(apps, category) in appData" :key="category" class="category">
                    <div class="category-title" @click="toggleCategory">{{ category }}</div>
                    <div class="category-content">
                        <button v-for="app in apps" :key="app.name" @click="switchToApp(app.url)">{{ app.name }}</button>
                    </div>
                </div>
                <div class="user-info">
                    <div class="user-name">{{ userName }}</div>
                    <button class="logout-btn" @click="handleLogout">Logout</button>
                </div>
            </div>

            <button class="toggle-btn" @click="toggleSidebar"></button>
            <iframe :src="currentPage" id="iframe" allowfullscreen allow="clipboard-read; clipboard-write" sandbox="allow-scripts allow-same-origin allow-popups allow-forms allow-downloads"></iframe>
        </div>
    </div>

    <script>
        const { createApp } = Vue;

        const client = new Appwrite.Client();
        client.setEndpoint('https://cloud.appwrite.io/v1')
              .setProject('66c2f6c7000abed7f1f9');

        const account = new Appwrite.Account(client);

        const app = createApp({
            data() {
                return {
                    appData: {},
                    currentPage: '',
                    loading: true,
                    error: null,
                    sidebarOpen: false,
                    userName: ''
                }
            },
            methods: {
                async checkAuth() {
                    try {
                        console.log("Checking authentication");
                        const session = await account.getSession('current');
                        console.log("Session:", session);
                        return session;
                    } catch (error) {
                        console.error("Not authenticated", error);
                        return null;
                    }
                },
                redirectToLogin() {
                    console.log("Redirecting to login");
                    window.location.href = '/';
                },
                async checkAllowlist(email) {
                    try {
                        console.log("Checking allowlist for email:", email);
                        const response = await axios.post('http://127.0.0.1:8000/check-allowlist', { email });
                        console.log("Received response:", response.data);
                        if (response.data.allowed) {
                            console.log("Access allowed, setting app data");
                            this.appData = response.data.app_data;
                            this.currentPage = this.appData["Updated Tools"][0].url;
                        } else {
                            console.log("Access denied");
                            this.error = 'Access Denied: Your email is not on the allowlist.';
                        }
                    } catch (error) {
                        console.error("Error checking allowlist:", error);
                        this.error = 'An error occurred while checking access.';
                    } finally {
                        console.log("Setting loading to false");
                        this.loading = false;
                    }
                },
                toggleSidebar() {
                    this.sidebarOpen = !this.sidebarOpen;
                },
                toggleCategory(event) {
                    const content = event.target.nextElementSibling;
                    content.classList.toggle('show');
                },
                switchToApp(url) {
                    this.currentPage = url;
                    localStorage.setItem('currentPage', url);
                    this.toggleSidebar();
                },
                async handleLogout() {
                    const loadingElement = document.createElement('div');
                    loadingElement.textContent = 'Logging out...';
                    document.body.appendChild(loadingElement);

                    try {
                        const logoutPromise = account.deleteSession('current');
                        const timeoutPromise = new Promise((_, reject) => 
                            setTimeout(() => reject(new Error('Logout timed out')), 5000)
                        );

                        await Promise.race([logoutPromise, timeoutPromise]);

                        localStorage.clear();
                        this.redirectToLogin();
                    } catch (error) {
                        console.error("Logout failed:", error);
                        alert("Logout failed. Please try again.");
                    } finally {
                        document.body.removeChild(loadingElement);
                    }
                },
                async fetchProfileInfo() {
                    try {
                        const user = await account.get();
                        this.userName = user.name || 'User';
                        await this.checkAllowlist(user.email);
                    } catch (error) {
                        console.error("Error fetching profile info:", error);
                        this.error = 'Error loading profile information.';
                    }
                }
            },
            async mounted() {
                console.log("Component mounted");
                const session = await this.checkAuth();
                if (!session) {
                    this.redirectToLogin();
                } else {
                    await this.fetchProfileInfo();
                }
            }
        });

        app.mount('#app');
    </script>
</body>
</html>