-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
120 lines (107 loc) · 2.41 KB
/
index.js
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
const express = require('express');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const app = express();
app.use(bodyParser.json());
const SECRET_KEY = 'your-secret-key';
// Mock user data for authentication
const mockUsers = [
{
id: 1,
email: 'testuser1@test.com',
password: 'testpassword1',
name: 'Test User 1',
is_in_Charge: true
},
{
id: 2,
email: 'testuser2@test.com',
password: 'testpassword2',
name: 'Test User 2',
is_in_Charge: false
}
];
// Mock event data
const mockEvents = [
{
id: 1,
date_start: '19-2-2023',
date_end: '19-2-2023',
time_start: '19:20',
time_end: '20:20',
notify_time_frame: 20,
location: '',
event_name: 'Test Event 1',
extraData: ''
},
{
id: 2,
date_start: '20-2-2023',
date_end: '20-2-2023',
time_start: '19:30',
time_end: '20:30',
notify_time_frame: 30,
location: '',
event_name: 'Test Event 2',
extraData: ''
}
];
// Mock notes data
const mockNotes = [
{
id: 1,
name: 'Test Note 1',
Creation_date: '2023-04-05T11:45:00Z',
text: 'This is a test note.',
audio: ''
},
{
id: 2,
name: 'Test Note 2',
Creation_date: '2023-04-05T12:00:00Z',
text: '',
audio: 'https://test-audio-url.com'
}
];
// Mock reminders data
const mockReminders = [
{
date: '19-2-2023',
Topic: 'Test Reminder 1',
extraData: ''
},
{
date: '20-2-2023',
Topic: 'Test Reminder 2',
extraData: ''
}
];
// Login route
app.post('/api/user/login', (req, res) => {
const { email, password } = req.body;
const user = mockUsers.find(user => user.email === email && user.password === password);
if (!user) {
return res.status(401).json({ message: 'Invalid credentials' });
}
const token = jwt.sign({ id: user.id }, SECRET_KEY);
return res.status(200).json({ user, token});
});
// Signup route
app.post('/api/user/signup', (req, res) => {
const { email, password, name, is_in_Charge } = req.body;
// Add new user to mockUsers array
const newUser = {
id: mockUsers.length + 1,
email,
password,
name,
is_in_Charge
};
mockUsers.push(newUser);
return res.status(200).json({ message: 'Signup successful' });
});
// Logout route
app.post('/api/user/logout', (req, res) => {
// TODO: Implement logout functionality
return res.status(200).json({ message: 'Logout successful' });
});