1
0

UITabAccount.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import UIWindowChangePassword from '../UIWindowChangePassword.js';
  20. import UIWindowChangeEmail from './UIWindowChangeEmail.js';
  21. import UIWindowChangeUsername from '../UIWindowChangeUsername.js';
  22. import UIWindowConfirmUserDeletion from './UIWindowConfirmUserDeletion.js';
  23. import UIWindowManageSessions from '../UIWindowManageSessions.js';
  24. // About
  25. export default {
  26. id: 'account',
  27. title_i18n_key: 'account',
  28. icon: 'user.svg',
  29. html: () => {
  30. let h = `<h1>${i18n('account')}</h1>`;
  31. // change password button
  32. if(!window.user.is_temp){
  33. h += `<div class="settings-card">`;
  34. h += `<strong>${i18n('password')}</strong>`;
  35. h += `<div style="flex-grow:1;">`;
  36. h += `<button class="button change-password" style="float:right;">${i18n('change_password')}</button>`;
  37. h += `</div>`;
  38. h += `</div>`;
  39. }
  40. // change username button
  41. h += `<div class="settings-card">`;
  42. h += `<div>`;
  43. h += `<strong style="display:block;">${i18n('username')}</strong>`;
  44. h += `<span class="username" style="display:block; margin-top:5px;">${html_encode(window.user.username)}</span>`;
  45. h += `</div>`;
  46. h += `<div style="flex-grow:1;">`;
  47. h += `<button class="button change-username" style="float:right;">${i18n('change_username')}</button>`;
  48. h += `</div>`
  49. h += `</div>`;
  50. // change email button
  51. if(window.user.email){
  52. h += `<div class="settings-card">`;
  53. h += `<div>`;
  54. h += `<strong style="display:block;">${i18n('email')}</strong>`;
  55. h += `<span class="user-email" style="display:block; margin-top:5px;">${html_encode(window.user.email)}</span>`;
  56. h += `</div>`;
  57. h += `<div style="flex-grow:1;">`;
  58. h += `<button class="button change-email" style="float:right;">${i18n('change_email')}</button>`;
  59. h += `</div>`;
  60. h += `</div>`;
  61. }
  62. // session manager
  63. h += `<div class="settings-card">`;
  64. h += `<strong>${i18n('sessions')}</strong>`;
  65. h += `<div style="flex-grow:1;">`;
  66. h += `<button class="button manage-sessions" style="float:right;">${i18n('manage_sessions')}</button>`;
  67. h += `</div>`;
  68. h += `</div>`;
  69. // 'Delete Account' button
  70. h += `<div class="settings-card settings-card-danger">`;
  71. h += `<strong style="display: inline-block;">${i18n("delete_account")}</strong>`;
  72. h += `<div style="flex-grow:1;">`;
  73. h += `<button class="button button-danger delete-account" style="float:right;">${i18n("delete_account")}</button>`;
  74. h += `</div>`;
  75. h += `</div>`;
  76. return h;
  77. },
  78. init: ($el_window) => {
  79. $el_window.find('.change-password').on('click', function (e) {
  80. UIWindowChangePassword({
  81. window_options:{
  82. parent_uuid: $el_window.attr('data-element_uuid'),
  83. disable_parent_window: true,
  84. parent_center: true,
  85. }
  86. });
  87. });
  88. $el_window.find('.change-username').on('click', function (e) {
  89. UIWindowChangeUsername({
  90. window_options:{
  91. parent_uuid: $el_window.attr('data-element_uuid'),
  92. disable_parent_window: true,
  93. parent_center: true,
  94. }
  95. });
  96. });
  97. $el_window.find('.change-email').on('click', function (e) {
  98. UIWindowChangeEmail({
  99. window_options:{
  100. parent_uuid: $el_window.attr('data-element_uuid'),
  101. disable_parent_window: true,
  102. parent_center: true,
  103. }
  104. });
  105. });
  106. $el_window.find('.manage-sessions').on('click', function (e) {
  107. UIWindowManageSessions({
  108. window_options:{
  109. parent_uuid: $el_window.attr('data-element_uuid'),
  110. disable_parent_window: true,
  111. parent_center: true,
  112. }
  113. });
  114. });
  115. $el_window.find('.delete-account').on('click', function (e) {
  116. UIWindowConfirmUserDeletion({
  117. window_options:{
  118. parent_uuid: $el_window.attr('data-element_uuid'),
  119. disable_parent_window: true,
  120. parent_center: true,
  121. }
  122. });
  123. });
  124. },
  125. };