Vijayakrishnan Krishnan 4 роки тому
батько
коміт
606fcdcbda

+ 1 - 0
.idea/stagfe.iml

@@ -5,6 +5,7 @@
       <sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" packagePrefix="App\" />
       <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Tests\" />
+      <excludeFolder url="file://$MODULE_DIR$/bootstrap/cache" />
       <excludeFolder url="file://$MODULE_DIR$/storage" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/asm89/stack-cors" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/brick/math" />

+ 35 - 21
app/Http/Controllers/GuestController.php

@@ -2,39 +2,53 @@
 
 namespace App\Http\Controllers;
 
+use App\Lib\Backend;
 use App\Models\Meeting;
 use App\Models\MeetingParticipant;
 use Illuminate\Http\Request;
 use App\Models\Pro;
+use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\DB;
 
 class GuestController extends Controller
 {
 
-    // old meeting
-    /*
-    public function meeting(Request $request, $meetingID, $participantID) {
-        $meeting = Meeting::where('uid', $meetingID)->first();
-        if(!$meeting) {
-            return abort(404, "Meeting no longer active");
-        }
-        $participants = MeetingParticipant::where('meeting_id', $meeting->id)->get();
-        foreach ($participants as $participant) {
-            $participant->proName = $participant->proName(); // eager-fill proName
-        }
-        return view('meeting', [
-            'meetingID' => $meetingID,
-            'participantID'=> $participantID,
-            'participants' => $participants,
-            'guest' => true
-        ]);
-    }
-    */
-
     public function join(Request $request) {
         return view('join');
     }
 
+    public function processJoin(Request $request) {
+
+        $api = new Backend();
+
+        try {
+
+            $apiResponse = $api->post('client/createAsGuest', [
+                'nameFirst' => $request->post('nameFirst'),
+                'nameLast' => $request->post('nameLast'),
+                'dob' => $request->post('dob'),
+                'medicareNumber' => $request->post('medicareNumber'),
+                'cellNumber' => $request->post('cellNumber'),
+                'emailAddress' => $request->post('emailAddress'),
+            ]);
+
+            $data = json_decode($apiResponse->getContents());
+
+            if (!property_exists($data, 'success') || !$data->success) {
+                return back()->with('message', $data->message)
+                    ->withInput($request->input());
+            }
+
+            Cookie::queue('sessionKey', $data->data->sessionKey);
+            Cookie::queue('clientUid', $data->data->clientUid);
+
+            return redirect('/client/dashboard');
+
+        } catch (\Exception $e) {
+            return redirect()->back()->with('message', $e->getMessage());
+        }
+    }
+
     public function checkin(Request $request) {
         return view('checkin');
     }
@@ -46,7 +60,7 @@ class GuestController extends Controller
     }
 
     public function dashboard(Request $request) {
-        $clientUid = $_COOKIE['clientUid'];
+        $clientUid = $request->cookie('clientUid');
         $client = DB::table('client')->where('uid', $clientUid)->first();
         return view('client-dashboard', [
             "client" => $client

+ 1 - 1
app/Http/Middleware/EnsureValidClientSession.php

@@ -39,6 +39,6 @@ class EnsureValidClientSession
     }
 
     private function redirectToLogIn(){
-        return redirect("/client/checkin");
+        return redirect("/join");
     }
 }

+ 61 - 0
app/Lib/Backend.php

@@ -0,0 +1,61 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: tatu
+ * Date: 6/22/20
+ * Time: 9:58 PM
+ */
+
+namespace App\Lib;
+
+
+use GuzzleHttp\Client as Guzzle;
+use Psr\Http\Message\StreamInterface;
+use GuzzleHttp\Exception\ClientException;
+
+
+class Backend
+{
+    protected $url;
+
+    public function __construct()
+    {
+        $this->url = env('BACKEND_URL', "http://localhost:8080/api");
+    }
+
+
+    public function post(string $url, array $data)
+    {
+        return $this->sendRequest($url, 'POST', ['form_params' => $data]);
+    }
+
+    public function get(string $url,  array $data = [])
+    {
+        return $this->sendRequest($url, 'GET', $data);
+    }
+
+
+    /**
+     * @param string $url
+     * @param string $method HTTP request method eg POST, GET.
+     * @param array $options
+     * @return StreamInterface
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function sendRequest(string $url, string $method,  array $options = []) : StreamInterface
+    {
+        $url = sprintf('%s/%s', rtrim($this->url, '/'), trim($url, '/'));
+
+        $response = null;
+        $client = new Guzzle();
+
+        try {
+            $response = $client->request($method, $url, $options);
+        }
+        catch (ClientException $clientException)  {
+            $response = $clientException->getResponse();
+        }
+
+        return $response->getBody();
+    }
+}

+ 1 - 1
resources/views/client-dashboard.blade.php

@@ -446,7 +446,7 @@
                         // log out
                         $.get("/api/session/logOut", function(_data) {
                             console.log(_data);
-                            window.location = '/client/checkin';
+                            window.location = '/join';
                         })
                     });
 

+ 7 - 49
resources/views/join.blade.php

@@ -1,9 +1,8 @@
 @extends('layouts.join')
 @section('content')
-    <form action=""
+    <form action="/join"
           method="post"
-          enctype="multipart/form-data"
-          onsubmit="return joinMeeting(this)">
+          enctype="multipart/form-data">
         @csrf
 
         <p class="login-box-msg">Welcome! Please check in.</p>
@@ -13,61 +12,20 @@
         @endif
 
         <div class="form-group mb-3">
-            <input type="text" name="nameFirst" class="form-control" placeholder="First Name" required>
+            <input type="text" name="nameFirst" class="form-control" placeholder="First Name" value="{{ request()->old('nameFirst') }}">
         </div>
         <div class="form-group mb-3">
-            <input type="text" name="nameLast" class="form-control" placeholder="Last Name" required>
+            <input type="text" name="nameLast" class="form-control" placeholder="Last Name" value="{{ request()->old('nameLast') }}">
         </div>
         <div class="form-group mb-3">
-            <input type="date" name="dob" class="form-control" placeholder="Date of Birth" required>
+            <input type="date" name="dob" class="form-control" placeholder="Date of Birth" value="{{ request()->old('dob') }}">
         </div>
         <div class="form-group mb-3">
-            <input type="text" name="medicareNumber" class="form-control" placeholder="Medicare Number" required>
+            <input type="text" name="medicareNumber" class="form-control" placeholder="Medicare Number" value="{{ request()->old('medicareNumber') }}">
         </div>
         <div class="form-group mb-3">
-            <input type="tel" name="cellNumber" class="form-control" placeholder="Cell Number">
-        </div>
-        <div class="form-group mb-3">
-            <input type="email" name="emailAddress" class="form-control" placeholder="Email Address">
+            <input type="tel" name="phoneNumber" class="form-control" placeholder="Phone Number" value="{{ request()->old('phoneNumber') }}">
         </div>
         <button type="submit" class="btn btn-primary btn-block mx-auto w-50 mt-4 mb-2">Check In</button>
     </form>
-    <script>
-        function joinMeeting(_form) {
-            $.ajax({
-                type: 'post',
-                url: '/api/client/createAsGuest',
-                data: $(_form).serialize(),
-                dataType: 'json'
-            })
-            .done(function (_data) {
-                console.log(_data);
-                if(_data.success) {
-                    Cookies.set('sessionKey', _data.data.sessionKey, {expires: 365});
-                    Cookies.set('clientUid', _data.data.clientUid, {expires: 365});
-                    window.location = '/client/dashboard';
-                }
-                else {
-                    new Noty({
-                        theme: 'mint',
-                        type: 'error',
-                        text: _data.message,
-                        progressBar: false,
-                        timeout: false,
-                    }).show();
-                }
-            })
-            .fail(function (_data) {
-                console.log(_data);
-                new Noty({
-                    theme: 'mint',
-                    type: 'error',
-                    text: _data.message,
-                    progressBar: false,
-                    timeout: false,
-                }).show();
-            });
-            return false;
-        }
-    </script>
 @endsection

+ 1 - 0
routes/web.php

@@ -33,6 +33,7 @@ Route::get('/meeting/{meetingID}/{participantID}', 'GuestController@meeting');
 
 Route::middleware('ensureNoValidClientSession')->group(function() {
     Route::get('/join', 'GuestController@join');
+    Route::post('/join', 'GuestController@processJoin');
     Route::get('/client/checkin', 'GuestController@checkin');
 });