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.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. *
  4. * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. import { loadState } from '@nextcloud/initial-state'
  22. import queryString from 'query-string'
  23. import Vue from 'vue'
  24. // eslint-disable-next-line no-unused-vars
  25. import OC from './OC/index' // TODO: Not needed but L10n breaks if removed
  26. import LoginView from './views/Login.vue'
  27. import Nextcloud from './mixins/Nextcloud'
  28. const query = queryString.parse(location.search)
  29. if (query.clear === '1') {
  30. try {
  31. window.localStorage.clear()
  32. window.sessionStorage.clear()
  33. console.debug('Browser storage cleared')
  34. } catch (e) {
  35. console.error('Could not clear browser storage', e)
  36. }
  37. }
  38. Vue.mixin(Nextcloud)
  39. const fromStateOr = (key, orValue) => {
  40. try {
  41. return loadState('core', key)
  42. } catch (e) {
  43. return orValue
  44. }
  45. }
  46. const View = Vue.extend(LoginView)
  47. new View({
  48. propsData: {
  49. errors: fromStateOr('loginErrors', []),
  50. messages: fromStateOr('loginMessages', []),
  51. redirectUrl: fromStateOr('loginRedirectUrl', undefined),
  52. username: fromStateOr('loginUsername', ''),
  53. throttleDelay: fromStateOr('loginThrottleDelay', 0),
  54. invertedColors: OCA.Theming && OCA.Theming.inverted,
  55. canResetPassword: fromStateOr('loginCanResetPassword', false),
  56. resetPasswordLink: fromStateOr('loginResetPasswordLink', ''),
  57. autoCompleteAllowed: fromStateOr('loginAutocomplete', true),
  58. resetPasswordTarget: fromStateOr('resetPasswordTarget', ''),
  59. resetPasswordUser: fromStateOr('resetPasswordUser', ''),
  60. directLogin: query.direct === '1',
  61. hasPasswordless: fromStateOr('webauthn-available', false),
  62. isHttps: window.location.protocol === 'https:',
  63. hasPublicKeyCredential: typeof (window.PublicKeyCredential) !== 'undefined',
  64. },
  65. }).$mount('#login')