RemoveAccount.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 GitHub account is still linked in order to remove
  104. your account.
  105. </p>
  106. <div class="content-box-inputs">
  107. <a class="button is-github" @click="confirmGithubLink()">
  108. <div class="icon">
  109. <img
  110. class="invert"
  111. src="/assets/social/github.svg"
  112. />
  113. </div>
  114. &nbsp; Check GitHub is linked
  115. </a>
  116. </div>
  117. </div>
  118. <div class="content-box" v-if="step === 'relink-github'">
  119. <h2 class="content-box-title">Re-link GitHub</h2>
  120. <p class="content-box-description">
  121. Re-link your GitHub account in order to verify your
  122. identity.
  123. </p>
  124. <div class="content-box-inputs">
  125. <a
  126. class="button is-github"
  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. There is no going back after confirming account removal.
  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. step: "confirm-identity",
  173. apiDomain: "",
  174. password: {
  175. value: "",
  176. visible: false
  177. }
  178. };
  179. },
  180. computed: mapGetters({
  181. isPasswordLinked: "settings/isPasswordLinked",
  182. isGithubLinked: "settings/isGithubLinked",
  183. socket: "websockets/getSocket"
  184. }),
  185. async mounted() {
  186. this.apiDomain = await lofig.get("apiDomain");
  187. },
  188. methods: {
  189. togglePasswordVisibility() {
  190. if (this.$refs.password.type === "password") {
  191. this.$refs.password.type = "text";
  192. this.password.visible = true;
  193. } else {
  194. this.$refs.password.type = "password";
  195. this.password.visible = false;
  196. }
  197. },
  198. confirmPasswordMatch() {
  199. return this.socket.dispatch(
  200. "users.confirmPasswordMatch",
  201. this.password.value,
  202. res => {
  203. if (res.status === "success") this.step = "remove-account";
  204. else new Toast(res.message);
  205. }
  206. );
  207. },
  208. confirmGithubLink() {
  209. return this.socket.dispatch("users.confirmGithubLink", res => {
  210. if (res.status === "success") {
  211. if (res.data.linked) this.step = "remove-account";
  212. else {
  213. new Toast(
  214. `Your GitHub account isn't linked. Please re-link your account and try again.`
  215. );
  216. this.step = "relink-github";
  217. localStorage.setItem(
  218. "github_redirect",
  219. window.location.pathname + window.location.search
  220. );
  221. }
  222. } else new Toast(res.message);
  223. });
  224. },
  225. remove() {
  226. return this.socket.dispatch("users.remove", res => {
  227. if (res.status === "success") {
  228. return this.socket.dispatch("users.logout", () => {
  229. return lofig.get("cookie").then(cookie => {
  230. document.cookie = `${cookie.SIDname}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
  231. this.closeModal("removeAccount");
  232. return window.location.reload();
  233. });
  234. });
  235. }
  236. return new Toast(res.message);
  237. });
  238. },
  239. ...mapActions("modalVisibility", ["closeModal", "openModal"])
  240. }
  241. };
  242. </script>
  243. <style lang="scss">
  244. .confirm-account-removal-modal {
  245. .modal-card {
  246. width: 650px;
  247. }
  248. }
  249. </style>
  250. <style lang="scss" scoped>
  251. h2 {
  252. margin: 0;
  253. }
  254. .content-box {
  255. margin-top: 20px;
  256. max-width: unset;
  257. }
  258. #steps {
  259. margin-top: 0;
  260. }
  261. #password-linked {
  262. #password-visibility-container {
  263. width: 100%;
  264. }
  265. > a {
  266. color: var(--primary-color);
  267. }
  268. }
  269. .control {
  270. margin-bottom: 0 !important;
  271. }
  272. #remove-account-container .content-box-inputs {
  273. width: fit-content;
  274. }
  275. </style>