StartComponent.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="container remote-auth-start">
  3. <div class="row mt-5 justify-content-center">
  4. <div class="col-12 col-md-5">
  5. <div class="card shadow-none border" style="border-radius: 20px;">
  6. <div v-if="!loaded" class="card-body d-flex justify-content-center flex-column" style="min-height: 662px;">
  7. <p class="lead text-center font-weight-bold mb-0">Sign-in with Mastodon</p>
  8. <div class="w-100">
  9. <hr>
  10. </div>
  11. <div class="d-flex justify-content-center align-items-center flex-grow-1">
  12. <b-spinner />
  13. </div>
  14. </div>
  15. <div v-else class="card-body" style="min-height: 662px;">
  16. <p class="lead text-center font-weight-bold">Sign-in with Mastodon</p>
  17. <hr>
  18. <p class="small text-center mb-3">Select your Mastodon server:</p>
  19. <button
  20. v-for="domain in domains"
  21. type="button"
  22. class="server-btn"
  23. @click="handleRedirect(domain)">
  24. <span class="font-weight-bold">{{ domain }}</span>
  25. </button>
  26. <hr>
  27. <p class="text-center">
  28. <button type="button" class="other-server-btn" @click="handleOther()">Sign-in with a different server</button>
  29. </p>
  30. <div class="w-100">
  31. <hr>
  32. <p class="text-center mb-0">
  33. <a class="font-weight-bold" href="/login">Go back to login</a>
  34. </p>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script type="text/javascript">
  43. export default {
  44. data() {
  45. return {
  46. loaded: false,
  47. domains: []
  48. }
  49. },
  50. mounted() {
  51. this.fetchDomains();
  52. },
  53. methods: {
  54. fetchDomains() {
  55. axios.post('/auth/raw/mastodon/domains')
  56. .then(res => {
  57. this.domains = res.data;
  58. })
  59. .finally(() => {
  60. setTimeout(() => {
  61. this.loaded = true;
  62. }, 500);
  63. })
  64. },
  65. handleRedirect(domain) {
  66. axios.post('/auth/raw/mastodon/redirect', { domain: domain })
  67. .then(res => {
  68. if(!res || !res.data.hasOwnProperty('ready')) {
  69. return;
  70. }
  71. if(res.data.hasOwnProperty('action') && res.data.action === 'incompatible_domain') {
  72. swal('Oops!', 'This server is not compatible, please choose another or try again later!', 'error');
  73. return;
  74. }
  75. if(res.data.ready) {
  76. window.location.href = '/auth/raw/mastodon/preflight?d=' + domain + '&dsh=' + res.data.dsh;
  77. }
  78. })
  79. },
  80. handleOther() {
  81. swal({
  82. text: 'Enter your mastodon domain (without https://)',
  83. content: "input",
  84. button: {
  85. text: "Next",
  86. closeModal: false,
  87. },
  88. })
  89. .then(domain => {
  90. if (!domain) throw null;
  91. if(domain.startsWith('https://')) {
  92. return;
  93. }
  94. return this.handleRedirect(domain);
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. @use '../../../../node_modules/bootstrap/scss/bootstrap';
  102. .remote-auth-start {
  103. .server-btn {
  104. @extend .btn;
  105. @extend .btn-primary;
  106. @extend .btn-block;
  107. @extend .rounded-pill;
  108. @extend .font-weight-light;
  109. background: linear-gradient(#6364FF, #563ACC);
  110. }
  111. .other-server-btn {
  112. @extend .btn;
  113. @extend .btn-dark;
  114. @extend .btn-block;
  115. @extend .rounded-pill;
  116. @extend .font-weight-light;
  117. }
  118. }
  119. </style>