|
12 | 12 | <div id="navdiv"></div> |
13 | 13 | </nav> |
14 | 14 |
|
15 | | - <form action="/control/user/{{ user.id }}" method="POST"> |
16 | | - <label for="callsign">Callsign:</label> |
17 | | - <input type="text" id="callsign" name="callsign" value="{{ user.callsign }}"><br> |
18 | | - <label for="name">Name:</label> |
19 | | - <input type="text" id="name" name="name" value="{{ user.name }}"><br> |
20 | | - <label for="permissions">Requested permissions:</label> |
21 | | - <select id="permissions" name="permissions"> |
22 | | - <option value="0" {% if user.permissions == 0 %}selected{% endif %}>none</option> |
23 | | - <option {% if user.permissions == 1 %}selected{% endif %} value="1">admin</option> |
24 | | - </select><br> |
25 | | - {% if user.pwdhash %} |
26 | | - <p>User has password<br> |
27 | | - {{ user.pwdhash }}</p> |
28 | | - {% else %} |
29 | | - <p>User doesn't have a password set</p> |
30 | | - {% endif %} |
31 | | - <input type="{{ 'text' if user.permissions == 1 else 'hidden'}}" id="password" name="password" placeholder="enter password"><br> |
32 | | - <label for="active">Active user?</label> |
33 | | - <input {% if user.active %}checked{% endif %} type="checkbox" name="active"><br> |
34 | | - <input type="hidden" name="csrf" value="{{ csrf }}"> |
35 | | - <button type="submit">Update user</button><br> |
36 | | - </form> |
37 | | - <button onclick="deleteUser()">Delete user</button> |
| 15 | + <label for="callsign">Callsign:</label> |
| 16 | + <input type="text" id="callsign" name="callsign" value="{{ user.callsign }}"><br> |
| 17 | + <label for="name">Name:</label> |
| 18 | + <input type="text" id="name" name="name" value="{{ user.name }}"><br> |
| 19 | + <label for="permissions">Requested permissions:</label> |
| 20 | + <select id="permissions" name="permissions"> |
| 21 | + <option value="0" {% if user.permissions == 0 %}selected{% endif %}>none</option> |
| 22 | + <option {% if user.permissions == 1 %}selected{% endif %} value="1">admin</option> |
| 23 | + </select><br> |
| 24 | + {% if user.pwdhash %} |
| 25 | + <p>User has password<br> |
| 26 | + {{ user.pwdhash }}</p> |
| 27 | + {% else %} |
| 28 | + <p>User doesn't have a password set</p> |
| 29 | + {% endif %} |
| 30 | + <input type="{{ 'text' if user.permissions == 1 else 'hidden'}}" id="password" name="password" placeholder="enter password"><br> |
| 31 | + <label for="active">Active user?</label> |
| 32 | + <input {% if user.active %}checked{% endif %} type="checkbox" name="active" id="active"><br> |
| 33 | + <input type="hidden" name="csrf" value="{{ csrf }}" id="csrf"> |
| 34 | + <button type="button" onclick="updateUser()">Update user</button><br> |
| 35 | + <button type="button" onclick="deleteUser()">Delete user</button> |
38 | 36 | <script src="{{ url_for('static', filename='dompurify.js') }}"></script> |
39 | 37 | <script src="{{ url_for('static', filename='nav.js') }}"></script> |
40 | 38 | <script> |
|
60 | 58 | } else if (response.status === 403) { |
61 | 59 | alert("403, eyes on me...\nYou don't have permission to delete this person!"); |
62 | 60 | } else { |
63 | | - alert(`There was something strange going on. We didn't account for it, but here it is:\n${response.status}\n${msg}`); |
| 61 | + alert(`An error occured that prevented the user from being deleted:\n${response.status}\n${msg}`); |
| 62 | + } |
| 63 | + } |
| 64 | + async function updateUser() { |
| 65 | + const callsign = document.getElementById("callsign"); |
| 66 | + const name = document.getElementById("name"); |
| 67 | + const permissions = document.getElementById("permissions"); |
| 68 | + const active = document.getElementById("active"); |
| 69 | + const csrf = document.getElementById("csrf"); |
| 70 | + let activeV; |
| 71 | + if (active.checked) { |
| 72 | + activeV = 1; |
| 73 | + } else { |
| 74 | + activeV = 0; |
| 75 | + } |
| 76 | + const response = await fetch(window.location.pathname, { |
| 77 | + method: "POST", |
| 78 | + headers: { |
| 79 | + "Content-Type": "application/json" |
| 80 | + }, |
| 81 | + body: JSON.stringify({ |
| 82 | + callsign: callsign.value, |
| 83 | + name: name.value, |
| 84 | + active: activeV, |
| 85 | + csrf: csrf.value, |
| 86 | + permissions: permissions.value |
| 87 | + }) |
| 88 | + }); |
| 89 | + if (response.ok) { |
| 90 | + window.location.href = "/control"; |
| 91 | + } else { |
| 92 | + msg = await response.text(); |
| 93 | + alert(`An error occured that prevented the user from being deleted.\nStatus code: ${response.status}\nReason: ${msg}`); |
64 | 94 | } |
65 | 95 | } |
66 | 96 | </script> |
|
0 commit comments