RemoveAccount.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <script setup lang="ts">
  2. import { useStore } from "vuex";
  3. import { ref, onMounted } from "vue";
  4. import { useRoute } from "vue-router";
  5. import Toast from "toasters";
  6. defineProps({
  7. modalUuid: { type: String, default: "" }
  8. });
  9. const route = useRoute();
  10. const store = useStore();
  11. const { socket } = store.state.websockets;
  12. const isPasswordLinked = () => store.dispatch("settings/isPasswordLinked");
  13. const isGithubLinked = () => store.dispatch("settings/isGithubLinked");
  14. const closeCurrentModal = () =>
  15. store.dispatch("modalVisibility/closeCurrentModal");
  16. const step = ref("confirm-identity");
  17. const apiDomain = ref("");
  18. const accountRemovalMessage = ref("");
  19. const password = ref({
  20. value: "",
  21. visible: false
  22. });
  23. const passwordElement = ref();
  24. const checkForAutofill = (cb, event) => {
  25. if (
  26. event.target.value !== "" &&
  27. event.inputType === undefined &&
  28. event.data === undefined &&
  29. event.dataTransfer === undefined &&
  30. event.isComposing === undefined
  31. )
  32. cb();
  33. };
  34. const submitOnEnter = (cb, event) => {
  35. if (event.which === 13) cb();
  36. };
  37. const togglePasswordVisibility = () => {
  38. if (passwordElement.value.type === "password") {
  39. passwordElement.value.type = "text";
  40. password.value.visible = true;
  41. } else {
  42. passwordElement.value.type = "password";
  43. password.value.visible = false;
  44. }
  45. };
  46. const confirmPasswordMatch = () =>
  47. socket.dispatch("users.confirmPasswordMatch", password.value.value, res => {
  48. if (res.status === "success") step.value = "remove-account";
  49. else new Toast(res.message);
  50. });
  51. const confirmGithubLink = () =>
  52. socket.dispatch("users.confirmGithubLink", res => {
  53. if (res.status === "success") {
  54. if (res.data.linked) step.value = "remove-account";
  55. else {
  56. new Toast(
  57. `Your GitHub account isn't linked. Please re-link your account and try again.`
  58. );
  59. step.value = "relink-github";
  60. }
  61. } else new Toast(res.message);
  62. });
  63. const relinkGithub = () => {
  64. localStorage.setItem(
  65. "github_redirect",
  66. `${window.location.pathname + window.location.search}${
  67. !route.query.removeAccount ? "&removeAccount=relinked-github" : ""
  68. }`
  69. );
  70. };
  71. const remove = () =>
  72. socket.dispatch("users.remove", res => {
  73. if (res.status === "success") {
  74. return socket.dispatch("users.logout", () =>
  75. lofig.get("cookie").then(cookie => {
  76. document.cookie = `${cookie.SIDname}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
  77. closeCurrentModal();
  78. window.location.href = "/";
  79. })
  80. );
  81. }
  82. return new Toast(res.message);
  83. });
  84. onMounted(async () => {
  85. apiDomain.value = await lofig.get("backend.apiDomain");
  86. accountRemovalMessage.value = await lofig.get("messages.accountRemoval");
  87. });
  88. </script>
  89. <template>
  90. <modal
  91. title="Confirm Account Removal"
  92. class="confirm-account-removal-modal"
  93. >
  94. <template #body>
  95. <div id="steps">
  96. <p
  97. class="step"
  98. :class="{ selected: step === 'confirm-identity' }"
  99. >
  100. 1
  101. </p>
  102. <span class="divider"></span>
  103. <p
  104. class="step"
  105. :class="{
  106. selected:
  107. (isPasswordLinked && step === 'export-data') ||
  108. step === 'relink-github'
  109. }"
  110. >
  111. 2
  112. </p>
  113. <span class="divider"></span>
  114. <p
  115. class="step"
  116. :class="{
  117. selected:
  118. (isPasswordLinked && step === 'remove-account') ||
  119. step === 'export-data'
  120. }"
  121. >
  122. 3
  123. </p>
  124. <span class="divider" v-if="!isPasswordLinked"></span>
  125. <p
  126. class="step"
  127. :class="{ selected: step === 'remove-account' }"
  128. v-if="!isPasswordLinked"
  129. >
  130. 4
  131. </p>
  132. </div>
  133. <div
  134. class="content-box"
  135. id="password-linked"
  136. v-if="step === 'confirm-identity' && isPasswordLinked"
  137. >
  138. <h2 class="content-box-title">Enter your password</h2>
  139. <p class="content-box-description">
  140. Confirming your password will let us verify your identity.
  141. </p>
  142. <p class="content-box-optional-helper">
  143. <router-link id="forgot-password" to="/reset_password">
  144. Forgot password?
  145. </router-link>
  146. </p>
  147. <div class="content-box-inputs">
  148. <div class="control is-grouped input-with-button">
  149. <div id="password-visibility-container">
  150. <input
  151. class="input"
  152. type="password"
  153. placeholder="Enter password here..."
  154. autofocus
  155. ref="passwordElement"
  156. v-model="password.value"
  157. @input="
  158. checkForAutofill(
  159. confirmPasswordMatch,
  160. $event
  161. )
  162. "
  163. @keypress="
  164. submitOnEnter(confirmPasswordMatch, $event)
  165. "
  166. />
  167. <a @click="togglePasswordVisibility()">
  168. <i class="material-icons">
  169. {{
  170. !password.visible
  171. ? "visibility"
  172. : "visibility_off"
  173. }}
  174. </i>
  175. </a>
  176. </div>
  177. <p class="control">
  178. <button
  179. class="button is-info"
  180. @click="confirmPasswordMatch()"
  181. >
  182. Check
  183. </button>
  184. </p>
  185. </div>
  186. </div>
  187. </div>
  188. <div
  189. class="content-box"
  190. v-else-if="isGithubLinked && step === 'confirm-identity'"
  191. >
  192. <h2 class="content-box-title">Verify your GitHub</h2>
  193. <p class="content-box-description">
  194. Check your account is still linked to remove your account.
  195. </p>
  196. <div class="content-box-inputs">
  197. <a class="button is-github" @click="confirmGithubLink()">
  198. <div class="icon">
  199. <img
  200. class="invert"
  201. src="/assets/social/github.svg"
  202. />
  203. </div>
  204. &nbsp; Check GitHub is linked
  205. </a>
  206. </div>
  207. </div>
  208. <div class="content-box" v-if="step === 'relink-github'">
  209. <h2 class="content-box-title">Re-link GitHub</h2>
  210. <p class="content-box-description">
  211. Re-link your GitHub account in order to verify your
  212. identity.
  213. </p>
  214. <div class="content-box-inputs">
  215. <a
  216. class="button is-github"
  217. @click="relinkGithub()"
  218. :href="`${apiDomain}/auth/github/link`"
  219. >
  220. <div class="icon">
  221. <img
  222. class="invert"
  223. src="/assets/social/github.svg"
  224. />
  225. </div>
  226. &nbsp; Re-link GitHub to account
  227. </a>
  228. </div>
  229. </div>
  230. <div v-if="step === 'export-data'">
  231. DOWNLOAD A BACKUP OF YOUR DATA BEFORE ITS PERMENATNELY DELETED
  232. </div>
  233. <div
  234. class="content-box"
  235. id="remove-account-container"
  236. v-if="step === 'remove-account'"
  237. >
  238. <h2 class="content-box-title">Remove your account</h2>
  239. <p class="content-box-description">
  240. {{ accountRemovalMessage }}
  241. </p>
  242. <div class="content-box-inputs">
  243. <quick-confirm placement="right" @confirm="remove()">
  244. <button class="button">
  245. <i class="material-icons">delete</i>
  246. &nbsp;Remove Account
  247. </button>
  248. </quick-confirm>
  249. </div>
  250. </div>
  251. </template>
  252. </modal>
  253. </template>
  254. <style lang="less">
  255. .confirm-account-removal-modal {
  256. .modal-card {
  257. width: 650px;
  258. }
  259. }
  260. </style>
  261. <style lang="less" scoped>
  262. h2 {
  263. margin: 0;
  264. }
  265. .content-box {
  266. margin-top: 20px;
  267. max-width: unset;
  268. }
  269. #steps {
  270. margin-top: 0;
  271. }
  272. #password-linked {
  273. #password-visibility-container {
  274. width: 100%;
  275. }
  276. > a {
  277. color: var(--primary-color);
  278. }
  279. }
  280. .control {
  281. margin-bottom: 0 !important;
  282. }
  283. #remove-account-container .content-box-inputs {
  284. width: fit-content;
  285. }
  286. </style>