RegisterForm.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <script>
  2. import Vue from 'vue'
  3. import { mapState, mapActions } from 'vuex'
  4. import { MA } from 'vuejs/api/ma-axios'
  5. import passwordStrength from 'check-password-strength'
  6. export default {
  7. name: "RegisterForm",
  8. data: () => ({
  9. form: null,
  10. mail: null,
  11. pass1: null,
  12. pass2: null,
  13. ps: ""
  14. }),
  15. computed: {
  16. psswd_class: function(){
  17. return this.ps.toLowerCase()
  18. },
  19. can_register: function() {
  20. if (this.ps === "Strong") {
  21. return 'can-register'
  22. }
  23. return ''
  24. }
  25. },
  26. methods: {
  27. ...mapActions({
  28. userRegister: 'User/userRegister'
  29. }),
  30. getRegisterForm(){
  31. // Form through ajax is provided by materio_user drupal custom module
  32. // vuejs attributes a inserted by form alter in same module
  33. MA.get(`/materio_user/register_form`)
  34. .then(({data}) => {
  35. console.log("getRegisterForm data", data);
  36. this.form = Vue.compile(data.rendered)
  37. this.$options.staticRenderFns = [];
  38. this._staticTrees = [];
  39. this.form.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
  40. })
  41. .catch(( error ) => {
  42. console.warn('Issue with getRegisterForm', error)
  43. })
  44. },
  45. checkSubmitEnabled () {
  46. if(this.ps === 'Strong'){
  47. this.$refs.register.disabled = false
  48. }else{
  49. this.$refs.register.disabled = true
  50. }
  51. },
  52. register () {
  53. console.log('register', this.mail, this.pass1, this.pass2);
  54. // TODO: check for identical password
  55. // TODO: check for valide email
  56. // TODO: check for unique email
  57. if(this.pass1 === this.pass2){
  58. this.userRegister({
  59. name: this.mail,
  60. mail: this.mail,
  61. pass: this.pass1
  62. }).then( () => {
  63. console.log('registered from register component');
  64. this.$emit('onRegistered')
  65. }
  66. ).catch(( error ) => {
  67. console.warn('Issue with register from registerform component', error)
  68. Promise.reject(error)
  69. })
  70. }
  71. }
  72. },
  73. beforeMount () {
  74. if(!this.form){
  75. this.getRegisterForm()
  76. }
  77. },
  78. mounted(){
  79. // console.log('LoginBlock mounted');
  80. Drupal.attachBehaviors(this.$el);
  81. this.checkSubmitEnabled()
  82. },
  83. render(h) {
  84. // console.log('LoginBlock render');
  85. if(!this.form){
  86. // console.log('LoginBlock render NAN');
  87. return h('span', 'Loading ...')
  88. }else{
  89. // console.log('LoginBlock render template');
  90. return this.form.render.call(this)
  91. }
  92. },
  93. watch: {
  94. pass1: function(n, o){
  95. if(n){
  96. this.ps = passwordStrength(n).value
  97. console.log('watch pass1 n', n, 'ps :', this.ps)
  98. this.checkSubmitEnabled()
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .form-type-email,
  106. .form-type-password-confirm{
  107. // display:inline-block;
  108. max-width:30%;
  109. margin:0;
  110. }
  111. .form-type-password input{
  112. &.weak {
  113. border-width: 2px;
  114. border-color: red!important;
  115. &:focus{
  116. outline:none;
  117. }
  118. }
  119. &.medium {
  120. border-width: 2px;
  121. border-color: orange!important;
  122. &:focus{
  123. outline:none;
  124. }
  125. }
  126. &.strong {
  127. border-width: 2px;
  128. border-color: green!important;
  129. &:focus{
  130. outline:none;
  131. }
  132. }
  133. }
  134. input{
  135. box-sizing:content-box;
  136. max-width:100%;
  137. }
  138. // input#edit-submit{
  139. //
  140. // }
  141. label,
  142. div.description{
  143. display:none;
  144. }
  145. </style>