users.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const User = require('../database/UserModel');
  2. exports.Users = async function(req, res) {
  3. if (req.session.role == "admin") {
  4. // Get the user.
  5. let user = await User.findOne({ where: { UUID: req.session.UUID }});
  6. let user_list = `
  7. <tr>
  8. <th><input class="form-check-input" type="checkbox"></th>
  9. <th>ID</th>
  10. <th>Avatar</th>
  11. <th>Name</th>
  12. <th>Username</th>
  13. <th>Email</th>
  14. <th>UUID</th>
  15. <th>Role</th>
  16. <th>Status</th>
  17. <th>Actions</th>
  18. </tr>`
  19. let users = await User.findAll();
  20. users.forEach((account) => {
  21. full_name = account.first_name + ' ' + account.last_name;
  22. user_info = `
  23. <tr>
  24. <td><input class="form-check-input" type="checkbox"></td>
  25. <td>${user.id}</td>
  26. <td><span class="avatar me-2">${account.avatar}</span></td>
  27. <td>${full_name}</td>
  28. <td>${account.username}</td>
  29. <td>${account.email}</td>
  30. <td>${account.UUID}</td>
  31. <td>${account.role}</td>
  32. <td><span class="badge badge-outline text-green">Active</span></td>
  33. <td><a href="#" class="btn">Edit</a></td>
  34. </tr>`
  35. user_list += user_info;
  36. });
  37. // Render the home page
  38. res.render("pages/users", {
  39. name: user.first_name + ' ' + user.last_name,
  40. role: user.role,
  41. avatar: user.avatar,
  42. isLoggedIn: true,
  43. user_list: user_list
  44. });
  45. } else {
  46. // Redirect to the login page
  47. res.redirect("/login");
  48. }
  49. }