login.vue 13 KB

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