users.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { User } from '../database/models.js';
  2. export const Users = async (req, res) => {
  3. let user_list = `
  4. <tr>
  5. <th><input class="form-check-input" type="checkbox"></th>
  6. <th>ID</th>
  7. <th>Avatar</th>
  8. <th>Name</th>
  9. <th>Username</th>
  10. <th>Email</th>
  11. <th>UUID</th>
  12. <th>Role</th>
  13. <th>Last Login</th>
  14. <th>Status</th>
  15. <th>Actions</th>
  16. </tr>`
  17. let allUsers = await User.findAll();
  18. allUsers.forEach((account) => {
  19. let active = '<span class="badge badge-outline text-green" title="User has logged-in within the last 30 days.">Active</span>'
  20. let lastLogin = new Date(account.lastLogin);
  21. let currentDate = new Date();
  22. let days = Math.floor((currentDate - lastLogin) / (1000 * 60 * 60 * 24));
  23. let avatar = account.username.charAt(0);
  24. if (days > 30) {
  25. active = '<span class="badge badge-outline text-grey" title="User has not logged-in within the last 30 days.">Inactive</span>';
  26. }
  27. let info = `
  28. <tr>
  29. <td><input class="form-check-input" type="checkbox"></td>
  30. <td>${account.id}</td>
  31. <td><span class="avatar avatar-sm bg-green-lt">${avatar}</span></span>
  32. <td>${account.name}</td>
  33. <td>${account.username}</td>
  34. <td>${account.email}</td>
  35. <td>${account.UUID}</td>
  36. <td>${account.role}</td>
  37. <td>${account.lastLogin}</td>
  38. <td>${active}</td>
  39. <td><a href="#" class="btn">View</a></td>
  40. </tr>`
  41. user_list += info;
  42. });
  43. res.render("users", {
  44. username: req.session.username,
  45. role: req.session.role,
  46. avatar: req.session.username.charAt(0).toUpperCase(),
  47. user_list: user_list,
  48. alert: '',
  49. link1: '',
  50. link2: '',
  51. link3: '',
  52. link4: '',
  53. link5: '',
  54. link6: '',
  55. link7: '',
  56. link8: '',
  57. link9: '',
  58. });
  59. }