RemoveAccount.vue 6.5 KB

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