Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/routes/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import express from 'express';
import jwt from 'jsonwebtoken';
import { User } from '../models/index.js';
import { auth } from '../middleware/auth.js';
import { log } from 'console';
import { authValidators } from '../middleware/validators.js';
const router = express.Router();
// Login
router.post('/login', authValidators.login, async (req, res) => {
try {
const { email, password } = req.body;
const user = await User.findOne({ where: { email, is_active: true } });
if (!user) {
return res.status(400).json({ message: 'Invalid credentials' });
}
const isMatch = await user.comparePassword(password);
if (!isMatch) {
return res.status(400).json({ message: 'Invalid credentials' });
}
// Update last login
await user.update({ last_login: new Date() });
const token = jwt.sign(
{ id: user.id, email: user.email, role: user.role },
process.env.JWT_SECRET,
{ expiresIn: '24h' }
);
res.json({
token,
user: {
id: user.id,
name: user.name,
email: user.email,
role: user.role,
permissions: user.permissions,
department: user.department,
phone: user.phone,
is_active: user.is_active,
last_login: user.last_login,
avatar: user.avatar
}
});
} catch (error) {
console.error('Login error:', error);
res.status(500).json({ message: 'Server error' });
}
});
// Get current user
router.get('/me', auth, async (req, res) => {
try {
const user = await User.findByPk(req.user.id, {
attributes: { exclude: ['password'] }
});
res.json(user);
} catch (error) {
console.error('Get user error:', error);
res.status(500).json({ message: 'Server error' });
}
});
// Change password
router.put('/change-password', auth, authValidators.changePassword, async (req, res) => {
try {
const { currentPassword, newPassword } = req.body;
const user = await User.findByPk(req.user.id);
const isMatch = await user.comparePassword(currentPassword);
if (!isMatch) {
return res.status(400).json({ message: 'Current password is incorrect' });
}
await user.update({ password: newPassword });
res.json({ message: 'Password updated successfully' });
} catch (error) {
console.error('Change password error:', error);
res.status(500).json({ message: 'Server error' });
}
});
export default router; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0034 ]-- |