StartComponent.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. Sign-in with <span class="font-weight-bold">{{ domain }}</span>
  25. </button>
  26. <hr>
  27. <p class="text-center">
  28. <button type="button" class="other-server-btn">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. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. @use '../../../../node_modules/bootstrap/scss/bootstrap';
  85. .remote-auth-start {
  86. .server-btn {
  87. @extend .btn;
  88. @extend .btn-primary;
  89. @extend .btn-block;
  90. @extend .rounded-pill;
  91. @extend .font-weight-light;
  92. background: linear-gradient(#6364FF, #563ACC);
  93. }
  94. .other-server-btn {
  95. @extend .btn;
  96. @extend .btn-dark;
  97. @extend .btn-block;
  98. @extend .rounded-pill;
  99. @extend .font-weight-light;
  100. }
  101. }
  102. </style>