]> _ Git - pmi.git/commitdiff
wip #5789 7:00
authorsoufiane <soufiane@cubedesigners.com>
Wed, 15 Mar 2023 19:24:36 +0000 (20:24 +0100)
committersoufiane <soufiane@cubedesigners.com>
Wed, 15 Mar 2023 19:24:36 +0000 (20:24 +0100)
app/Http/Controllers/AjaxController.php
app/Http/Controllers/ClientController.php [new file with mode: 0644]
app/Http/Controllers/SignInController.php [new file with mode: 0644]
app/Models/BackpackClient.php [new file with mode: 0644]
config/auth.php
resources/js/app.js
resources/styles/components/modal-confirm.styl [new file with mode: 0644]
resources/styles/components/signin.styl
resources/views/pages/sign_in.blade.php
resources/views/partials/header.blade.php
resources/views/partials/modal-confirm.blade.php [new file with mode: 0644]

index 6ed4311487d1bfcd3dba2b68527629f49d3d7ea9..6372628e12f90242737cf6c4a6b6bd7e734dc61c 100644 (file)
@@ -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 (file)
index 0000000..3678462
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use App\Models\BackpackClient;
+use Illuminate\Support\Facades\Auth;
+use Cubist\Backpack\app\Http\Controllers\CubistFrontController;
+
+class ClientController extends CubistFrontController
+{
+    public function view(Request $request) {
+        return $request->user();
+    }
+}
diff --git a/app/Http/Controllers/SignInController.php b/app/Http/Controllers/SignInController.php
new file mode 100644 (file)
index 0000000..627c536
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+
+namespace App\Http\Controllers;
+
+//use App\Models\Product;
+use App\Models\ProductType;
+use Cubist\Backpack\app\Http\Controllers\CubistFrontController;
+use Illuminate\Http\Request;
+
+class SignInController extends CubistFrontController
+{
+    public function view(Request $request, $id)
+    {
+        return view('pages.signin');
+    }
+}
diff --git a/app/Models/BackpackClient.php b/app/Models/BackpackClient.php
new file mode 100644 (file)
index 0000000..1d29377
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+namespace App\Models;
+
+use App\User;
+use Backpack\Base\app\Models\Traits\InheritsRelationsFromParentModel;
+use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification;
+
+class BackpackClient extends User
+{
+    use InheritsRelationsFromParentModel;
+
+    protected $table = 'clients';
+}
index 8d5b185058c9aea56b31cac031aaec849a558cd1..86aae4279021d19258b09f5c8c3ac2eb8d55a1c0 100644 (file)
@@ -41,6 +41,11 @@ return [
             'provider' => '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',
index 251b5c5ed83a229bc691876b6907a1d942ff9f61..d44a1b9dac1dd5778eab5bbb02862e6351f744b3 100644 (file)
@@ -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 (file)
index 0000000..58fae71
--- /dev/null
@@ -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
index 78527498f8b35472571c4288553d9f8304f62275..5c6e1f31a6003b5339d753a8183a327ed5707bf4 100644 (file)
@@ -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
index 05795ef326bb60b27759f8257a5f2a9df2a67adb..8b9591b5c05ea98d8d813d63dbd39233adf7f34c 100644 (file)
                 </form>
             </div>
         </div>
-        <div class="signin-form" v-if="emailExist">
+        <div class="signin-form hidden" :ref="(signin) => signin.classList.remove('hidden')" v-if="emailExist">
             <div class="ajax-form flex flex-col max-w-half">
                 <div class="form-info text-navy mb-10">
                     <h1 class="text-4xl m-0">Se connecter</h1>
                 </div>
-                <form class="form-portal">
+                <form id="signin-form" class="form-portal" @submit.prevent="signin">
                     @csrf
                     <div class="form-group mb-6">
                         <label class="form-input text-navy">
                             <span class="form-required-legend inline-block my-4 mr-3 text-grey-dark xs:self-start xs:mt-5">
                                 *{{ __('Champs obligatoires')}}
                             </span>
-                        <button id="checkemail" class="form-submit-button btn btn-custom xs:w-full" @click.prevent="signin">
+                        <button id="checkemail" class="form-submit-button btn btn-custom xs:w-full">
                             {{ __('Connexion') }}
                         </button>
                     </div>
                 </form>
             </div>
         </div>
-        <div class="signup-form" v-if="!emailExist && validateEmail">
+        <div class="signup-form hidden" :ref="(signup) => signup.classList.remove('hidden')" v-if="!emailExist && validateEmail">
             <div class="ajax-form flex flex-col max-w-half">
                 <div class="form-info text-navy mb-10">
                     <h1 class="text-4xl m-0">Créer un compte</h1>
             </div>
         </div>
     </div>
+    @include('partials.modal-confirm')
 @endsection
index 5886798622f0af45aba14c453f82a8d1086f2912..c92e6376182599e96ec68e81a43e27faff62d33c 100644 (file)
         </nav>
 
         @php
-            //var_dump($nav);
+            var_dump(Auth::user());
         @endphp
 
+        @guest
         <a href="{{ $nav->getHrefByName('signin') }}"
-           class="text-right flex items-center cursor-pointer text-white hover:text-primary">
+           class="text-right flex items-center cursor-pointer text-white hover:text-primary"
+        >
             @include('partials.account')
         </a>
+        @endguest
 
         @if (config('features.quote'))
             <a href="{{ $nav->getHrefByName('cart') }}"
diff --git a/resources/views/partials/modal-confirm.blade.php b/resources/views/partials/modal-confirm.blade.php
new file mode 100644 (file)
index 0000000..0f404a3
--- /dev/null
@@ -0,0 +1,9 @@
+<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>