DweebUI/controllers/users.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-01-08 02:29:56 +00:00
import { User } from '../database/models.js';
2023-10-15 22:11:58 +00:00
2024-01-08 02:29:56 +00:00
export const Users = async (req, res) => {
let user_list = `
<tr>
<th><input class="form-check-input" type="checkbox"></th>
<th>ID</th>
<th>Avatar</th>
<th>Name</th>
<th>Username</th>
<th>Email</th>
<th>UUID</th>
<th>Role</th>
2024-01-08 02:29:56 +00:00
<th>Last Login</th>
<th>Status</th>
<th>Actions</th>
</tr>`
2023-10-15 22:11:58 +00:00
2024-01-08 02:29:56 +00:00
let allUsers = await User.findAll();
allUsers.forEach((account) => {
let active = '<span class="badge badge-outline text-green">Active</span>'
let lastLogin = new Date(account.lastLogin);
let currentDate = new Date();
let days = Math.floor((currentDate - lastLogin) / (1000 * 60 * 60 * 24));
2024-03-14 02:55:13 +00:00
let avatar = account.username.charAt(0);
2024-01-08 02:29:56 +00:00
if (days > 30) {
active = '<span class="badge badge-outline text-grey">Inactive</span>';
}
let info = `
2023-10-15 22:11:58 +00:00
<tr>
<td><input class="form-check-input" type="checkbox"></td>
2024-01-08 02:29:56 +00:00
<td>${account.id}</td>
2024-03-14 02:55:13 +00:00
<td><span class="avatar avatar-sm bg-green-lt">${avatar}</span></span>
2024-01-08 02:29:56 +00:00
<td>${account.name}</td>
<td>${account.username}</td>
<td>${account.email}</td>
<td>${account.UUID}</td>
<td>${account.role}</td>
2024-01-08 02:29:56 +00:00
<td>${account.lastLogin}</td>
<td>${active}</td>
<td><a href="#" class="btn">Edit</a></td>
2023-10-15 22:11:58 +00:00
</tr>`
2024-01-08 02:29:56 +00:00
user_list += info;
});
2023-10-15 22:11:58 +00:00
2024-01-08 02:29:56 +00:00
res.render("users", {
name: req.session.user,
role: req.session.role,
avatar: req.session.avatar,
user_list: user_list
});
2023-10-15 22:11:58 +00:00
}