RemoveAccount.vue 7.0 KB

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