login from modal is working, register is lacking password generator

This commit is contained in:
Bachir Soussi Chiadmi 2019-10-06 16:32:25 +02:00
parent 79f9be6c06
commit 96b23acbb3
7 changed files with 343 additions and 33 deletions

View File

@ -10,13 +10,23 @@
.modal[data-v-b98ce164] { .modal[data-v-b98ce164] {
background-color: #fff; background-color: #fff;
position: absolute; position: absolute;
width: 250px; box-sizing: border;
height: 200px; max-width: 80vw;
max-height: 70vh;
top: 0; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
margin: auto; margin: auto;
padding: 1em;
border-radius: 3px;
box-shadow: 2px 2px;
}
fieldset[data-v-2952b9b1] {
padding: 0;
margin: 0;
border: none;
} }

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@
<div class="description" v-html="product.field_description" /> <div class="description" v-html="product.field_description" />
<span class="price">{{ product.price__number }}</span> <span class="price">{{ product.price__number }}</span>
</section> </section>
<aside class=""> <aside v-if="!isAdherent">
<input <input
v-if="product.field_multiple" v-if="product.field_multiple"
v-model="quantity" v-model="quantity"
@ -24,11 +24,17 @@
Commander Commander
</button> </button>
</aside> </aside>
<Modal <Modal
v-if="login" v-if="showLoginModal"
@close="closeModal"
> >
i'm a modal <div>
Please login or register before continue.
</div>
<LoginRegisterForm @onLogedIn="logedIn"/>
</Modal> </Modal>
</article> </article>
</template> </template>
@ -38,6 +44,7 @@ import { REST } from 'vuejs/api/rest-axios'
import router from 'vuejs/route' import router from 'vuejs/route'
import { mapState, mapActions } from 'vuex' import { mapState, mapActions } from 'vuex'
import Modal from 'vuejs/components/Helper/Modal' import Modal from 'vuejs/components/Helper/Modal'
import LoginRegisterForm from 'vuejs/components/Helper/LoginRegisterForm'
let basePath = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix; let basePath = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix;
@ -48,25 +55,28 @@ export default {
data(){ data(){
return { return {
quantity: 1, quantity: 1,
login:false, showLoginModal:false
register:false
} }
}, },
computed: { computed: {
...mapState({ ...mapState({
isloggedin: state => state.User.isloggedin isloggedin: state => state.User.isloggedin,
isAdherent: state => state.User.isAdherent
}) })
}, },
methods:{ methods:{
...mapActions({ // ...mapActions({
userLogin: 'User/userLogin' // userLogin: 'User/userLogin'
}), // }),
closeModal () {
this.showLoginModal = false;
},
checkaddtocart() { checkaddtocart() {
console.log('checkaddtocart'); console.log('checkaddtocart');
if(!this.isloggedin){ if(!this.isloggedin){
// TODO: show popup login or register // TODO: show popup login or register
this.login = true this.showLoginModal = true
// TODO: rest login or register // TODO: rest login or register
// TODO: rest login // TODO: rest login
// TODO: this.addtocart() // TODO: this.addtocart()
@ -74,6 +84,10 @@ export default {
this.addtocart() this.addtocart()
} }
}, },
logedIn () {
console.log('Product: logedIn');
this.closeModal()
},
addtocart () { addtocart () {
console.log("addtocart") console.log("addtocart")
@ -93,7 +107,8 @@ export default {
} }
}, },
components: { components: {
Modal Modal,
LoginRegisterForm
} }
} }
</script> </script>

View File

@ -0,0 +1,58 @@
<template>
<div id="login-form">
<h2>Login</h2>
<input
type="email"
name="email"
v-model="email"
placeholder="Email"
>
<input
type="password"
name="password"
v-model="password"
placeholder="Password"
>
<button
type="button"
name="login"
@click.stop="onLogin"
>
login
</button>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
name: "LoginForm",
data: () => ({
email:null,
password:null
}),
methods: {
...mapActions({
userLogin: 'User/userLogin'
}),
onLogin () {
this.userLogin({
mail: this.email,
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)
})
}
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -0,0 +1,97 @@
<template>
<div id="login-form">
<fieldset class="login">
<h2>Login</h2>
<input
type="email"
name="email"
v-model="loginEmail"
placeholder="Email"
>
<input
type="password"
name="password"
v-model="password"
placeholder="Password"
>
<button
type="button"
name="login"
@click.stop="onLogin"
>
login
</button>
</fieldset>
<fieldset class="register">
<h2>Or register</h2>
<input
type="email"
name="email"
v-model="registerEmail"
placeholder="Email"
>
<button
type="button"
name="register"
@click.stop="onRegister"
>
register
</button>
</fieldset>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
name: "LoginForm",
data: () => ({
loginEmail:null,
password:null,
registerEmail:null
}),
methods: {
...mapActions({
userLogin: 'User/userLogin',
userRegister: 'User/userRegister'
}),
onLogin () {
this.userLogin({
mail: this.loginEmail,
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)
})
},
onRegister () {
console.log('on register');
this.userRegister({
mail: this.registerEmail
}).then( () => {
console.log('user registered');
}
).catch(( error ) => {
console.warn('Issue with register from login component', error)
Promise.reject(error)
})
}
}
}
</script>
<style lang="scss" scoped>
fieldset{
padding:0;
margin:0;
border:none;
}
</style>

