login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. name: 'login',
  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. methods: {
  52. selectStrategy (key, useForm) {
  53. this.selectedStrategy = key
  54. this.screen = 'login'
  55. if (!useForm) {
  56. this.isLoading = true
  57. window.location.assign(this.$helpers.resolvePath('login/' + key))
  58. } else {
  59. this.$refs.iptEmail.focus()
  60. }
  61. },
  62. refreshStrategies () {
  63. this.isLoading = true
  64. graphQL.query({
  65. query: CONSTANTS.GRAPHQL.GQL_QUERY_AUTHENTICATION,
  66. variables: {
  67. mode: 'active'
  68. }
  69. }).then(resp => {
  70. if (resp.data.authentication) {
  71. this.strategies = resp.data.authentication
  72. } else {
  73. throw new Error('No authentication providers available!')
  74. }
  75. this.isLoading = false
  76. }).catch(err => {
  77. console.error(err)
  78. this.$store.dispatch('alert', {
  79. style: 'error',
  80. icon: 'gg-warning',
  81. msg: err.message
  82. })
  83. this.isLoading = false
  84. })
  85. },
  86. login () {
  87. if (this.username.length < 2) {
  88. this.$store.dispatch('alert', {
  89. style: 'error',
  90. icon: 'gg-warning',
  91. msg: 'Enter a valid email / username.'
  92. })
  93. this.$refs.iptEmail.focus()
  94. } else if (this.password.length < 2) {
  95. this.$store.dispatch('alert', {
  96. style: 'error',
  97. icon: 'gg-warning',
  98. msg: 'Enter a valid password.'
  99. })
  100. this.$refs.iptPassword.focus()
  101. } else {
  102. this.isLoading = true
  103. graphQL.mutate({
  104. mutation: CONSTANTS.GRAPHQL.GQL_MUTATION_LOGIN,
  105. variables: {
  106. username: this.username,
  107. password: this.password,
  108. provider: this.selectedStrategy
  109. }
  110. }).then(resp => {
  111. if (resp.data.login) {
  112. let respObj = resp.data.login
  113. if (respObj.succeeded === true) {
  114. if (respObj.tfaRequired === true) {
  115. this.screen = 'tfa'
  116. this.securityCode = ''
  117. this.loginToken = respObj.tfaLoginToken
  118. this.$nextTick(() => {
  119. this.$refs.iptTFA.focus()
  120. })
  121. } else {
  122. this.$store.dispatch('alert', {
  123. style: 'success',
  124. icon: 'gg-check',
  125. msg: 'Login successful!'
  126. })
  127. }
  128. this.isLoading = false
  129. } else {
  130. throw new Error(respObj.message)
  131. }
  132. } else {
  133. throw new Error('Authentication is unavailable.')
  134. }
  135. }).catch(err => {
  136. console.error(err)
  137. this.$store.dispatch('alert', {
  138. style: 'error',
  139. icon: 'gg-warning',
  140. msg: err.message
  141. })
  142. this.isLoading = false
  143. })
  144. }
  145. },
  146. verifySecurityCode () {
  147. if (this.securityCode.length !== 6) {
  148. this.$store.dispatch('alert', {
  149. style: 'error',
  150. icon: 'gg-warning',
  151. msg: 'Enter a valid security code.'
  152. })
  153. this.$refs.iptTFA.focus()
  154. } else {
  155. this.isLoading = true
  156. graphQL.mutate({
  157. mutation: CONSTANTS.GRAPHQL.GQL_MUTATION_LOGINTFA,
  158. variables: {
  159. loginToken: this.loginToken,
  160. securityCode: this.securityCode
  161. }
  162. }).then(resp => {
  163. if (resp.data.loginTFA) {
  164. let respObj = resp.data.loginTFA
  165. if (respObj.succeeded === true) {
  166. this.$store.dispatch('alert', {
  167. style: 'success',
  168. icon: 'gg-check',
  169. msg: 'Login successful!'
  170. })
  171. this.isLoading = false
  172. } else {
  173. throw new Error(respObj.message)
  174. }
  175. } else {
  176. throw new Error('Authentication is unavailable.')
  177. }
  178. }).catch(err => {
  179. console.error(err)
  180. this.$store.dispatch('alert', {
  181. style: 'error',
  182. icon: 'gg-warning',
  183. msg: err.message
  184. })
  185. this.isLoading = false
  186. })
  187. }
  188. }
  189. },
  190. mounted () {
  191. this.$store.commit('navigator/subtitleStatic', 'Login')
  192. this.refreshStrategies()
  193. this.$refs.iptEmail.focus()
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. .login {
  199. background-color: mc('blue', '800');
  200. background-image: url('../../static/svg/login-bg-motif.svg');
  201. background-repeat: repeat;
  202. background-size: 200px;
  203. width: 100%;
  204. height: 100%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. animation: loginBgReveal 20s linear infinite;
  209. @include keyframes(loginBgReveal) {
  210. 0% {
  211. background-position-y: 0;
  212. }
  213. 100% {
  214. background-position-y: -800px;
  215. }
  216. }
  217. &::before {
  218. content: '';
  219. position: absolute;
  220. background-image: url('../../static/svg/login-bg.svg');
  221. background-position: center bottom;
  222. background-size: cover;
  223. top: 0;
  224. left: 0;
  225. width: 100vw;
  226. height: 100vh;
  227. @include until($tablet) {
  228. display: none;
  229. }
  230. }
  231. &::after {
  232. content: '';
  233. position: absolute;
  234. background-image: linear-gradient(to bottom, rgba(mc('blue', '800'), 1) 0%, rgba(mc('blue', '800'), 0) 100%);
  235. top: 0;
  236. left: 0;
  237. width: 100vw;
  238. height: 25vh;
  239. }
  240. &-container {
  241. position: relative;
  242. display: flex;
  243. width: 400px;
  244. align-items: stretch;
  245. box-shadow: 0 14px 28px rgba(0,0,0,0.2);
  246. border-radius: 6px;
  247. animation: zoomIn .5s ease;
  248. &::after {
  249. position: absolute;
  250. top: 1rem;
  251. right: 1rem;
  252. content: " ";
  253. @include spinner(mc('blue', '500'),0.5s,16px);
  254. display: none;
  255. }
  256. &.is-expanded {
  257. width: 650px;
  258. .login-frame {
  259. border-radius: 0 6px 6px 0;
  260. border-left: none;
  261. @include until($tablet) {
  262. border-radius: 0;
  263. }
  264. }
  265. }
  266. &.is-loading::after {
  267. display: block;
  268. }
  269. @include until($tablet) {
  270. width: 100%;
  271. border-radius: 0;
  272. &.is-expanded {
  273. width: 100%;
  274. }
  275. }
  276. }
  277. &-providers {
  278. display: flex;
  279. flex-direction: column;
  280. width: 250px;
  281. border-right: none;
  282. border-radius: 6px 0 0 6px;
  283. z-index: 1;
  284. overflow: hidden;
  285. @include until($tablet) {
  286. width: 50px;
  287. border-radius: 0;
  288. }
  289. button {
  290. flex: 0 1 50px;
  291. padding: 5px 15px;
  292. border: none;
  293. color: #FFF;
  294. // background: linear-gradient(to right, rgba(mc('light-blue', '800'), .7), rgba(mc('light-blue', '800'), 1));
  295. // border-top: 1px solid rgba(mc('light-blue', '900'), .5);
  296. background: linear-gradient(to right, rgba(0,0,0, .5), rgba(0,0,0, .7));
  297. border-top: 1px solid rgba(0,0,0, .2);
  298. font-family: $core-font-standard;
  299. font-weight: 600;
  300. text-align: left;
  301. min-height: 40px;
  302. display: flex;
  303. justify-content: flex-start;
  304. align-items: center;
  305. transition: all .4s ease;
  306. &:focus {
  307. outline: none;
  308. }
  309. @include until($tablet) {
  310. justify-content: center;
  311. }
  312. &:hover {
  313. background-color: rgba(0,0,0, .4);
  314. }
  315. &:first-child {
  316. border-top: none;
  317. &.is-active {
  318. border-top: 1px solid rgba(255,255,255, .5);
  319. }
  320. }
  321. &.is-active {
  322. background-image: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,.77) 100%);
  323. color: mc('grey', '800');
  324. cursor: default;
  325. &:hover {
  326. background-color: transparent;
  327. }
  328. svg path {
  329. fill: mc('grey', '800');
  330. }
  331. }
  332. i {
  333. margin-right: 10px;
  334. font-size: 16px;
  335. @include until($tablet) {
  336. margin-right: 0;
  337. font-size: 20px;
  338. }
  339. }
  340. svg {
  341. margin-right: 10px;
  342. width: auto;
  343. height: 20px;
  344. max-width: 18px;
  345. max-height: 20px;
  346. path {
  347. fill: #FFF;
  348. }
  349. @include until($tablet) {
  350. margin-right: 0;
  351. font-size: 20px;
  352. }
  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>