loading and displaying real login form and register form from drupal
This commit is contained in:
@ -1,94 +0,0 @@
|
||||
<template lang="html">
|
||||
<div id="block-userlogin" class="">
|
||||
<h2>{{ title }}</h2>
|
||||
<section>
|
||||
<input
|
||||
id="edit-name"
|
||||
class="form-email"
|
||||
type="text"
|
||||
v-bind:placeholder="form.ph_email" name="name"
|
||||
v-model="mail"
|
||||
@keyup.enter="login"
|
||||
/>
|
||||
<input
|
||||
id="edit-pass"
|
||||
class="form-text"
|
||||
type="password"
|
||||
v-bind:placeholder="form.ph_pass" name="pass"
|
||||
v-model="password"
|
||||
@keyup.enter="login"
|
||||
/>
|
||||
<button
|
||||
id="edit-submit"
|
||||
class="button"
|
||||
@click.stop="login"
|
||||
>
|
||||
{{ form.btn_value }}
|
||||
</button>
|
||||
<ul>
|
||||
<li><a
|
||||
v-bind:href="form.register.href"
|
||||
>
|
||||
{{ form.register.title }}
|
||||
</a></li>
|
||||
<li><a
|
||||
v-bind:href="form.reset.href"
|
||||
>
|
||||
{{ form.reset.title }}
|
||||
</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// https://github.com/alvar0hurtad0/drupal-vuejs-todo
|
||||
import { mapState, mapActions } from 'vuex'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
mail: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
props: ['title', 'form'],
|
||||
computed: {
|
||||
...mapState(['User'])
|
||||
},
|
||||
methods: {
|
||||
...mapActions({
|
||||
userLogin: 'User/userLogin'
|
||||
}),
|
||||
login () {
|
||||
this.userLogin({
|
||||
mail: this.mail,
|
||||
pass: this.password
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
section{
|
||||
max-width:300px;
|
||||
}
|
||||
input{
|
||||
display:block;
|
||||
max-width:100%;
|
||||
margin:0.5em 0 0 0;
|
||||
}
|
||||
button{
|
||||
margin:0.5em 0 0 0;
|
||||
}
|
||||
ul{
|
||||
margin:0; padding:0.5em 0 0 0;
|
||||
}
|
||||
li{
|
||||
list-style:none;
|
||||
margin:0.5em 0 0 0; padding:0;
|
||||
font-size:0.882em;
|
||||
}
|
||||
a{
|
||||
}
|
||||
</style>
|
@ -0,0 +1,86 @@
|
||||
<script>
|
||||
|
||||
import Vue from 'vue'
|
||||
import { mapState, mapActions } from 'vuex'
|
||||
import { MA } from 'vuejs/api/ma-axios'
|
||||
|
||||
export default {
|
||||
name: "LoginForm",
|
||||
data: () => ({
|
||||
form:null,
|
||||
mail:null,
|
||||
password:null
|
||||
}),
|
||||
methods: {
|
||||
...mapActions({
|
||||
userLogin: 'User/userLogin'
|
||||
}),
|
||||
getLoginForm(){
|
||||
// Form through ajax is provided by materio_user custom module
|
||||
// vuejs attributes a inserted by template in theme level
|
||||
MA.get(`/materio_user/login_form`)
|
||||
.then(({data}) => {
|
||||
console.log("getLoginForm data");
|
||||
this.form = Vue.compile(data.rendered)
|
||||
this.$options.staticRenderFns = [];
|
||||
this._staticTrees = [];
|
||||
this.form.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
|
||||
})
|
||||
.catch(( error ) => {
|
||||
console.warn('Issue with getLoginForm', error)
|
||||
})
|
||||
},
|
||||
login () {
|
||||
this.userLogin({
|
||||
mail: this.mail,
|
||||
pass: this.password
|
||||
}).then( () => {
|
||||
console.log('logedin from login component');
|
||||
this.$emit('onLogedIn')
|
||||
}
|
||||
).catch(( error ) => {
|
||||
console.warn('Issue with login from login component', error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
}
|
||||
},
|
||||
beforeMount () {
|
||||
if(!this.form){
|
||||
this.getLoginForm()
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
// console.log('LoginBlock mounted');
|
||||
Drupal.attachBehaviors(this.$el);
|
||||
},
|
||||
render(h) {
|
||||
// console.log('LoginBlock render');
|
||||
if(!this.form){
|
||||
// console.log('LoginBlock render NAN');
|
||||
return h('span', 'Loading ...')
|
||||
}else{
|
||||
// console.log('LoginBlock render template');
|
||||
return this.form.render.call(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-item,
|
||||
.form-actions{
|
||||
display:inline-block;
|
||||
max-width:32%;
|
||||
margin:0;
|
||||
}
|
||||
input{
|
||||
box-sizing:border-box;
|
||||
max-width:100%;
|
||||
}
|
||||
div.description{
|
||||
display:none;
|
||||
}
|
||||
.form-item-persistent-login{
|
||||
display:none;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,86 @@
|
||||
<script>
|
||||
|
||||
import Vue from 'vue'
|
||||
import { mapState, mapActions } from 'vuex'
|
||||
import { MA } from 'vuejs/api/ma-axios'
|
||||
|
||||
export default {
|
||||
name: "RegisterForm",
|
||||
data: () => ({
|
||||
form:null,
|
||||
mail:null,
|
||||
password:null
|
||||
}),
|
||||
methods: {
|
||||
...mapActions({
|
||||
userRegister: 'User/userRegister'
|
||||
}),
|
||||
getRegisterForm(){
|
||||
// Form through ajax is provided by materio_user custom module
|
||||
// vuejs attributes a inserted by template in theme level
|
||||
MA.get(`/materio_user/register_form`)
|
||||
.then(({data}) => {
|
||||
console.log("getRegisterForm data");
|
||||
this.form = Vue.compile(data.rendered)
|
||||
this.$options.staticRenderFns = [];
|
||||
this._staticTrees = [];
|
||||
this.form.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
|
||||
})
|
||||
.catch(( error ) => {
|
||||
console.warn('Issue with getRegisterForm', error)
|
||||
})
|
||||
},
|
||||
// login () {
|
||||
// this.userLogin({
|
||||
// mail: this.mail,
|
||||
// pass: this.password
|
||||
// }).then( () => {
|
||||
// console.log('logedin from login component');
|
||||
// this.$emit('onLogedIn')
|
||||
// }
|
||||
// ).catch(( error ) => {
|
||||
// console.warn('Issue with login from login component', error)
|
||||
// Promise.reject(error)
|
||||
// })
|
||||
// }
|
||||
},
|
||||
beforeMount () {
|
||||
if(!this.form){
|
||||
this.getRegisterForm()
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
// console.log('LoginBlock mounted');
|
||||
Drupal.attachBehaviors(this.$el);
|
||||
},
|
||||
render(h) {
|
||||
// console.log('LoginBlock render');
|
||||
if(!this.form){
|
||||
// console.log('LoginBlock render NAN');
|
||||
return h('span', 'Loading ...')
|
||||
}else{
|
||||
// console.log('LoginBlock render template');
|
||||
return this.form.render.call(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
// .form-item,
|
||||
// .form-actions{
|
||||
// display:inline-block;
|
||||
// max-width:30%;
|
||||
// margin:0;
|
||||
// }
|
||||
// input{
|
||||
// box-sizing:content-box;
|
||||
// max-width:100%;
|
||||
// }
|
||||
// div.description{
|
||||
// display:none;
|
||||
// }
|
||||
// .form-item-persistent-login{
|
||||
// display:none;
|
||||
// }
|
||||
</style>
|
Reference in New Issue
Block a user