RemoveAccount.vue 8.2 KB

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