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.

Login.vue 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!--
  2. - @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. -
  4. - @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. - @author Richard Steinmetz <richard@steinmetz.cloud>
  6. -
  7. - @license GNU AGPL version 3 or any later version
  8. -
  9. - This program is free software: you can redistribute it and/or modify
  10. - it under the terms of the GNU Affero General Public License as
  11. - published by the Free Software Foundation, either version 3 of the
  12. - License, or (at your option) any later version.
  13. -
  14. - This program is distributed in the hope that it will be useful,
  15. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. - GNU Affero General Public License for more details.
  18. -
  19. - You should have received a copy of the GNU Affero General Public License
  20. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. -->
  22. <template>
  23. <div class="guest-box login-box">
  24. <template v-if="!hideLoginForm || directLogin">
  25. <transition name="fade" mode="out-in">
  26. <div v-if="!passwordlessLogin && !resetPassword && resetPasswordTarget === ''">
  27. <LoginForm :username.sync="user"
  28. :redirect-url="redirectUrl"
  29. :direct-login="directLogin"
  30. :messages="messages"
  31. :errors="errors"
  32. :throttle-delay="throttleDelay"
  33. :auto-complete-allowed="autoCompleteAllowed"
  34. :email-states="emailStates"
  35. @submit="loading = true" />
  36. <a v-if="canResetPassword && resetPasswordLink !== ''"
  37. id="lost-password"
  38. class="login-box__link"
  39. :href="resetPasswordLink">
  40. {{ t('core', 'Forgot password?') }}
  41. </a>
  42. <a v-else-if="canResetPassword && !resetPassword"
  43. id="lost-password"
  44. class="login-box__link"
  45. :href="resetPasswordLink"
  46. @click.prevent="resetPassword = true">
  47. {{ t('core', 'Forgot password?') }}
  48. </a>
  49. <template v-if="hasPasswordless">
  50. <div v-if="countAlternativeLogins"
  51. class="alternative-logins">
  52. <a v-if="hasPasswordless"
  53. class="button"
  54. :class="{ 'single-alt-login-option': countAlternativeLogins }"
  55. href="#"
  56. @click.prevent="passwordlessLogin = true">
  57. {{ t('core', 'Log in with a device') }}
  58. </a>
  59. </div>
  60. <a v-else
  61. href="#"
  62. @click.prevent="passwordlessLogin = true">
  63. {{ t('core', 'Log in with a device') }}
  64. </a>
  65. </template>
  66. </div>
  67. <div v-else-if="!loading && passwordlessLogin"
  68. key="reset-pw-less"
  69. class="login-additional login-passwordless">
  70. <PasswordLessLoginForm :username.sync="user"
  71. :redirect-url="redirectUrl"
  72. :auto-complete-allowed="autoCompleteAllowed"
  73. :is-https="isHttps"
  74. :is-localhost="isLocalhost"
  75. @submit="loading = true" />
  76. <NcButton type="tertiary"
  77. :aria-label="t('core', 'Back to login form')"
  78. :wide="true"
  79. @click="passwordlessLogin = false">
  80. {{ t('core', 'Back') }}
  81. </NcButton>
  82. </div>
  83. <div v-else-if="!loading && canResetPassword"
  84. key="reset-can-reset"
  85. class="login-additional">
  86. <div class="lost-password-container">
  87. <ResetPassword v-if="resetPassword"
  88. :username.sync="user"
  89. :reset-password-link="resetPasswordLink"
  90. @abort="resetPassword = false" />
  91. </div>
  92. </div>
  93. <div v-else-if="resetPasswordTarget !== ''">
  94. <UpdatePassword :username.sync="user"
  95. :reset-password-target="resetPasswordTarget"
  96. @done="passwordResetFinished" />
  97. </div>
  98. </transition>
  99. </template>
  100. <template v-else>
  101. <transition name="fade" mode="out-in">
  102. <NcNoteCard type="info" :title="t('core', 'Login form is disabled.')">
  103. {{ t('core', 'The Nextcloud login form is disabled. Use another login option if available or contact your administration.') }}
  104. </NcNoteCard>
  105. </transition>
  106. </template>
  107. <div id="alternative-logins" class="alternative-logins">
  108. <NcButton v-for="(alternativeLogin, index) in alternativeLogins"
  109. :key="index"
  110. type="secondary"
  111. :wide="true"
  112. :class="[alternativeLogin.class]"
  113. role="link"
  114. :href="alternativeLogin.href">
  115. {{ alternativeLogin.name }}
  116. </NcButton>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import { loadState } from '@nextcloud/initial-state'
  122. import queryString from 'query-string'
  123. import LoginForm from '../components/login/LoginForm.vue'
  124. import PasswordLessLoginForm from '../components/login/PasswordLessLoginForm.vue'
  125. import ResetPassword from '../components/login/ResetPassword.vue'
  126. import UpdatePassword from '../components/login/UpdatePassword.vue'
  127. import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
  128. import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
  129. const query = queryString.parse(location.search)
  130. if (query.clear === '1') {
  131. try {
  132. window.localStorage.clear()
  133. window.sessionStorage.clear()
  134. console.debug('Browser storage cleared')
  135. } catch (e) {
  136. console.error('Could not clear browser storage', e)
  137. }
  138. }
  139. export default {
  140. name: 'Login',
  141. components: {
  142. LoginForm,
  143. PasswordLessLoginForm,
  144. ResetPassword,
  145. UpdatePassword,
  146. NcButton,
  147. NcNoteCard,
  148. },
  149. data() {
  150. return {
  151. loading: false,
  152. user: loadState('core', 'loginUsername', ''),
  153. passwordlessLogin: false,
  154. resetPassword: false,
  155. // Initial data
  156. errors: loadState('core', 'loginErrors', []),
  157. messages: loadState('core', 'loginMessages', []),
  158. redirectUrl: loadState('core', 'loginRedirectUrl', false),
  159. throttleDelay: loadState('core', 'loginThrottleDelay', 0),
  160. canResetPassword: loadState('core', 'loginCanResetPassword', false),
  161. resetPasswordLink: loadState('core', 'loginResetPasswordLink', ''),
  162. autoCompleteAllowed: loadState('core', 'loginAutocomplete', true),
  163. resetPasswordTarget: loadState('core', 'resetPasswordTarget', ''),
  164. resetPasswordUser: loadState('core', 'resetPasswordUser', ''),
  165. directLogin: query.direct === '1',
  166. hasPasswordless: loadState('core', 'webauthn-available', false),
  167. countAlternativeLogins: loadState('core', 'countAlternativeLogins', false),
  168. alternativeLogins: loadState('core', 'alternativeLogins', []),
  169. isHttps: window.location.protocol === 'https:',
  170. isLocalhost: window.location.hostname === 'localhost',
  171. hideLoginForm: loadState('core', 'hideLoginForm', false),
  172. emailStates: loadState('core', 'emailStates', []),
  173. }
  174. },
  175. methods: {
  176. passwordResetFinished() {
  177. this.resetPasswordTarget = ''
  178. this.directLogin = true
  179. },
  180. },
  181. }
  182. </script>
  183. <style lang="scss">
  184. body {
  185. font-size: var(--default-font-size);
  186. }
  187. .login-box {
  188. // Same size as dashboard panels
  189. width: 320px;
  190. box-sizing: border-box;
  191. &__link {
  192. display: block;
  193. padding: 1rem;
  194. font-size: var(--default-font-size);
  195. text-align: center;
  196. font-weight: normal !important;
  197. }
  198. }
  199. .fade-enter-active, .fade-leave-active {
  200. transition: opacity .3s;
  201. }
  202. .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  203. opacity: 0;
  204. }
  205. .alternative-logins {
  206. display: flex;
  207. flex-direction: column;
  208. gap: 0.75rem;
  209. .button-vue {
  210. box-sizing: border-box;
  211. }
  212. }
  213. .login-passwordless {
  214. .button-vue {
  215. margin-top: 0.5rem;
  216. }
  217. }
  218. </style>