From: soufiane Date: Mon, 27 Mar 2023 09:00:30 +0000 (+0200) Subject: wip #5780 @6:30 Gestion des erreurs, correctifs js/css, refactorisation X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3dcff35c31e3fbba1ccdea13ff0a79007de50603;p=pmi.git wip #5780 @6:30 Gestion des erreurs, correctifs js/css, refactorisation --- diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 00b5e65..637ade4 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -385,23 +385,25 @@ class AjaxController extends CubistFrontController }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); } @@ -443,7 +445,6 @@ class AjaxController extends CubistFrontController } - if(isset($request->address['delivery_address'])){ foreach ($addressToArray as $key => &$value){ $value->delivery_address = "0"; @@ -490,6 +491,17 @@ class AjaxController extends CubistFrontController } 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; } } diff --git a/app/Http/Controllers/SignInController.php b/app/Http/Controllers/SignInController.php index b4bcd69..546d950 100644 --- a/app/Http/Controllers/SignInController.php +++ b/app/Http/Controllers/SignInController.php @@ -12,6 +12,6 @@ class SignInController extends CubistFrontController { public function view(Request $request) { - return view('pages.signin'); + return view('pages.sign_in'); } } diff --git a/app/Http/Middleware/RedirectClientIfAuthenticated.php b/app/Http/Middleware/RedirectClientIfAuthenticated.php index ff7ca77..fb9e042 100644 --- a/app/Http/Middleware/RedirectClientIfAuthenticated.php +++ b/app/Http/Middleware/RedirectClientIfAuthenticated.php @@ -16,11 +16,11 @@ class RedirectClientIfAuthenticated */ 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'); } diff --git a/app/Models/Client.php b/app/Models/Client.php index 084e1af..d22cb1d 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -24,7 +24,7 @@ class Client extends CubistMagicAbstractModel $this->addField(['name' => 'password', 'label' => 'Password', - 'type' => 'Text']); + 'type' => 'Hidden']); $this->addField(['name' => 'lastname', 'label' => 'Nom', @@ -70,7 +70,8 @@ class Client extends CubistMagicAbstractModel 'type' => 'BunchOfFieldsMultiple', 'bunch' => 'App\SubForms\Address', 'column' => true, - 'tab' => 'Informations client' + 'tab' => 'Informations client', + 'edit_label' => 'Éditer « %city »' ]); $this->addField(['name' => 'status', diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a8fd24b..b5cf465 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -57,7 +57,8 @@ class AppServiceProvider extends ServiceProvider BladeX::component('components.cart-add')->tag('cart-add'); // ... BladeX::component('components.news-grid'); // ... BladeX::component('components.news-item'); // ... - BladeX::component('components.address-form'); // ... + BladeX::component('components.address-form'); // ... + BladeX::component('components.modal-confirm'); // ... } catch (\Exception $e) { } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 5ea48d3..f6a9e36 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -38,7 +38,6 @@ class RouteServiceProvider extends ServiceProvider $this->mapApiRoutes(); $this->mapWebRoutes(); - // } diff --git a/app/SubForms/Address.php b/app/SubForms/Address.php index 38deba3..24c6d1b 100644 --- a/app/SubForms/Address.php +++ b/app/SubForms/Address.php @@ -9,66 +9,51 @@ class Address extends SubForm { { 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', ]); } diff --git a/resources/js/app.js b/resources/js/app.js index 3dc5338..2fd2d3a 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -60,13 +60,17 @@ const app = new Vue({ 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: {}, @@ -100,10 +104,6 @@ const app = new Vue({ }); }, - 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. @@ -160,20 +160,19 @@ const app = new Vue({ 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, @@ -193,6 +192,29 @@ const app = new Vue({ 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'), @@ -216,15 +238,15 @@ const app = new Vue({ } }) .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() @@ -234,62 +256,61 @@ const app = new Vue({ 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, @@ -300,11 +321,11 @@ const app = new Vue({ .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){ @@ -316,10 +337,10 @@ const app = new Vue({ .then(function (response) { // root.removeErrors() - root.validateRegister = true + root.validateForm = true }) .catch(function (error) { - + root.errorHandling(error, root) }) }, deleteAddress(index, form){ @@ -349,9 +370,27 @@ const app = new Vue({ }) } + }, + 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) + }, + } } - }); @@ -371,6 +410,15 @@ document.addEventListener('DOMContentLoaded', function () { } }); +/** + * 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}); diff --git a/resources/styles/components/modal-confirm.styl b/resources/styles/components/modal-confirm.styl index 58fae71..917a523 100644 --- a/resources/styles/components/modal-confirm.styl +++ b/resources/styles/components/modal-confirm.styl @@ -7,8 +7,9 @@ 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 diff --git a/resources/styles/components/my-account.styl b/resources/styles/components/my-account.styl index f723dd0..f2d424c 100644 --- a/resources/styles/components/my-account.styl +++ b/resources/styles/components/my-account.styl @@ -44,7 +44,7 @@ &.label-checkbox display: flex !important - [type="checkbox"] + [type="radio"] width: 16px !important height: 24px margin: 0 diff --git a/resources/styles/components/signin.styl b/resources/styles/components/signin.styl index d5e55cd..117a698 100644 --- a/resources/styles/components/signin.styl +++ b/resources/styles/components/signin.styl @@ -43,7 +43,7 @@ .line-up border-top: 1px solid #D5D7DF -[class*="-form-errors"] +[class*="form-errors"] padding: 20px background: rgba(248,30,96,.21) li diff --git a/resources/views/components/address-form.blade.php b/resources/views/components/address-form.blade.php index 0eda804..07633ab 100644 --- a/resources/views/components/address-form.blade.php +++ b/resources/views/components/address-form.blade.php @@ -1,4 +1,11 @@
+
+
    +
  • + @{{ errorName[0] }} +
  • +
+
@@ -56,4 +63,3 @@ Supprimer cette adresse - diff --git a/resources/views/components/modal-confirm.blade.php b/resources/views/components/modal-confirm.blade.php new file mode 100644 index 0000000..8517ca5 --- /dev/null +++ b/resources/views/components/modal-confirm.blade.php @@ -0,0 +1,8 @@ + diff --git a/resources/views/pages/my_account.blade.php b/resources/views/pages/my_account.blade.php index e8cb493..55b070c 100644 --- a/resources/views/pages/my_account.blade.php +++ b/resources/views/pages/my_account.blade.php @@ -29,6 +29,13 @@

{{ __('Mes coordonnées') }}

+
+
    +
  • + @{{ errorName[0] }} +
  • +
+