}elseif(in_array($key,['phone'])){
$validation[$key] = 'required|numeric';
}elseif ($key === "actually_password"){
- $validation[$key] = 'required|missing|current_password';
+ $validation[$key] = 'required';
}elseif ($key === "password"){
$validation[$key] = 'required|confirmed|min:8';
}
}
$data = $this->validation_form($request, $validation);
-
- $data['password'] = Hash::make($data['password']);
- /*$password = $data['actually_password'];
- $actuallyPassword = Auth::guard('web-clients')->user()->password;*/
$email = Auth::guard('web-clients')->user()->email;
- /*if (!Hash::check($password,$actuallyPassword)) {
- throw ValidationException::withMessages(['password' => __('Le mot de passe est incorrect')]);
+ if($request->password) {
+ $data['password'] = Hash::make($data['password']);
+ $password = $data['actually_password'];
+ $actuallyPassword = Auth::guard('web-clients')->user()->password;
+
+ if (!Hash::check($password, $actuallyPassword)) {
+ throw ValidationException::withMessages(['password' => __('Le mot de passe est incorrect')]);
+ }
+ unset($data['actually_password']);
}
- unset($data['actually_password']);*/
$client = Client::where('email',$email)->update($data);
}
}
-
if(isset($request->address['delivery_address'])){
foreach ($addressToArray as $key => &$value){
$value->delivery_address = "0";
}
public function getuser() {
- return Auth::guard('web-clients')->user();
+ $user = Auth::guard('web-clients')->user();
+ $addressToArray = json_decode($user->address);
+ $checkBillingAddress = array_filter($addressToArray, function($n) { return $n->billing_address; });
+ $checkDeliveryAddress = array_filter($addressToArray, function($n) { return $n->delivery_address; });
+
+ $data = [
+ 'user' => $user,
+ 'address_billing' => key($checkBillingAddress) ?? "0",
+ 'address_delivery' => key($checkDeliveryAddress) ?? "0"
+ ];
+
+ return $data;
}
}
{
public function view(Request $request)
{
- return view('pages.signin');
+ return view('pages.sign_in');
}
}
*/
public function handle($request, Closure $next)
{
- if (($request->is('se-connecter')) && Auth::guard('web-clients')->check()) {
+ if (($request->path() === "se-connecter") && Auth::guard('web-clients')->check()) {
return redirect('/');
}
- if (($request->is('mon-compte')) && !Auth::guard('web-clients')->check()) {
+ if (($request->path() === "mon-compte") && !Auth::guard('web-clients')->check()) {
return redirect('/se-connecter');
}
$this->addField(['name' => 'password',
'label' => 'Password',
- 'type' => 'Text']);
+ 'type' => 'Hidden']);
$this->addField(['name' => 'lastname',
'label' => 'Nom',
'type' => 'BunchOfFieldsMultiple',
'bunch' => 'App\SubForms\Address',
'column' => true,
- 'tab' => 'Informations client'
+ 'tab' => 'Informations client',
+ 'edit_label' => 'Éditer « %city »'
]);
$this->addField(['name' => 'status',
BladeX::component('components.cart-add')->tag('cart-add'); // <cart-add id="1234"> ... </cart-add>
BladeX::component('components.news-grid'); // <news-grid :items="$news"> ... </news-grid>
BladeX::component('components.news-item'); // <news-item :item="$newsItem"> ... </news-item>
- BladeX::component('components.address-form'); // <news-item :item="$newsItem"> ... </news-item>
+ BladeX::component('components.address-form'); // <address-form> ... </address-form>
+ BladeX::component('components.modal-confirm'); // <modal-confirm> ... </modal-confirm>
} catch (\Exception $e) {
}
$this->mapApiRoutes();
$this->mapWebRoutes();
-
//
}
{
parent::init();
- $this->addField([
- 'name' => 'id',
- 'label' => 'Id',
- 'type' => 'Integer',
- 'attributes' => [
- 'disabled' => 'disabled'
- ]
- ]);
-
$this->addField([
'name' => 'name',
'label' => "Nom de l'adresse",
- 'type' => 'Text',
- 'tab' => 'Nom'
+ 'type' => 'Text'
]);
$this->addField([
'name' => 'address',
'label' => "Adresse",
- 'type' => 'Textarea',
- 'tab' => 'Adresse'
+ 'type' => 'Textarea'
]);
$this->addField([
'name' => 'lastname',
'label' => "Nom",
- 'type' => 'Text',
- 'tab' => 'Nom'
+ 'type' => 'Text'
]);
$this->addField([
'name' => 'firstname',
'label' => "Prénom",
- 'type' => 'Text',
- 'tab' => 'Prénom'
+ 'type' => 'Text'
]);
$this->addField([
'name' => 'zipcode',
'label' => "Code postal",
- 'type' => 'Number',
- 'tab' => 'Code postal'
+ 'type' => 'Number'
]);
$this->addField([
'name' => 'city',
- 'label' => "Titre",
- 'type' => 'Text',
- 'tab' => 'Ville'
+ 'label' => "Ville",
+ 'type' => 'Text'
]);
$this->addField([
'name' => 'billing_address',
- 'label' => "Adresse de facturation",
+ 'label' => "Adresse de facturation par défaut",
'type' => 'Checkbox',
]);
$this->addField([
'name' => 'delivery_address',
- 'label' => "Adresse de livraison",
+ 'label' => "Adresse de livraison par défaut",
'type' => 'Checkbox',
]);
}
data: {
items: {}, // Populated from data attribute on root element so we can pass data from PHP
savingCart: false,
- type: 'password',
+ type: {
+ 'pw': 'password',
+ 'new_pw': 'password',
+ 'confirm': 'password'
+ },
email_signin: '',
password_signin: '',
emailExist: false,
validateEmail: false,
address_choice: true,
- validateRegister: false,
+ validateForm: false,
tab: 'infos',
addresses: [{}],
errorsForm: {},
});
},
- updated(){
- //console.log(this.selected)
- },
-
computed: {
cartItemCount() {
// Todo: See if this should count just number of items or make a sum of all quantities? What is more useful? The sum of quantities can be found using map/reduce functions but this needs to be adapted for the object structure using Object.keys as the source.
closeCart() {
document.body.classList.remove('cart-open');
},
- //next code is for login and register form
- toggleType() {
- this.type = this.type === "password" ? "text" : "password"
+ //next code is for login and account page
+ toggleType(el) {
+ this.type[el] = this.type[el] === "password" ? "text" : "password"
},
removeErrors() {
- let errorMessage = document.querySelectorAll('.form-error'),
+ let errors = document.querySelector('.form-errors'),
errorInput = document.querySelectorAll('.error')
- for (var i = 0; i < errorMessage.length; i++) {
- errorMessage[i].remove();
- }
- for (var i = 0; i < errorInput.length; i++) {
- errorInput[i].classList.remove('error');
- }
+ if(errors)
+ errors.remove()
+ for (var i = 0; i < errorInput.length; i++) {
+ errorInput[i].classList.remove('error');
+ }
},
checkEmailExist() {
let root = this,
console.log('error', error)
})
},
+ errorHandling(data, root){
+ if (data.response) {
+ let errors = data.response.data.errors
+ root.errorsForm = errors
+
+ root.removeErrors()
+
+ for (let k in errors) {
+ if(k.indexOf('.')){
+ let keys = k.split('.')
+ for(let i = 0; i < keys.length; i++){
+ if(i !== 0){
+ k += '['+keys[i]+']'
+ }else{
+ k = keys[i]
+ }
+ }
+ }
+ let el = document.querySelector('[name*="' + k + '"]')
+ el.classList.add('error')
+ }
+ }
+ },
signin() {
let root = this,
form = document.getElementById('signin-form'),
}
})
.catch(function (error) {
- console.log(error)
+ root.errorHandling(error, root)
})
},
- async signup() {
+ signup() {
let root = this,
form = document.getElementById('signup-form'),
data = new FormData(form)
- await axios.post('/ajax/signup', data)
+ axios.post('/ajax/signup', data)
.then(function (response) {
//
root.removeErrors()
top: 0,
behavior: "smooth"
})
- root.validateRegister = true
+ root.validateForm = true
root.email_signin = ''
root.errorsForm = {}
})
.catch(function (error) {
- if (error.response) {
- let errors = error.response.data.errors
- root.errorsForm = errors
-
- root.removeErrors()
-
- for (let k in errors) {
- if(k.indexOf('.')){
- let keys = k.split('.')
- for(let i = 0; i < keys.length; i++){
- if(i !== 0){
- k += '['+keys[i]+']'
- }else{
- k = keys[i]
- }
- }
- }
- let el = document.querySelector('[name*="' + k + '"]')
- el.classList.add('error')
- }
- }
+ root.errorHandling(error, root)
})
},
activeTab(tab){
this.tab = tab
+ this.errorsForm = {}
this.resetUrlAccount()
+ this.removeErrors()
},
getUser(){
let root = this
axios.post('/ajax/getuser')
.then(function (response) {
//
- root.user = response.data
- root.addresses = JSON.parse(response.data.address)
+ root.user = response.data['user']
+ root.addresses = JSON.parse(root.user.address)
- let indexBillingAddress = root.addresses.filter(address => address.billing_address === "1")[0]['id'];
- let indexDeliveryAddress = root.addresses.filter(address => address.delivery_address === "1")[0]['id'];
-
- root.default_billing_address = 'billing'+indexBillingAddress
- root.default_delivery_address = 'delivery'+indexDeliveryAddress
+ root.default_billing_address = 'billing'+response.data['address_billing']
+ root.default_delivery_address = 'delivery'+response.data['address_delivery']
})
.catch(function (error) {
})
},
- addAddressToForm(){
+ addAddressToForm(event){
let newAddress = {
'billing_address': '0',
'delivery_address': '0'
}
+
this.addresses.push(newAddress)
+
+ //disabled click at most once
+ let target = event.target
+ target.setAttribute('disabled', 'disabled')
+
+ setTimeout(function (){
+
+ let forms = document.querySelector('.form-portal').parentElement.parentElement.lastChild
+ let top = forms.offsetTop - 60;
+
+ window.scrollTo({
+ top: top,
+ behavior: "smooth"
+ })
+
+ //enabled click after scroll is happened
+ target.removeAttribute('disabled')
+
+ }, 150)
},
update(id){
let root = this,
.then(function (response) {
//
root.removeErrors()
- root.validateRegister = true
+ root.validateForm = true
root.form[id] = response.data
})
.catch(function (error) {
-
+ root.errorHandling(error, root)
})
},
updateAddress(id){
.then(function (response) {
//
root.removeErrors()
- root.validateRegister = true
+ root.validateForm = true
})
.catch(function (error) {
-
+ root.errorHandling(error, root)
})
},
deleteAddress(index, form){
})
}
+ },
+ directives: {
+ 'close-outside': {
+ twoWay: true,
+ bind(el, binding, vnode) {
+ const vm = vnode.context;
+ Window.event = (e) => {
+ if (!el.contains(e.target) || e.key === "Escape") {
+ vm.validateForm = false
+ }
+ }
+ document.body.addEventListener('click', Window.event)
+ document.body.addEventListener('keydown', Window.event)
+ },
+ unbind: function () {
+ document.body.removeEventListener('click', Window.event)
+ document.body.removeEventListener('keydown', Window.event)
+ },
+ }
}
-
});
}
});
+/**
+ * The following block of code is used for to close "modal confirm update/register"
+ * with escape key of keyboard or by clicking outside the modal
+ */
+
+/**
+ * end of block
+ */
+
document.addEventListener('scroll', function () {
checkScroll();
}, {passive: true});
width: 100%
height: 100vh
padding: 0 25px
- z-index: 99
- top: -120px
+ z-index: 999
+ //top: -120px
+ top: -var(--header-height)
&-text
width: 100%
max-width: 744px
&.label-checkbox
display: flex !important
- [type="checkbox"]
+ [type="radio"]
width: 16px !important
height: 24px
margin: 0
.line-up
border-top: 1px solid #D5D7DF
-[class*="-form-errors"]
+[class*="form-errors"]
padding: 20px
background: rgba(248,30,96,.21)
li
<form :id="'update-address-'+key" class="form-portal max-w-half-form" @submit.prevent="updateAddress('update-address-'+key)">
+ <div class="form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <ul class="list-disc list-inside text-red">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ @{{ errorName[0] }}
+ </li>
+ </ul>
+ </div>
<div class="form-group mb-12">
<div class="fields grid">
<label class="form-input text-navy">
</div>
<div class="form-group">
<label class="label-checkbox flex">
- <input type="checkbox" :checked="default_billing_address !== 'billing'+key ? false : true" class="w-4 h-4" name="address[billing_address]" @click="default_billing_address = 'billing'+key" />
+ <input type="radio" :checked="default_billing_address !== 'billing'+key ? false : true" class="w-4 h-4" name="address[billing_address]" @click="default_billing_address = 'billing'+key" />
<span class="ml-4">{{ __('Adresse de facturation par défaut') }}</span>
</label>
<label class="label-checkbox flex mb-6">
- <input type="checkbox" :checked="default_delivery_address !== 'delivery'+key ? false : true" class="w-4 h-4" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+key" />
+ <input type="radio" :checked="default_delivery_address !== 'delivery'+key ? false : true" class="w-4 h-4" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+key" />
<span class="ml-4">{{ __('Adresse de livraison par défaut') }}</span>
</label>
</div>
<span class="ml-3">Supprimer cette adresse</span>
</button>
</form>
-
--- /dev/null
+<div class="modal-confirm fixed top-0 left-0 flex items-center" v-cloak v-if="validateForm">
+ <div class="modal-confirm-text relative text-2xl bg-white p-24 text-center mx-auto" v-close-outside>
+ <button class="modal-confirm-close absolute" @click.prevent="validateForm = false">
+ @svg('icon-close-thin', 'w-4')
+ </button>
+ {{ $slot }}
+ </div>
+</div>
<div class="ajax-form flex flex-col pt-12">
<h2 class="text-2xl m-0">{{ __('Mes coordonnées') }}</h2>
<form id="update-details" class="form-portal max-w-half-form" @submit.prevent="update('update-details')">
+ <div class="form-errors my-10" v-if="Object.keys(errorsForm).length > 0">
+ <ul class="list-disc list-inside text-red">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ @{{ errorName[0] }}
+ </li>
+ </ul>
+ </div>
<div class="form-group fields grid">
<label class="form-input half text-navy">
{{ __('Nom') }}<span>*</span>
<div id="account-address" class="account-address" v-cloak v-if="tab === 'address'">
<div class="account-address-header flex items-center justify-between border-b border-b-light-b relative">
<h2 class="text-2xl m-0">{{ __('Mes adresses') }}</h2>
- <button class="btn btn-custom xs:w-full flex items-center absolute right-0" @click.prevent="addAddressToForm()">
+ <button class="btn btn-custom xs:w-full flex items-center absolute right-0" @click.prevent="addAddressToForm">
<span class="pr-2">{{ __('Ajouter une adresse') }}</span>
@svg('icon-white-add')
</button>
<div class="pb-12 border-b border-b-light-b">
<h2 class="text-2xl m-0">{{ __('Modifier mon mot de passe') }}</h2>
</div>
+ <div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <ul class="list-disc list-inside text-red">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ @{{ errorName[0] }}
+ </li>
+ </ul>
+ </div>
<div class="ajax-form flex flex-col pt-12">
<form id="update-password" class="form-portal max-w-half-form" @submit.prevent="update('update-password')">
<div class="form-group fields grid">
<label class="form-input text-navy">
{{ __('Mot de passe actuel') }}<span>*</span>
<div class="relative">
- <input class="py-3 mt-3" :type="type" required="required" name="actually_password" />
- <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType">
- <span v-if="type === 'password' ">
+ <input class="py-3 mt-3" :type="type['pw']" required="required" name="actually_password" />
+ <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType('pw')">
+ <span v-if="type['pw'] === 'password' ">
@svg('icon-eye')
</span>
<span v-else>
<label class="form-input text-navy">
{{ __('Nouveau mot de passe') }}<span>*</span>
<div class="relative">
- <input class="py-3 mt-3" :type="type" required="required" name="password" />
- <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType">
- <span v-if="type === 'password' ">
+ <input class="py-3 mt-3" :type="type['new_pw']" required="required" name="password" />
+ <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType('new_pw')">
+ <span v-if="type['new_pw'] === 'password' ">
@svg('icon-eye')
</span>
<span v-else>
<label class="form-input text-navy">
{{ __('Confirmer le nouveau mot de passe') }}<span>*</span>
<div class="relative">
- <input class="py-3 mt-3" :type="type" required="required" name="password_confirmation" />
- <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType">
- <span v-if="type === 'password' ">
+ <input class="py-3 mt-3" :type="type['confirm']" required="required" name="password_confirmation" />
+ <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType('confirm')">
+ <span v-if="type['confirm'] === 'password' ">
@svg('icon-eye')
</span>
<span v-else>
</div>
</content>
</full-width>
+ <modal-confirm>
+ <p>{{ __('Vos informations ont été mises à jour avec succès !') }}</p>
+ </modal-confirm>
@endsection
<div class="form-info text-navy mb-10">
<h1 class="text-4xl m-0">Se connecter</h1>
</div>
+
<form id="signin-form" class="form-portal" @submit.prevent="signin">
+ <div class="form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <ul class="list-disc list-inside text-red">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ @{{ errorName[0] }}
+ </li>
+ </ul>
+ </div>
@csrf
<div class="form-group mb-6">
<label class="form-input text-navy">
<label class="form-input text-navy">
{{ __('Mot de passe') }}<span>*</span>
<div class="relative">
- <input class="py-3 mt-3" :type="type" required="required" name="password" />
- <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType">
- <span v-if="type === 'password' ">
+ <input class="py-3 mt-3" :type="type['pw']" name="password" />
+ <button class="btn-show-pwd bg-white w-12" @click.prevent="toggleType('pw')">
+ <span v-if="type['pw'] === 'password' ">
@svg('icon-eye')
</span>
<span v-else>
<div class="form-info text-navy mb-10">
<h1 class="text-4xl m-0">{{ __("Créer un compte") }}</h1>
</div>
+
<div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
<ul class="list-disc list-inside text-red">
<li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
</li>
</ul>
</div>
+
<form id="signup-form" class="form-portal" @submit.prevent="signup()">
@csrf
<div class="form-group mb-6">
</div>
</div>
</div>
- @include('partials.modal-confirm')
+ <modal-confirm>
+ <p class="mb-4">{{ __('Nous avons bien reçu votre demande d’inscription') }}.</p>
+ <p>{{ __('Vous recevrez un mail de confirmation une fois votre compte validé') }}.</p>
+ </modal-confirm>
@endsection
</nav>
-
<ul class="account-header">
- <li>
- <a href="{{ $nav->getHrefByName('signin') }}"
+ <li class="{{ Route::currentRouteName() === "client" ? "active" : '' }}">
+ <a href="{{ Auth::guard('web-clients')->check() ? $nav->getHrefByName('Mon compte') : $nav->getHrefByName('signin') }}"
class="text-right flex items-center cursor-pointer text-white hover:text-primary"
>
@include('partials.account')
+++ /dev/null
-<div class="modal-confirm absolute left-0 hidden" :ref="(modalconfirm) => modalconfirm.classList.remove('hidden')" v-if="validateRegister">
- <div class="modal-confirm-text relative text-2xl bg-white p-24 text-center mx-auto">
- <button class="modal-confirm-close absolute" @click.prevent="validateRegister = false">
- @svg('icon-close-thin', 'w-4')
- </button>
- <p class="mb-4">Nous avons bien reçu votre demande d’inscription.</p>
- <p>Vous recevrez un mail de confirmation une fois votre compte validé.</p>
- </div>
-</div>
@auth('web-clients')
<ul class="account-header-list">
- <li>
+ <li class="{{ Request::is('mon-compte') ? "active" : '' }}">
<a href="/mon-compte">
<span>{{ __('Mon compte') }}</span>
</a>
<ul>
- <li>
+ <li :class="{ active : tab === 'address' }">
<a href="/mon-compte#address" @click.stop="tab = 'address'">
<span>{{ __('Mes adresses') }}</span>
</a>
</li>
</ul>
</li>
- <li>
+ <li class="{{ Request::is('mes-commandes') ? "active" : '' }}">
<a href="">
<span>{{ __('Mes commandes') }}</span>
</a>
</li>
- <li>
+ <li class="{{ Request::is('panier-enregistré') ? "active" : '' }}">
<a href="">
<span>{{ __('Panier enregistrés') }}</span>
</a>
<?php
-
Route::get('/deconnexion', 'ClientController@logout');
+//add specific name to be simple to add active class
+//add middleware to secure this specific page
+Route::any('{page}', 'PageController@catchall')->where(
+ ['page' => '\b(se-connecter|mon-compte)\b']
+)->name('client')->middleware('client');
+
Route::any('{page}/{subs?}', 'PageController@catchall')
- ->where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*'])
- ->middleware('client');
+ ->where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*']);