users.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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">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. if (days > 30) {
  24. active = '<span class="badge badge-outline text-grey">Inactive</span>';
  25. }
  26. let info = `
  27. <tr>
  28. <td><input class="form-check-input" type="checkbox"></td>
  29. <td>${account.id}</td>
  30. <td><span class="avatar me-2">${account.avatar}</span></td>
  31. <td>${account.name}</td>
  32. <td>${account.username}</td>
  33. <td>${account.email}</td>
  34. <td>${account.UUID}</td>
  35. <td>${account.role}</td>
  36. <td>${account.lastLogin}</td>
  37. <td>${active}</td>
  38. <td><a href="#" class="btn">Edit</a></td>
  39. </tr>`
  40. user_list += info;
  41. });
  42. res.render("users", {
  43. name: req.session.user,
  44. role: req.session.role,
  45. avatar: req.session.avatar,
  46. user_list: user_list
  47. });
  48. }