diff --git a/backend/workerRoutes.js b/backend/workerRoutes.js index 21b586f..2d096cf 100644 --- a/backend/workerRoutes.js +++ b/backend/workerRoutes.js @@ -25,16 +25,16 @@ export default function(db) { const router = express.Router(); router.post('/auth/login', async (req, res) => { - const { username, password, deviceUuid } = req.body; + const { username, password } = req.body; const [rows] = await db.execute('SELECT id, role, password_hash, status FROM workers WHERE username = ?', [username]); if (rows.length === 0) { return res.status(401).json({ message: 'Invalid credentials' }); } const user = rows[0]; - // Check if the worker's status is 'active' - if (user.role === 'worker' && user.status !== 'active') { - // Return the same message as invalid credentials to avoid leaking information + // Allow both workers and managers to login + // Check if the user's status is 'active' + if (user.status !== 'active') { return res.status(401).json({ message: 'Invalid credentials' }); } @@ -42,12 +42,14 @@ export default function(db) { if (!passwordMatch) { return res.status(401).json({ message: 'Invalid credentials' }); } - if (deviceUuid && user.role !== 'manager') { - const deviceValidation = await validateDeviceForUser(user.id, deviceUuid, db); - if (!deviceValidation.valid) { - return res.status(403).json({ message: deviceValidation.message }); - } + // Check if worker has device_uuid (Android device) + if (user.role === 'worker') { + const [deviceRows] = await db.execute('SELECT device_uuid FROM workers WHERE id = ?', [user.id]); + if (deviceRows[0].device_uuid) { + return res.status(403).json({ message: 'useMobileApp' }); + } } + // Managers can always login, workers without device_uuid can login const token = jwt.sign({ userId: user.id, role: user.role }, process.env.JWT_SECRET, { expiresIn: '1h' }); res.json({ token }); }); diff --git a/package-lock.json b/package-lock.json index 848bd6f..64edba2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@capacitor/cli": "^7.4.0", "@capacitor/core": "^7.4.0", + "@heroicons/vue": "^2.2.0", "@turf/turf": "^7.2.0", "bcrypt": "^6.0.0", "body-parser": "^2.2.0", @@ -1206,6 +1207,15 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@heroicons/vue": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@heroicons/vue/-/vue-2.2.0.tgz", + "integrity": "sha512-G3dbSxoeEKqbi/DFalhRxJU4mTXJn7GwZ7ae8NuEQzd1bqdd0jAbdaBZlHPcvPD2xI1iGzNVB4k20Un2AguYPw==", + "license": "MIT", + "peerDependencies": { + "vue": ">= 3" + } + }, "node_modules/@humanfs/core": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", diff --git a/package.json b/package.json index f41df41..937e625 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dependencies": { "@capacitor/cli": "^7.4.0", "@capacitor/core": "^7.4.0", + "@heroicons/vue": "^2.2.0", "@turf/turf": "^7.2.0", "bcrypt": "^6.0.0", "body-parser": "^2.2.0", diff --git a/src/App.vue b/src/App.vue index a7976c3..aa4cb34 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,19 +8,20 @@ class="flex justify-between items-center px-4 py-3 sm:px-8 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 shadow-sm transition-colors duration-300">

{{ $t('appTitle') }}

- - - - +
+ +
+
+ + +
+