You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
8.9 KiB

4 years ago
  1. {% extends "bootstrap/base.html" %}
  2. {% block title %}Manage your Technical Incompetence account{% endblock %}
  3. {% block styles %}
  4. {{super()}}
  5. <link rel="stylesheet" href="{{url_for('.static', filename='style.css')}}">
  6. {% endblock %}
  7. {% block navbar %}
  8. <nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark">
  9. <div class="navbar-brand">Technical Incompetence Account</div>
  10. <form class="form-inline ml-auto">
  11. {# <div class="custom-control custom-switch">
  12. <input type="checkbox" class="custom-control-input" id="darkSwitch" />
  13. <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
  14. </div>
  15. <div class="navbar-text" style="margin-right: 20px; ">{{ user['userName'] }}</div> #}
  16. <a class="btn btn-primary" href="/logout" role="button">Logout</a>
  17. </form>
  18. </nav>
  19. {% endblock %}
  20. {% block content %}
  21. <div class="container" style="margin-top: 15px">
  22. <div id="success-alert" class="alert alert-success" role="alert" style="display: none;">
  23. This is a success alert—check it out!
  24. </div>
  25. <div id="error-alert" class="alert alert-danger" role="alert" style="display: none;">
  26. This is a danger alert—check it out!
  27. </div>
  28. <form>
  29. <div class="row">
  30. <div class="col-lg-6" id="firstNameRow">
  31. <label for="formGroupExampleInput1">First name</label>
  32. <input id="firstName" type="text" class="form-control" placeholder="First name" value="{{ user['firstName'] }}">
  33. </div>
  34. <div class="col-lg-6">
  35. <label for="formGroupExampleInput2">Last name</label>
  36. <input id="lastName" type="text" class="form-control" placeholder="Last name" value="{{ user['lastName'] }}">
  37. </div>
  38. </div>
  39. <br>
  40. <button type="button" class="btn btn-primary" onclick="updateName();">Change Name</button>
  41. </form>
  42. <br><br>
  43. <form>
  44. <div class="row">
  45. <div class="col-lg-6" id="userNameRow">
  46. <label for="formGroupExampleInput3">Username</label>
  47. <input id="userName" type="text" class="form-control" placeholder="Username" value="{{ user['userName'] }}">
  48. <br>
  49. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#userNameWarningModal">Change Username</button>
  50. <br>
  51. </div>
  52. <div class="col-lg-6">
  53. <label for="formGroupExampleInput4">Email</label>
  54. <input id="email" type="email" class="form-control" placeholder="Email" value="{{ user['email'] }}">
  55. <br>
  56. <button type="button" class="btn btn-primary" onclick="updateEmail();">Change Email</button>
  57. <br>
  58. </div>
  59. </div>
  60. </form>
  61. <br><br>
  62. <form>
  63. <button id="passwordButton" type="button" class="btn btn-danger" data-toggle="modal" data-target="#passwordChangeModal">Change Password</button>
  64. </form>
  65. </div>
  66. <div id="userNameWarningModal" class="modal fade" tabindex="-1" role="dialog">
  67. <div class="modal-dialog" role="document">
  68. <div class="modal-content">
  69. <div class="modal-header">
  70. <h5 class="modal-title">Warning</h5>
  71. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  72. <span aria-hidden="true">&times;</span>
  73. </button>
  74. </div>
  75. <div class="modal-body">
  76. <div id="username-alert" class="alert alert-danger" role="alert" style="display: none;">
  77. This is a danger alert—check it out!
  78. </div>
  79. <p>If you change your username, you will be logged out here and likely need to re-login in everywhere with your new username.</p>
  80. </div>
  81. <div class="modal-footer">
  82. <button type="button" class="btn btn-danger" onclick="updateUserName();">Save new username</button>
  83. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <div id="passwordChangeModal" class="modal fade" tabindex="-1" role="dialog">
  89. <div class="modal-dialog" role="document">
  90. <div class="modal-content">
  91. <div class="modal-header">
  92. <h5 class="modal-title">Update Password</h5>
  93. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  94. <span aria-hidden="true">&times;</span>
  95. </button>
  96. </div>
  97. <div class="modal-body">
  98. <div id="password-alert" class="alert alert-danger" role="alert" style="display: none;">
  99. This is a danger alert—check it out!
  100. </div>
  101. <p>If you change your username, you will be logged out here and likely need to re-login in everywhere with your new username.</p>
  102. <form style="padding: .75rem 1.25rem;">
  103. <div class="row">
  104. <label for="formGroupExampleInput5">Current Password</label>
  105. <input id="currentPassword" type="password" class="form-control" placeholder="Current Password">
  106. </div>
  107. <br>
  108. <div class="row">
  109. <label for="formGroupExampleInput6">New Password</label>
  110. <input id="newPassword" type="password" class="form-control" placeholder="New Password">
  111. </div>
  112. <br>
  113. <div class="row">
  114. <label for="formGroupExampleInput6">Confirm New Password</label>
  115. <input id="confirmNewPassword" type="password" class="form-control" placeholder="Confirm New Password">
  116. </div>
  117. </form>
  118. </div>
  119. <div class="modal-footer">
  120. <button type="button" class="btn btn-danger" onclick="updatePassword();">Change Password</button>
  121. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. {% endblock %}
  127. {% block scripts %}
  128. {{ super() }}
  129. <script>
  130. function updateEmail() {
  131. email = $('#email').val();
  132. if (email.trim().length === 0) {
  133. showError('Email is required');
  134. return false;
  135. }
  136. dn = '{{ user['dn'] }}';
  137. $.ajax({
  138. url: '/update/email',
  139. method: 'POST',
  140. data: { "email": email,
  141. "dn": dn },
  142. success: function(data) {
  143. if (data === 'Success')
  144. showSuccess('Email updated!');
  145. else
  146. showError(data);
  147. }
  148. });
  149. }
  150. function updateName() {
  151. first = $('#firstName').val();
  152. last = $('#lastName').val();
  153. if (first.trim().length === 0 || last.trim().length === 0) {
  154. showError('Both first and last name are required');
  155. return false;
  156. }
  157. dn = '{{ user['dn'] }}';
  158. $.ajax({
  159. url: '/update/name',
  160. method: 'POST',
  161. data: { "firstName": first,
  162. "lastName": last,
  163. "dn": dn },
  164. success: function(data) {
  165. if (data === 'Success')
  166. showSuccess('Name updated!');
  167. else
  168. showError(data);
  169. }
  170. });
  171. }
  172. function updateUserName() {
  173. user = $('#userName').val();
  174. if (user.trim().length === 0) {
  175. showUsernameError('Username is required');
  176. return false;
  177. }
  178. dn = '{{ user['dn'] }}';
  179. $.ajax({
  180. url: '/update/username',
  181. method: 'POST',
  182. data: { "userName": user,
  183. "dn": dn },
  184. success: function(data) {
  185. if (data === 'Success')
  186. window.location = window.location.origin + "/logout";
  187. else
  188. showUsernameError(data);
  189. }
  190. });
  191. }
  192. function updatePassword() {
  193. currentPassword = $('#currentPassword').val();
  194. newPassword = $('#newPassword').val();
  195. confirmPassword = $('#confirmNewPassword').val();
  196. dn = '{{ user['dn'] }}';
  197. $.ajax({
  198. url: '/update/password',
  199. method: 'POST',
  200. data: { "currentPassword": currentPassword,
  201. "newPassword": newPassword,
  202. "confirmPassword": confirmPassword,
  203. "dn": dn },
  204. success: function(data) {
  205. if (data === 'Success')
  206. window.location = window.location.origin + "/logout";
  207. else
  208. showPasswordError(data)
  209. }
  210. });
  211. }
  212. function showError(error) {
  213. hideSuccess();
  214. $('#error-alert').text(error);
  215. $('#error-alert').show();
  216. }
  217. function showPasswordError(error) {
  218. $('#password-alert').text(error);
  219. $('#password-alert').show();
  220. }
  221. function showUsernameError(error) {
  222. $('#username-alert').text(error);
  223. $('#username-alert').show();
  224. }
  225. function hideError() {
  226. $('#error-alert').hide();
  227. }
  228. function showSuccess(message) {
  229. hideError();
  230. $('#success-alert').text(message);
  231. $('#success-alert').show();
  232. }
  233. function hideSuccess() {
  234. $('#success-alert').hide();
  235. }
  236. </script>
  237. {% endblock %}