The Bubble web UI in VueJS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

104 lines
4.5 KiB

  1. <!-- Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ -->
  2. <template>
  3. <div>
  4. <h2>{{ messages.form_title_restore }}</h2>
  5. <div v-if="!configs"><img :src="loadingImgSrc" /></div>
  6. <div v-else-if="configs.restoreInProgress" class="alert alert-info">
  7. {{ messages.message_restore_not_applicable }}<hr/>
  8. <a href="/">{{ messages.message_back_to_root }}</a>
  9. </div>
  10. <div v-else>
  11. <form @submit.prevent="handleSubmit">
  12. <div class="form-group">
  13. <label htmlFor="restoreShortKey">{{messages.field_label_restore_short_key}}</label>
  14. <input type="text" v-model="restoreShortKey" name="restoreShortKey" class="form-control"
  15. :class="{ 'is-invalid': submitted && !restoreShortKey }" />
  16. <div v-show="submitted && !restoreShortKey" class="invalid-feedback">
  17. {{ messages.err_restoreShortKey_required }}
  18. </div>
  19. <div v-if="submitted && errors.has('restoreShortKey')" class="invalid-feedback d-block">
  20. {{ errors.first('restoreShortKey') }}
  21. </div>
  22. </div>
  23. <div class="form-group">
  24. <label htmlFor="restoreLongNetworkKeyFile">{{ messages.field_label_restore_long_key }}</label>
  25. <input type="file" ref="restoreLongNetworkKeyFile" @change="readUploadedKeyFile"
  26. class="form-control" :class="{ 'is-invalid': submitted && !restoreLongNetworkKey }" />
  27. <div v-show="submitted && !restoreLongNetworkKey" class="invalid-feedback">
  28. {{ messages.err_restoreLongNetworkKey_required }}
  29. </div>
  30. <div v-if="submitted && errors.has('restoreLongNetworkKey')" class="invalid-feedback d-block">
  31. {{ errors.first('restoreLongNetworkKey') }}
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label htmlFor="password">{{messages.field_label_password}}</label>
  36. <input type="password" v-model="password" name="password" class="form-control"
  37. :class="{ 'is-invalid': submitted && !password }" />
  38. <div v-show="submitted && !password" class="invalid-feedback">
  39. {{ messages.err_password_required }}
  40. </div>
  41. <div v-if="submitted && errors.has('password')" class="invalid-feedback d-block">
  42. {{ errors.first('password') }}
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <button class="btn btn-primary" :disabled="status.restoring">
  47. {{ messages.button_label_restore }}
  48. </button>
  49. <img v-show="status.restoring" :src="loadingImgSrc" />
  50. </div>
  51. </form>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapState, mapActions } from 'vuex';
  57. import { loadingImgSrc } from '~/_store';
  58. export default {
  59. data () {
  60. return {
  61. restoreShortKey: (this.$route.query && this.$route.query.k) ? this.$route.query.k : null,
  62. restoreLongNetworkKey: null,
  63. password: '',
  64. submitted: false,
  65. loadingImgSrc: loadingImgSrc
  66. }
  67. },
  68. created () {
  69. this.loadSystemConfigs();
  70. },
  71. computed: {
  72. ...mapState('account', [ 'status' ]),
  73. ...mapState('system', [ 'configs', 'messages' ])
  74. },
  75. methods: {
  76. ...mapActions('account', [ 'restore' ]),
  77. ...mapActions('system', [ 'loadSystemConfigs' ]),
  78. handleSubmit (e) {
  79. this.errors.clear();
  80. const { restoreShortKey, password } = this;
  81. this.submitted = true;
  82. this.restore({
  83. shortKey: restoreShortKey, longKey: this.restoreLongNetworkKey, password: password,
  84. systemConfigs: this.configs, messages: this.messages, errors: this.errors
  85. });
  86. },
  87. readUploadedKeyFile() {
  88. var uploadedFile = this.$refs.restoreLongNetworkKeyFile.files[0];
  89. var reader = new FileReader();
  90. reader.onload = (event) => this.restoreLongNetworkKey = event.target.result;
  91. reader.readAsText(uploadedFile);
  92. }
  93. }
  94. };
  95. </script>