LoginForm.vue 2.0 KB

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