LoginForm.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <script>
  2. import Vue from 'vue'
  3. import { mapState, mapActions } from 'vuex'
  4. import { MA } from 'vuejs/api/ma-axios'
  5. export default {
  6. name: "LoginForm",
  7. data: () => ({
  8. form:null,
  9. mail:null,
  10. password:null
  11. }),
  12. computed: {
  13. ...mapState({
  14. loginMessage: state => state.User.loginMessage,
  15. })
  16. },
  17. methods: {
  18. ...mapActions({
  19. userLogin: 'User/userLogin'
  20. }),
  21. getLoginForm(){
  22. // Form through ajax is provided by materio_user drupal custom module
  23. // vuejs attributes a inserted by form alter in same module
  24. MA.get(`/materio_user/login_form`)
  25. .then(({data}) => {
  26. console.log('getLoginForm data')
  27. this.form = Vue.compile(data.rendered)
  28. this.$options.staticRenderFns = [];
  29. this._staticTrees = [];
  30. this.form.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
  31. })
  32. .catch((error) => {
  33. console.warn('Issue with getLoginForm', error)
  34. })
  35. },
  36. login () {
  37. this.userLogin({
  38. mail: this.mail,
  39. pass: this.password
  40. }).then( () => {
  41. console.log('logedin from login component')
  42. this.$emit('onLogedIn')
  43. }
  44. ).catch((error) => {
  45. console.warn('Issue with login from login component', error)
  46. Promise.reject(error)
  47. })
  48. }
  49. },
  50. beforeMount () {
  51. if (!this.form) {
  52. this.getLoginForm()
  53. }
  54. },
  55. mounted(){
  56. // console.log('LoginBlock mounted')
  57. Drupal.attachBehaviors(this.$el);
  58. },
  59. render(h) {
  60. // console.log('LoginBlock render')
  61. if (!this.form) {
  62. // console.log('LoginBlock render NAN')
  63. return h('span', 'Loading ...')
  64. } else {
  65. // console.log('LoginBlock render template')
  66. return this.form.render.call(this)
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .form-item,
  73. .form-actions{
  74. display:inline-block;
  75. max-width:32%;
  76. margin:0;
  77. }
  78. input{
  79. box-sizing:border-box;
  80. max-width:100%;
  81. }
  82. div.description{
  83. display:none;
  84. }
  85. .form-item-persistent-login{
  86. display:none;
  87. }
  88. </style>