View File

@ -1,6 +1,12 @@
<template> <template>
<div class="overlay"> <div
<div class="modal"> class="overlay"
@click.self="close"
>
<div
class="modal"
v-bind:style="styles"
>
<slot></slot> <slot></slot>
</div> </div>
</div> </div>
@ -8,9 +14,26 @@
<script> <script>
export default { export default {
name: "", name: "",
props: {
styles: {
default: function () {
return {
width: '500px',
height: '350px'
}
},
type: Object
}
},
data: () => ({ data: () => ({
}) }),
methods: {
close () {
console.log('click close');
this.$emit('close')
}
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -23,9 +46,14 @@ export default {
.modal{ .modal{
background-color:#fff; background-color:#fff;
position:absolute; position:absolute;
width:250px; box-sizing:border;
height:200px; max-width:80vw;
max-height:70vh;
top:0; right:0; bottom:0; left:0; top:0; right:0; bottom:0; left:0;
margin:auto; margin:auto;
padding:1em;
border-radius:3px;
box-shadow:2px 2px;
} }
</style> </style>

View File

@ -14,7 +14,9 @@ export default {
logout_token: null, logout_token: null,
isloggedin: false, isloggedin: false,
isAdmin: false, isAdmin: false,
canSearch: false isAdherent: false,
canSearch: false,
roles: []
}, },
// getters // getters
@ -53,6 +55,7 @@ export default {
if(state.roles.indexOf('adherent') != -1){ if(state.roles.indexOf('adherent') != -1){
// console.log('is admin'); // console.log('is admin');
state.canSearch = true state.canSearch = true
state.isAdherent = true
} }
}, },
setLoggedOut (state) { setLoggedOut (state) {
@ -73,7 +76,21 @@ export default {
// actions // actions
actions : { actions : {
userRegister({ dispatch, commit, state }, credentials){
return new Promise((resolve, reject) => {
REST.post('/user/register?_format=json', credentials)
.then(({ data }) => {
console.log('user REST registered', data);
resolve()
})
.catch(( error ) => {
console.warn('Issue with register', error)
Promise.reject(error)
})
})
},
userLogin({ dispatch, commit, state }, credentials){ userLogin({ dispatch, commit, state }, credentials){
return new Promise((resolve, reject) => {
dispatch('getToken', credentials) dispatch('getToken', credentials)
.then(() => { .then(() => {
dispatch('getUser').then((userdata) => { dispatch('getUser').then((userdata) => {
@ -81,6 +98,8 @@ export default {
if (state.isAdmin){ if (state.isAdmin){
window.location.reload(true); window.location.reload(true);
} }
resolve()
})
}) })
}) })
}, },