StartComponent.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 v-if="!config.default_only && !config.custom_only">
  27. <p v-if="!config.default_only && !config.custom_only" 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. props: {
  45. config: {
  46. type: Object
  47. }
  48. },
  49. data() {
  50. return {
  51. loaded: false,
  52. domains: []
  53. }
  54. },
  55. mounted() {
  56. this.fetchDomains();
  57. },
  58. methods: {
  59. fetchDomains() {
  60. axios.post('/auth/raw/mastodon/domains')
  61. .then(res => {
  62. this.domains = res.data;
  63. })
  64. .finally(() => {
  65. setTimeout(() => {
  66. this.loaded = true;
  67. }, 500);
  68. })
  69. },
  70. handleRedirect(domain) {
  71. axios.post('/auth/raw/mastodon/redirect', { domain: domain })
  72. .then(res => {
  73. if(!res || !res.data.hasOwnProperty('ready')) {
  74. return;
  75. }
  76. if(res.data.hasOwnProperty('action') && res.data.action === 'incompatible_domain') {
  77. swal('Oops!', 'This server is not compatible, please choose another or try again later!', 'error');
  78. return;
  79. }
  80. if(res.data.hasOwnProperty('action') && res.data.action === 'blocked_domain') {
  81. swal('Server Blocked', 'This server is blocked by admins and cannot be used, please try another server!', 'error');
  82. return;
  83. }
  84. if(res.data.ready) {
  85. window.location.href = '/auth/raw/mastodon/preflight?d=' + domain + '&dsh=' + res.data.dsh;
  86. }
  87. })
  88. },
  89. handleOther() {
  90. swal({
  91. text: 'Enter your mastodon domain (without https://)',
  92. content: "input",
  93. button: {
  94. text: "Next",
  95. closeModal: false,
  96. },
  97. })
  98. .then(domain => {
  99. if (!domain || domain.length < 2 || domain.indexOf('.') == -1) {
  100. swal('Oops!', "Please enter a valid domain!", 'error');
  101. return;
  102. };
  103. if(domain.startsWith('http')) {
  104. swal('Oops!', "The domain you enter should not start with http(s://)\nUse the domain format, like mastodon.social", 'error');
  105. return;
  106. }
  107. return this.handleRedirect(domain);
  108. })
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. @use '../../../../node_modules/bootstrap/scss/bootstrap';
  115. .remote-auth-start {
  116. .server-btn {
  117. @extend .btn;
  118. @extend .btn-primary;
  119. @extend .btn-block;
  120. @extend .rounded-pill;
  121. @extend .font-weight-light;
  122. background: linear-gradient(#6364FF, #563ACC);
  123. }
  124. .other-server-btn {
  125. @extend .btn;
  126. @extend .btn-dark;
  127. @extend .btn-block;
  128. @extend .rounded-pill;
  129. @extend .font-weight-light;
  130. }
  131. }
  132. </style>