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.

486 lines
13 KiB

  1. <template lang="pug">
  2. v-app
  3. .login(:class='{ "is-error": error }')
  4. .login-container(:class='{ "is-expanded": strategies.length > 1, "is-loading": isLoading }')
  5. .login-providers(v-show='strategies.length > 1')
  6. button(v-for='strategy in strategies', :class='{ "is-active": strategy.key === selectedStrategy }', @click='selectStrategy(strategy.key, strategy.useForm)', :title='strategy.title')
  7. em(v-html='strategy.icon')
  8. span {{ strategy.title }}
  9. .login-providers-fill
  10. .login-frame(v-show='screen === "login"')
  11. h1.text-xs-center.display-1 {{ siteTitle }}
  12. h2.text-xs-center.subheading {{ $t('auth:loginRequired') }}
  13. v-text-field(solo, ref='iptEmail', v-model='username', :placeholder='$t("auth:fields.emailUser")')
  14. v-text-field.mt-2(
  15. solo,
  16. ref='iptPassword',
  17. v-model='password',
  18. :append-icon='hidePassword ? "visibility" : "visibility_off"',
  19. :append-icon-cb='() => (hidePassword = !hidePassword)',
  20. :type='hidePassword ? "password" : "text"',
  21. :placeholder='$t("auth:fields.password")',
  22. @keyup.enter='login'
  23. )
  24. v-btn.mt-3(block, large, color='primary', @click='login') {{ $t('auth:actions.login') }}
  25. .login-frame(v-show='screen === "tfa"')
  26. .login-frame-icon
  27. svg.icons.is-48(role='img')
  28. title {{ $t('auth:tfa.title') }}
  29. use(xlink:href='#nc-key')
  30. h2 {{ $t('auth:tfa.subtitle') }}
  31. input(type='text', ref='iptTFA', v-model='securityCode', :placeholder='$t("auth:tfa.placeholder")', @keyup.enter='verifySecurityCode')
  32. button.button.is-blue.is-fullwidth(@click='verifySecurityCode')
  33. span {{ $t('auth:tfa.verifyToken') }}
  34. .login-copyright
  35. span {{ $t('footer.poweredBy') }}
  36. a(href='https://wiki.js.org', rel='external', title='Wiki.js') Wiki.js
  37. </template>
  38. <script>
  39. /* global CONSTANTS, graphQL, siteConfig */
  40. import _ from 'lodash'
  41. export default {
  42. data () {
  43. return {
  44. error: false,
  45. strategies: [],
  46. selectedStrategy: 'local',
  47. screen: 'login',
  48. username: '',
  49. password: '',
  50. hidePassword: true,
  51. securityCode: '',
  52. loginToken: '',
  53. isLoading: false
  54. }
  55. },
  56. computed: {
  57. siteTitle () {
  58. return siteConfig.title
  59. }
  60. },
  61. mounted () {
  62. this.$store.commit('navigator/subtitleStatic', 'Login')
  63. this.refreshStrategies()
  64. this.$refs.iptEmail.focus()
  65. },
  66. methods: {
  67. selectStrategy (key, useForm) {
  68. this.selectedStrategy = key
  69. this.screen = 'login'
  70. if (!useForm) {
  71. this.isLoading = true
  72. window.location.assign(this.$helpers.resolvePath('login/' + key))
  73. } else {
  74. this.$refs.iptEmail.focus()
  75. }
  76. },
  77. refreshStrategies () {
  78. this.isLoading = true
  79. graphQL.query({
  80. query: CONSTANTS.GRAPH.AUTHENTICATION.QUERY_LOGIN_PROVIDERS
  81. }).then(resp => {
  82. if (_.has(resp, 'data.authentication.providers')) {
  83. this.strategies = _.get(resp, 'data.authentication.providers', [])
  84. } else {
  85. throw new Error('No authentication providers available!')
  86. }
  87. this.isLoading = false
  88. }).catch(err => {
  89. console.error(err)
  90. this.$store.dispatch('alert', {
  91. style: 'error',
  92. icon: 'gg-warning',
  93. msg: err.message
  94. })
  95. this.isLoading = false
  96. })
  97. },
  98. login () {
  99. if (this.username.length < 2) {
  100. this.$store.dispatch('alert', {
  101. style: 'error',
  102. icon: 'gg-warning',
  103. msg: 'Enter a valid email / username.'
  104. })
  105. this.$refs.iptEmail.focus()
  106. } else if (this.password.length < 2) {
  107. this.$store.dispatch('alert', {
  108. style: 'error',
  109. icon: 'gg-warning',
  110. msg: 'Enter a valid password.'
  111. })
  112. this.$refs.iptPassword.focus()
  113. } else {
  114. this.isLoading = true
  115. graphQL.mutate({
  116. mutation: CONSTANTS.GRAPH.AUTHENTICATION.MUTATION_LOGIN,
  117. variables: {
  118. username: this.username,
  119. password: this.password,
  120. provider: this.selectedStrategy
  121. }
  122. }).then(resp => {
  123. if (_.has(resp, 'data.authentication.login')) {
  124. let respObj = _.get(resp, 'data.authentication.login', {})
  125. if (respObj.operation.succeeded === true) {
  126. if (respObj.tfaRequired === true) {
  127. this.screen = 'tfa'
  128. this.securityCode = ''
  129. this.loginToken = respObj.tfaLoginToken
  130. this.$nextTick(() => {
  131. this.$refs.iptTFA.focus()
  132. })
  133. } else {
  134. this.$store.dispatch('alert', {
  135. style: 'success',
  136. icon: 'gg-check',
  137. msg: 'Login successful!'
  138. })
  139. }
  140. this.isLoading = false
  141. } else {
  142. throw new Error(respObj.operation.message)
  143. }
  144. } else {
  145. throw new Error('Authentication is unavailable.')
  146. }
  147. }).catch(err => {
  148. console.error(err)
  149. this.$store.dispatch('alert', {
  150. style: 'error',
  151. icon: 'gg-warning',
  152. msg: err.message
  153. })
  154. this.isLoading = false
  155. })
  156. }
  157. },
  158. verifySecurityCode () {
  159. if (this.securityCode.length !== 6) {
  160. this.$store.dispatch('alert', {
  161. style: 'error',
  162. icon: 'gg-warning',
  163. msg: 'Enter a valid security code.'
  164. })
  165. this.$refs.iptTFA.focus()
  166. } else {
  167. this.isLoading = true
  168. graphQL.mutate({
  169. mutation: CONSTANTS.GRAPH.AUTHENTICATION.MUTATION_LOGINTFA,
  170. variables: {
  171. loginToken: this.loginToken,
  172. securityCode: this.securityCode
  173. }
  174. }).then(resp => {
  175. if (_.has(resp, 'data.authentication.loginTFA')) {
  176. let respObj = _.get(resp, 'data.authentication.loginTFA', {})
  177. if (respObj.operation.succeeded === true) {
  178. this.$store.dispatch('alert', {
  179. style: 'success',
  180. icon: 'gg-check',
  181. msg: 'Login successful!'
  182. })
  183. this.isLoading = false
  184. } else {
  185. throw new Error(respObj.operation.message)
  186. }
  187. } else {
  188. throw new Error('Authentication is unavailable.')
  189. }
  190. }).catch(err => {
  191. console.error(err)
  192. this.$store.dispatch('alert', {
  193. style: 'error',
  194. icon: 'gg-warning',
  195. msg: err.message
  196. })
  197. this.isLoading = false
  198. })
  199. }
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss">
  205. .login {
  206. background-color: mc('blue', '800');
  207. background-image: url('../static/svg/login-bg-motif.svg');
  208. background-repeat: repeat;
  209. background-size: 200px;
  210. width: 100%;
  211. height: 100%;
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. animation: loginBgReveal 20s linear infinite;
  216. @include keyframes(loginBgReveal) {
  217. 0% {
  218. background-position-y: 0;
  219. }
  220. 100% {
  221. background-position-y: -800px;
  222. }
  223. }
  224. &::before {
  225. content: '';
  226. position: absolute;
  227. background-image: url('../static/svg/login-bg.svg');
  228. background-position: center bottom;
  229. background-size: cover;
  230. top: 0;
  231. left: 0;
  232. width: 100vw;
  233. height: 100vh;
  234. @include until($tablet) {
  235. display: none;
  236. }
  237. }
  238. &::after {
  239. content: '';
  240. position: absolute;
  241. background-image: linear-gradient(to bottom, rgba(mc('blue', '800'), 1) 0%, rgba(mc('blue', '800'), 0) 100%);
  242. top: 0;
  243. left: 0;
  244. width: 100vw;
  245. height: 25vh;
  246. }
  247. &-container {
  248. position: relative;
  249. display: flex;
  250. width: 400px;
  251. align-items: stretch;
  252. box-shadow: 0 14px 28px rgba(0,0,0,0.2);
  253. border-radius: 6px;
  254. animation: zoomIn .5s ease;
  255. &::after {
  256. position: absolute;
  257. top: 1rem;
  258. right: 1rem;
  259. content: " ";
  260. @include spinner(mc('blue', '500'),0.5s,16px);
  261. display: none;
  262. }
  263. &.is-expanded {
  264. width: 650px;
  265. .login-frame {
  266. border-radius: 0 6px 6px 0;
  267. border-left: none;
  268. @include until($tablet) {
  269. border-radius: 0;
  270. }
  271. }
  272. }
  273. &.is-loading::after {
  274. display: block;
  275. }
  276. @include until($tablet) {
  277. width: 100%;
  278. border-radius: 0;
  279. &.is-expanded {
  280. width: 100%;
  281. }
  282. }
  283. }
  284. &-providers {
  285. display: flex;
  286. flex-direction: column;
  287. width: 250px;
  288. border-right: none;
  289. border-radius: 6px 0 0 6px;
  290. z-index: 1;
  291. overflow: hidden;
  292. @include until($tablet) {
  293. width: 50px;
  294. border-radius: 0;
  295. }
  296. button {
  297. flex: 0 1 50px;
  298. padding: 5px 15px;
  299. border: none;
  300. color: #FFF;
  301. // background: linear-gradient(to right, rgba(mc('light-blue', '800'), .7), rgba(mc('light-blue', '800'), 1));
  302. // border-top: 1px solid rgba(mc('light-blue', '900'), .5);
  303. background: linear-gradient(to right, rgba(0,0,0, .5), rgba(0,0,0, .7));
  304. border-top: 1px solid rgba(0,0,0, .2);
  305. font-family: $core-font-standard;
  306. font-weight: 600;
  307. text-align: left;
  308. min-height: 40px;
  309. display: flex;
  310. justify-content: flex-start;
  311. align-items: center;
  312. transition: all .4s ease;
  313. &:focus {
  314. outline: none;
  315. }
  316. @include until($tablet) {
  317. justify-content: center;
  318. }
  319. &:hover {
  320. background-color: rgba(0,0,0, .4);
  321. }
  322. &:first-child {
  323. border-top: none;
  324. &.is-active {
  325. border-top: 1px solid rgba(255,255,255, .5);
  326. }
  327. }
  328. &.is-active {
  329. background-image: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,.77) 100%);
  330. color: mc('grey', '800');
  331. cursor: default;
  332. &:hover {
  333. background-color: transparent;
  334. }
  335. svg path {
  336. fill: mc('grey', '800');
  337. }
  338. }
  339. i {
  340. margin-right: 10px;
  341. font-size: 16px;
  342. @include until($tablet) {
  343. margin-right: 0;
  344. font-size: 20px;
  345. }
  346. }
  347. svg {
  348. margin-right: 10px;
  349. width: auto;
  350. height: 20px;
  351. max-width: 18px;
  352. max-height: 20px;
  353. path {
  354. fill: #FFF;
  355. }
  356. @include until($tablet) {
  357. margin-right: 0;
  358. font-size: 20px;
  359. }
  360. }
  361. em {
  362. height: 20px;
  363. }
  364. span {
  365. font-weight: 600;
  366. @include until($tablet) {
  367. display: none;
  368. }
  369. }
  370. }
  371. &-fill {
  372. flex: 1 1 0;
  373. background: linear-gradient(to right, rgba(mc('light-blue', '800'), .7), rgba(mc('light-blue', '800'), 1));
  374. }
  375. }
  376. &-frame {
  377. background-image: radial-gradient(circle at top center, rgba(255,255,255,1) 5%,rgba(255,255,255,.6) 100%);
  378. border: 1px solid rgba(255,255,255, .5);
  379. border-radius: 6px;
  380. width: 400px;
  381. padding: 1rem;
  382. color: mc('grey', '700');
  383. display: block;
  384. @include until($tablet) {
  385. width: 100%;
  386. border-radius: 0;
  387. border: none;
  388. }
  389. h1 {
  390. font-size: 2rem;
  391. font-weight: 400;
  392. color: mc('light-blue', '700');
  393. text-shadow: 1px 1px 0 #FFF;
  394. padding: 0;
  395. margin: 0;
  396. }
  397. h2 {
  398. font-size: 1.5rem;
  399. font-weight: 300;
  400. color: mc('grey', '700');
  401. text-shadow: 1px 1px 0 #FFF;
  402. padding: 0;
  403. margin: 0 0 25px 0;
  404. }
  405. }
  406. &-tfa {
  407. position: relative;
  408. display: flex;
  409. width: 400px;
  410. align-items: stretch;
  411. box-shadow: 0 14px 28px rgba(0,0,0,0.2);
  412. border-radius: 6px;
  413. animation: zoomIn .5s ease;
  414. }
  415. &-copyright {
  416. display: flex;
  417. align-items: center;
  418. justify-content: center;
  419. position: absolute;
  420. left: 0;
  421. bottom: 10vh;
  422. width: 100%;
  423. z-index: 2;
  424. color: mc('grey', '500');
  425. font-weight: 400;
  426. a {
  427. font-weight: 600;
  428. color: mc('blue', '500');
  429. margin-left: .25rem;
  430. @include until($tablet) {
  431. color: mc('blue', '200');
  432. }
  433. }
  434. @include until($tablet) {
  435. color: mc('blue', '50');
  436. }
  437. }
  438. }
  439. </style>