RemoveAccount.vue 7.5 KB

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