RemoveAccount.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. import { storeToRefs } from "pinia";
  7. import { useSettingsStore } from "@/stores/settings";
  8. import { useWebsocketsStore } from "@/stores/websockets";
  9. import { useRemoveAccountStore } from "@/stores/removeAccount";
  10. const props = defineProps({
  11. modalUuid: { type: String, default: "" }
  12. });
  13. const settingsStore = useSettingsStore();
  14. const route = useRoute();
  15. const store = useStore();
  16. const { socket } = useWebsocketsStore();
  17. const removeAccountStore = useRemoveAccountStore(props);
  18. const { githubLinkConfirmed } = storeToRefs(removeAccountStore);
  19. const { isPasswordLinked, isGithubLinked } = settingsStore;
  20. const closeCurrentModal = () =>
  21. store.dispatch("modalVisibility/closeCurrentModal");
  22. const step = ref("confirm-identity");
  23. const apiDomain = ref("");
  24. const accountRemovalMessage = ref("");
  25. const password = ref({
  26. value: "",
  27. visible: false
  28. });
  29. const passwordElement = ref();
  30. const githubAuthentication = ref(false);
  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. lofig.get("cookie").then(cookie => {
  83. document.cookie = `${cookie.SIDname}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
  84. closeCurrentModal();
  85. window.location.href = "/";
  86. })
  87. );
  88. }
  89. return new Toast(res.message);
  90. });
  91. onMounted(async () => {
  92. apiDomain.value = await lofig.get("backend.apiDomain");
  93. accountRemovalMessage.value = await lofig.get("messages.accountRemoval");
  94. githubAuthentication.value = await lofig.get(
  95. "siteSettings.githubAuthentication"
  96. );
  97. if (githubLinkConfirmed.value === true) confirmGithubLink();
  98. });
  99. </script>
  100. <template>
  101. <modal
  102. title="Confirm Account Removal"
  103. class="confirm-account-removal-modal"
  104. >
  105. <template #body>
  106. <div id="steps">
  107. <p
  108. class="step"
  109. :class="{ selected: step === 'confirm-identity' }"
  110. >
  111. 1
  112. </p>
  113. <span class="divider"></span>
  114. <p
  115. class="step"
  116. :class="{
  117. selected:
  118. (isPasswordLinked && step === 'export-data') ||
  119. step === 'relink-github'
  120. }"
  121. >
  122. 2
  123. </p>
  124. <span class="divider"></span>
  125. <p
  126. class="step"
  127. :class="{
  128. selected:
  129. (isPasswordLinked && step === 'remove-account') ||
  130. step === 'export-data'
  131. }"
  132. >
  133. 3
  134. </p>
  135. <span class="divider" v-if="!isPasswordLinked"></span>
  136. <p
  137. class="step"
  138. :class="{ selected: step === 'remove-account' }"
  139. v-if="!isPasswordLinked"
  140. >
  141. 4
  142. </p>
  143. </div>
  144. <div
  145. class="content-box"
  146. id="password-linked"
  147. v-if="
  148. step === 'confirm-identity' &&
  149. (isPasswordLinked || !githubAuthentication)
  150. "
  151. >
  152. <h2 class="content-box-title">Enter your password</h2>
  153. <p class="content-box-description">
  154. Confirming your password will let us verify your identity.
  155. </p>
  156. <p class="content-box-optional-helper">
  157. <router-link id="forgot-password" to="/reset_password">
  158. Forgot password?
  159. </router-link>
  160. </p>
  161. <div class="content-box-inputs">
  162. <div class="control is-grouped input-with-button">
  163. <div id="password-visibility-container">
  164. <input
  165. class="input"
  166. type="password"
  167. placeholder="Enter password here..."
  168. autofocus
  169. ref="passwordElement"
  170. v-model="password.value"
  171. @input="
  172. checkForAutofill(
  173. confirmPasswordMatch,
  174. $event
  175. )
  176. "
  177. @keypress="
  178. submitOnEnter(confirmPasswordMatch, $event)
  179. "
  180. />
  181. <a @click="togglePasswordVisibility()">
  182. <i class="material-icons">
  183. {{
  184. !password.visible
  185. ? "visibility"
  186. : "visibility_off"
  187. }}
  188. </i>
  189. </a>
  190. </div>
  191. <p class="control">
  192. <button
  193. class="button is-info"
  194. @click="confirmPasswordMatch()"
  195. >
  196. Check
  197. </button>
  198. </p>
  199. </div>
  200. </div>
  201. </div>
  202. <div
  203. class="content-box"
  204. v-else-if="
  205. githubAuthentication &&
  206. isGithubLinked &&
  207. step === 'confirm-identity'
  208. "
  209. >
  210. <h2 class="content-box-title">Verify your GitHub</h2>
  211. <p class="content-box-description">
  212. Check your account is still linked to remove your account.
  213. </p>
  214. <div class="content-box-inputs">
  215. <a class="button is-github" @click="confirmGithubLink()">
  216. <div class="icon">
  217. <img
  218. class="invert"
  219. src="/assets/social/github.svg"
  220. />
  221. </div>
  222. &nbsp; Check GitHub is linked
  223. </a>
  224. </div>
  225. </div>
  226. <div
  227. class="content-box"
  228. v-if="githubAuthentication && step === 'relink-github'"
  229. >
  230. <h2 class="content-box-title">Re-link GitHub</h2>
  231. <p class="content-box-description">
  232. Re-link your GitHub account in order to verify your
  233. identity.
  234. </p>
  235. <div class="content-box-inputs">
  236. <a
  237. class="button is-github"
  238. @click="relinkGithub()"
  239. :href="`${apiDomain}/auth/github/link`"
  240. >
  241. <div class="icon">
  242. <img
  243. class="invert"
  244. src="/assets/social/github.svg"
  245. />
  246. </div>
  247. &nbsp; Re-link GitHub to account
  248. </a>
  249. </div>
  250. </div>
  251. <div v-if="step === 'export-data'">
  252. DOWNLOAD A BACKUP OF YOUR DATA BEFORE ITS PERMENATNELY DELETED
  253. </div>
  254. <div
  255. class="content-box"
  256. id="remove-account-container"
  257. v-if="step === 'remove-account'"
  258. >
  259. <h2 class="content-box-title">Remove your account</h2>
  260. <p class="content-box-description">
  261. {{ accountRemovalMessage }}
  262. </p>
  263. <div class="content-box-inputs">
  264. <quick-confirm placement="right" @confirm="remove()">
  265. <button class="button">
  266. <i class="material-icons">delete</i>
  267. &nbsp;Remove Account
  268. </button>
  269. </quick-confirm>
  270. </div>
  271. </div>
  272. </template>
  273. </modal>
  274. </template>
  275. <style lang="less">
  276. .confirm-account-removal-modal {
  277. .modal-card {
  278. width: 650px;
  279. }
  280. }
  281. </style>
  282. <style lang="less" scoped>
  283. h2 {
  284. margin: 0;
  285. }
  286. .content-box {
  287. margin-top: 20px;
  288. max-width: unset;
  289. }
  290. #steps {
  291. margin-top: 0;
  292. }
  293. #password-linked {
  294. #password-visibility-container {
  295. width: 100%;
  296. }
  297. > a {
  298. color: var(--primary-color);
  299. }
  300. }
  301. .control {
  302. margin-bottom: 0 !important;
  303. }
  304. #remove-account-container .content-box-inputs {
  305. width: fit-content;
  306. }
  307. </style>