-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFronten.html
More file actions
114 lines (105 loc) · 3 KB
/
Fronten.html
File metadata and controls
114 lines (105 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Accounts, Roles & Permissions</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
select, button {
margin: 5px 0;
padding: 8px 12px;
border-radius: 6px;
}
button {
border: none;
background: #4CAF50;
color: white;
cursor: pointer;
}
button:hover {
background: #45a049;
}
#status {
margin-top: 20px;
padding: 12px;
border: 1px solid #ccc;
border-radius: 5px;
background: #f9f9f9;
min-height: 30px;
}
</style>
</head>
<body>
<h2>User Accounts with Roles & Permissions</h2>
<label for="userSelect">Select User:</label>
<select id="userSelect"></select>
<p>
<button onclick="checkRole('admin')">Check Admin Role</button>
<button onclick="checkRole('editor')">Check Editor Role</button>
<button onclick="checkPermission('write')">Check Write Permission</button>
<button onclick="checkPermission('delete')">Check Delete Permission</button>
</p>
<div id="status">Select a user and click a button to check roles or permissions.</div>
<script>
// Store user accounts, roles, and permissions
const users = [
{
id: 1,
username: "karol",
roles: ["admin", "editor"],
permissions: ["read", "write", "delete"]
},
{
id: 2,
username: "alice",
roles: ["viewer"],
permissions: ["read"]
},
{
id: 3,
username: "bob",
roles: ["editor"],
permissions: ["read", "write"]
}
];
// Populate dropdown with users
const userSelect = document.getElementById("userSelect");
users.forEach(user => {
const option = document.createElement("option");
option.value = user.id;
option.textContent = user.username;
userSelect.appendChild(option);
});
// Get selected user
function getSelectedUser() {
const id = parseInt(userSelect.value, 10);
return users.find(user => user.id === id);
}
// Check if user has a role
function checkRole(role) {
const user = getSelectedUser();
if (!user) {
return displayStatus("No user selected.");
}
const hasRole = user.roles.includes(role);
displayStatus(`${user.username} has role "${role}": ${hasRole}`);
}
// Check if user has a permission
function checkPermission(permission) {
const user = getSelectedUser();
if (!user) {
return displayStatus("No user selected.");
}
const hasPermission = user.permissions.includes(permission);
displayStatus(`${user.username} has permission "${permission}": ${hasPermission}`);
}
// Display results
function displayStatus(message) {
document.getElementById("status").textContent = message;
}
</script>
</body>
</html>