From 09e7f778f5cb0b96e8344633b2f829bdfe8e2bda Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 15 Mar 2023 20:24:36 +0100 Subject: [PATCH] wip #5789 7:00 --- app/Http/Controllers/AjaxController.php | 39 +++++++++++-- app/Http/Controllers/ClientController.php | 14 +++++ app/Http/Controllers/SignInController.php | 17 ++++++ app/Models/BackpackClient.php | 13 +++++ config/auth.php | 10 ++++ resources/js/app.js | 58 ++++++++++++------- .../styles/components/modal-confirm.styl | 53 +++++++++++++++++ resources/styles/components/signin.styl | 8 +-- resources/views/pages/sign_in.blade.php | 9 +-- resources/views/partials/header.blade.php | 7 ++- .../views/partials/modal-confirm.blade.php | 9 +++ 11 files changed, 201 insertions(+), 36 deletions(-) create mode 100644 app/Http/Controllers/ClientController.php create mode 100644 app/Http/Controllers/SignInController.php create mode 100644 app/Models/BackpackClient.php create mode 100644 resources/styles/components/modal-confirm.styl create mode 100644 resources/views/partials/modal-confirm.blade.php diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 6ed4311..6372628 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -17,7 +17,9 @@ use Illuminate\Validation\ValidationException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Rules\Password; +use Illuminate\Support\Facades\Hash; +use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Auth; class AjaxController extends CubistFrontController { @@ -290,8 +292,29 @@ class AjaxController extends CubistFrontController return $email; } - public function signin(Request $request) { - $this->check_email_exist($request); + public function signin(Request $request) + { + $validation = [ + 'email' => 'required|email', + 'password' => 'required', + ]; + + $validator = Validator::make($request->all(), $validation); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + + $validator->validate(); + $data = $validator->validated(); + + if (Auth::guard('web-clients')->attempt($data)) { + $request->session()->regenerate(); + + var_dump(Auth::user()); + }else{ + return 'pas ok'; + } } public function signup(Request $request) { @@ -301,15 +324,16 @@ class AjaxController extends CubistFrontController 'password_confirmation' => 'required', 'lastname' => 'required|alpha|max:255', 'firstname' => 'required|alpha|max:255', - 'phone' => 'required|numeric|min:10', + 'phone' => 'required|numeric', 'company' => 'required|string', 'vat' => 'required|alpha_num|min:13', 'siren' => 'required|numeric', 'address.*.address' => 'required|string|max:255', - 'address.*.zipcode' => 'required|numeric|min:5', + 'address.*.zipcode' => 'required|numeric', 'address.*.city' => 'required|string|max:255', 'address.*.billing_address' => 'nullable', - 'address.*.delivery_address' => 'nullable' + 'address.*.delivery_address' => 'nullable', + 'confirm_condition' => 'required' ]; $validator = Validator::make($request->all(), $validation); @@ -320,8 +344,11 @@ class AjaxController extends CubistFrontController $validator->validate(); $data = $validator->validated(); $data['status'] = 0; + $data['password'] = Hash::make($data['password']); $client = new Clients($data); $client->save(); + + return $data; } } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php new file mode 100644 index 0000000..3678462 --- /dev/null +++ b/app/Http/Controllers/ClientController.php @@ -0,0 +1,14 @@ +user(); + } +} diff --git a/app/Http/Controllers/SignInController.php b/app/Http/Controllers/SignInController.php new file mode 100644 index 0000000..627c536 --- /dev/null +++ b/app/Http/Controllers/SignInController.php @@ -0,0 +1,17 @@ + 'users', ], + 'web-clients' => [ + 'driver' => 'session', + 'provider' => 'clients' + ], + 'api' => [ 'driver' => 'token', 'provider' => 'users', @@ -70,6 +75,11 @@ return [ 'model' => App\User::class, ], + 'clients' => [ + 'driver' => 'eloquent', + 'model' => App\Models\BackpackClient::class, + ] + // 'users' => [ // 'driver' => 'database', // 'table' => 'users', diff --git a/resources/js/app.js b/resources/js/app.js index 251b5c5..d44a1b9 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -63,7 +63,7 @@ const app = new Vue({ emailExist: false, validateEmail: false, address_choice: true, - savingUser: false + validateRegister: false }, beforeMount() { @@ -143,10 +143,13 @@ const app = new Vue({ toggleType() { this.type = this.type === "password" ? "text" : "password" }, - showForm(el) { - document.querySelector(el).classList.remove('hidden') + removeErrors() { + let errorMessage = document.querySelectorAll('.form-error') + for (var i = 0; i < errorMessage.length; i++) { + errorMessage[i].remove(); + } }, - checkEmailExist(){ + checkEmailExist() { let root = this, data = { email: root.email_signin @@ -156,24 +159,36 @@ const app = new Vue({ .then(function (response) { //do the verification before to set validateEmail true root.validateEmail = true - if(response.data.length > 0) { + if (response.data.length > 0) { root.emailExist = true } }) .catch(function (error) { - console.log('error',error) + console.log('error', error) }) }, signin() { let root = this, - data = { - email: root.email_signin, - password: root.password_signin - } + form = document.getElementById('signin-form'), + data = new FormData(form) + + console.log(form) axios.post('/ajax/signin', data) .then(function (response) { // + let lastVisitedUrl = document.referrer; + let homeUrl = window.location.origin; + + if(lastVisitedUrl){ + if(lastVisitedUrl.includes('pm-instrumentation')){ + history.back() + }else{ + window.location.replace(homeUrl) + } + }else{ + window.location.replace(homeUrl) + } }) .catch(function (error) { console.log(error) @@ -181,25 +196,28 @@ const app = new Vue({ }, signup() { let root = this, - el = document.getElementById('signup-form'), - data = new FormData(el) + form = document.getElementById('signup-form'), + data = new FormData(form) axios.post('/ajax/signup', data) .then(function (response) { // - this.savingUser = true + root.removeErrors() + form.reset() + + window.scrollTo({ + top: 0, + behavior: "smooth" + }) + root.validateRegister = true }) .catch(function (error) { if (error.response) { let errors = error.response.data.errors - let form = document.querySelector('.form-input') - let errorMessage = document.querySelectorAll('.form-error') - for (var i = 0; i < errorMessage.length; i++) { - errorMessage[i].remove(); - } + root.removeErrors() - for(let k in errors){ - let el = document.querySelector('[name='+k+']') + for (let k in errors) { + let el = document.querySelector('[name=' + k + ']') let span = document.createElement("span") span.classList.add('form-error') span.innerText = errors[k] diff --git a/resources/styles/components/modal-confirm.styl b/resources/styles/components/modal-confirm.styl new file mode 100644 index 0000000..58fae71 --- /dev/null +++ b/resources/styles/components/modal-confirm.styl @@ -0,0 +1,53 @@ +// +.page-signin main + position: relative + +// +.modal-confirm + width: 100% + height: 100vh + padding: 0 25px + z-index: 99 + top: -120px + &-text + width: 100% + max-width: 744px + opacity: 0 + animation-name: opacity, top + animation-duration: .3s, 1s + animation-delay: .6s, .6s + animation-fill-mode: forwards, forwards + z-index: 1 + box-shadow: 0 30px 60px rgba(24,47,76,.2) + font-family: 'Barlow',sans-serif + .mb-4 + margin-bottom: 1rem !important + &-close + top: 24px + right: 24px + &:after + content: "" + width: 100% + height: 100vh + position: fixed + top: 0 + left: 0 + background-color: rgba(21,47,78,.25) + animation-name: opacity + animation-duration: .5s + animation-timing-function: ease-in + animation-fill-mode: forwards + + @keyframes opacity + 0% + opacity: 0 + + 100% + opacity: 1 + + @keyframes top + 0% + top: 62px + + 100% + top: 92px diff --git a/resources/styles/components/signin.styl b/resources/styles/components/signin.styl index 7852749..5c6e1f3 100644 --- a/resources/styles/components/signin.styl +++ b/resources/styles/components/signin.styl @@ -4,20 +4,20 @@ padding: 0 !important [type="checkbox"] width: 16px !important - height: 16px + height: 24px margin: 0 - border: 1px solid #EEF1F7 - border-radius: 2px + border: 0 display: grid place-content: center padding: 0 position: relative - top: 7px &:before content: "" width: 16px height: 16px background-color: #F7F8FC + border: 1px solid #EEF1F7 + border-radius: 2px &:checked:before content: "" border-color: #0EAADA diff --git a/resources/views/pages/sign_in.blade.php b/resources/views/pages/sign_in.blade.php index 05795ef..8b9591b 100644 --- a/resources/views/pages/sign_in.blade.php +++ b/resources/views/pages/sign_in.blade.php @@ -23,12 +23,12 @@ -
+ -