RemoveAccount.vue 6.6 KB

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