login.vue 13 KB

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