Register.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="modal is-active">
  3. <div class="modal-background" />
  4. <div class="modal-card">
  5. <header class="modal-card-head">
  6. <p class="modal-card-title">
  7. Register
  8. </p>
  9. <button class="delete" @click="closeCurrentModal()" />
  10. </header>
  11. <section class="modal-card-body">
  12. <!-- validation to check if exists http://bulma.io/documentation/elements/form/ -->
  13. <label class="label">Email</label>
  14. <p class="control">
  15. <input
  16. v-model="email"
  17. class="input"
  18. type="text"
  19. placeholder="Email..."
  20. autofocus
  21. />
  22. </p>
  23. <label class="label">Username</label>
  24. <p class="control">
  25. <input
  26. v-model="username"
  27. class="input"
  28. type="text"
  29. placeholder="Username..."
  30. />
  31. </p>
  32. <label class="label">Password</label>
  33. <p class="control">
  34. <input
  35. v-model="password"
  36. class="input"
  37. type="password"
  38. placeholder="Password..."
  39. @keypress="$parent.submitOnEnter(submitModal, $event)"
  40. />
  41. </p>
  42. <p>
  43. By logging in/registering you agree to our
  44. <router-link to="/terms"> Terms of Service </router-link
  45. >&nbsp;and
  46. <router-link to="/privacy"> Privacy Policy </router-link>.
  47. </p>
  48. </section>
  49. <footer class="modal-card-foot">
  50. <a class="button is-primary" href="#" @click="submitModal()"
  51. >Submit</a
  52. >
  53. <a
  54. class="button is-github"
  55. :href="$parent.serverDomain + '/auth/github/authorize'"
  56. @click="githubRedirect()"
  57. >
  58. <div class="icon">
  59. <img class="invert" src="/assets/social/github.svg" />
  60. </div>
  61. &nbsp;&nbsp;Register with GitHub
  62. </a>
  63. </footer>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import { mapActions } from "vuex";
  69. import { Toast } from "vue-roaster";
  70. export default {
  71. data() {
  72. return {
  73. username: "",
  74. email: "",
  75. password: "",
  76. recaptcha: {
  77. key: "",
  78. token: ""
  79. }
  80. };
  81. },
  82. mounted: function() {
  83. let _this = this;
  84. lofig.get("recaptcha", obj => {
  85. _this.recaptcha.key = obj.key;
  86. let recaptchaScript = document.createElement("script");
  87. recaptchaScript.onload = () => {
  88. grecaptcha.ready(() => {
  89. grecaptcha
  90. .execute(this.recaptcha.key, { action: "login" })
  91. .then(function(token) {
  92. _this.recaptcha.token = token;
  93. });
  94. });
  95. };
  96. recaptchaScript.setAttribute(
  97. "src",
  98. `https://www.google.com/recaptcha/api.js?render=${
  99. this.recaptcha.key
  100. }`
  101. );
  102. document.head.appendChild(recaptchaScript);
  103. });
  104. },
  105. methods: {
  106. submitModal: function() {
  107. console.log(this.recaptcha.token);
  108. this.register({
  109. username: this.username,
  110. email: this.email,
  111. password: this.password,
  112. recaptchaToken: this.recaptcha.token
  113. })
  114. .then(res => {
  115. if (res.status == "success") location.reload();
  116. })
  117. .catch(err => Toast.methods.addToast(err.message, 5000));
  118. },
  119. githubRedirect: function() {
  120. localStorage.setItem("github_redirect", this.$route.path);
  121. },
  122. ...mapActions("modals", ["toggleModal", "closeCurrentModal"]),
  123. ...mapActions("user/auth", ["register"])
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .button.is-github {
  129. background-color: #333;
  130. color: #fff !important;
  131. }
  132. .is-github:focus {
  133. background-color: #1a1a1a;
  134. }
  135. .is-primary:focus {
  136. background-color: #028bca !important;
  137. }
  138. .invert {
  139. filter: brightness(5);
  140. }
  141. #recaptcha {
  142. padding: 10px 0;
  143. }
  144. a {
  145. color: #029ce3;
  146. }
  147. </style>