Browse Source

Added new middleware to check session.
Added passing lobby pros.
Added checking accessing lobby and activity of meeting.

Kain_Stropov 5 years ago
parent
commit
e9704f417c

+ 2 - 2
app/Http/Controllers/ClientController.php

@@ -50,7 +50,7 @@ class ClientController extends Controller
 	}
 
 	public function entranceLobby(Request $request, Lobby $lobby) {
-        if (!$lobby->id) {
+        if (!$lobby->id || !$lobby->is_stranger_accessible) {
             \abort(404);
             return;
         }
@@ -84,7 +84,7 @@ class ClientController extends Controller
         // }
         $session = AppSession::where("session_key",$sessionKey)->first();
         $meeting = null;
-        if ($session->meetingParticipant && $session->meetingParticipant->meeting->lobby_id === $lobby->id) {
+        if ($session->meetingParticipant && $session->meetingParticipant->meeting->lobby_id === $lobby->id && $session->meetingParticipant->meeting->is_active) {
             $meeting = new MeetingModel($session->meetingParticipant->meeting);
         }
         return view('client/index',compact('lobbyModel','meeting','sessionKey'));

+ 1 - 1
app/Http/Controllers/MeetingCenterController.php

@@ -24,7 +24,7 @@ class MeetingCenterController extends Controller
         $appSession = AppSession::where("session_key",$sessionKey)->first();
         $user = new ProModel($appSession->pro);
         $meeting = null;
-        if ($appSession->is_currently_meeting_participant) {
+        if ($appSession->is_currently_meeting_participant && $appSession->meetingParticipant->meeting->is_active) {
             $meeting = new MeetingWithLobbyModel($appSession->meetingParticipant->meeting);
         }
 

+ 5 - 1
app/Http/Kernel.php

@@ -66,5 +66,9 @@ class Kernel extends HttpKernel
 
         'ensureValidSession' => \App\Http\Middleware\EnsureValidSession::class,
         'ensureNoValidSession' => \App\Http\Middleware\EnsureNoValidSession::class,
+
+        'ensureValidProSession' => \App\Http\Middleware\EnsureValidProSession::class,
+        'ensureNoValidProSession' => \App\Http\Middleware\EnsureNoValidProSession::class,
+        'ensureOnlyStrangerSession' => \App\Http\Middleware\EnsureOnlyStrangerSession::class,
     ];
-}
+}

+ 43 - 0
app/Http/Middleware/EnsureNoValidProSession.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use App\Models\AppSession;
+
+class EnsureNoValidProSession
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        //if not valid session, redirect to /pro/request-sms-login-token
+        $sessionKey = $request->cookie("sessionKey");
+
+        if(!$sessionKey){
+            return $next($request);
+        }
+
+        $appSession = AppSession::where("session_key",$sessionKey)->first();
+
+        if(!$appSession){
+            return $next($request);
+        }
+
+        if(!$appSession->is_active){
+            return $next($request);
+        }
+
+        if ($appSession->session_type !== 'PRO') {
+            return $next($request);
+        }
+
+        return redirect("/mc/dashboard");
+
+    }
+}

+ 46 - 0
app/Http/Middleware/EnsureOnlyStrangerSession.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use App\Models\AppSession;
+
+class EnsureOnlyStrangerSession
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        //if not valid session, redirect to /pro/request-sms-login-token
+        $sessionKey = $request->cookie("sessionKey");
+
+        if(!$sessionKey){
+            return $next($request);
+        }
+
+        $appSession = AppSession::where("session_key",$sessionKey)->first();
+
+        if(!$appSession){
+            return $next($request);
+        }
+
+        if(!$appSession->is_active){
+            return $next($request);
+        }
+
+        if ($appSession->session_type === 'STRANGER') {
+            return $next($request);
+        }
+
+        if ($appSession->session_type === 'PRO')
+            return redirect("/mc/dashboard");
+        else
+            return redirect("/");
+
+    }
+}

+ 44 - 0
app/Http/Middleware/EnsureValidProSession.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+
+use App\Models\AppSession;
+
+class EnsureValidProSession
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+
+        //if not valid session, redirect to /pro/request-sms-login-token
+        $sessionKey = $request->cookie("sessionKey");
+
+        $appSession = AppSession::where("session_key",$sessionKey)->first();
+
+        if(!$appSession){
+            return $this->redirectToLogIn();
+        }
+
+        if(!$appSession->is_active){
+            return $this->redirectToLogIn();
+        }
+
+        if ($appSession->session_type !== 'PRO') {
+            return $this->redirectToLogIn();
+        }
+
+        return $next($request);
+    }
+
+    private function redirectToLogIn(){
+        return redirect("/");
+    }
+}

+ 4 - 0
app/HttpModels/ClientLobbyModel.php

@@ -6,10 +6,14 @@ use App\Models\Lobby;
 class ClientLobbyModel {
     public $uid;
     public $name;
+    public $pros = [];
 
     public function __construct(Lobby $lobby)
     {
         $this->uid = $lobby->uid;
         $this->name = $lobby->name;
+        foreach ($lobby->pros as $pro) {
+            $this->pros[] = new LobbyProModel($pro);
+        }
     }
 }

+ 15 - 0
app/HttpModels/LobbyProModel.php

@@ -0,0 +1,15 @@
+<?php
+namespace App\HttpModels;
+
+use App\Models\Pro;
+
+class LobbyProModel {
+    public $uid;
+    public $name;
+
+    public function __construct(Pro $pro)
+    {
+        $this->uid = $pro->uid;
+        $this->name = $pro->name_display;
+    }
+}

+ 5 - 0
app/Models/Lobby.php

@@ -13,4 +13,9 @@ class Lobby extends Model
     {
         return $this->hasMany(Meeting::class);
     }
+
+    public function pros()
+    {
+        return $this->belongsToMany(Pro::class, 'lobby_pro');
+    }
 }

+ 25 - 19
resources/js/components/pages/ClientEntrance.vue

@@ -40,8 +40,8 @@
 
                                 <div class="form-group mt-5 mb-3">
                                     <select class="form-control custom-select" v-model="user.targetLobbyProUid" name="targetLobbyProUid">
-                                        <option value="">Do you wish to speak with particular Doctor?</option>
-                                        <option v-for="pro in prosList" :value="pro.uid" :key="pro.uid">{{pro.name}} - {{pro.type}}</option>
+                                        <option value>Do you wish to speak with particular Doctor?</option>
+                                        <option v-for="pro in prosList" :value="pro.uid" :key="pro.uid">{{pro.name}}</option>
                                     </select>
                                 </div>
                             </form>
@@ -128,7 +128,11 @@ export default {
     props: {
         lobbyProp: {
             type: Object,
-            required: true
+            default: {
+                uid: null,
+                name: "Base",
+                pros: []
+            }
         },
         meetingProp: {
             type: Object
@@ -139,13 +143,13 @@ export default {
         }
     },
     computed: {
-        prosList(){
-            return [{
-                name: 'Test',
-                type: 'Cardiologist',
-                uid: 'someuid'
-            }]
-        }
+        // prosList(){
+        //     return [{
+        //         name: 'Test',
+        //         type: 'Cardiologist',
+        //         uid: 'someuid'
+        //     }]
+        // }
     },
     data() {
         return {
@@ -178,7 +182,8 @@ export default {
             maxRows: 4,
             rowHeight: 240,
             gridPadding: 8,
-            loadingInProgress: false
+            loadingInProgress: false,
+            prosList: []
         };
     },
     sockets: {},
@@ -664,7 +669,7 @@ export default {
         }
     },
     mounted() {
-        console.log(this.lobbyProp)
+        console.log(this.lobbyProp);
         if (this.meetingProp) {
             this.meetingUid = this.meetingProp.uid;
             this.$nextTick(this.initializePublisher);
@@ -672,8 +677,8 @@ export default {
         }
 
         this.sockets.subscribe("meeting-closed", data => {
-            this.$eventBus.$emit("leaveMeeting")
-        })
+            this.$eventBus.$emit("leaveMeeting");
+        });
 
         let self = this;
 
@@ -703,14 +708,15 @@ export default {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                 },
                 error: jXhr => {
-                    console.error(getSingleError(jXhr))
+                    console.error(getSingleError(jXhr));
                 }
             });
-            this.$store.dispatch("leaveMeeting")
-            this.$socket.emit('meetingLeft')
-            this.disconnect()
-            alert('Meeting was Closed.')
+            this.$store.dispatch("leaveMeeting");
+            this.$socket.emit("meetingLeft");
+            this.disconnect();
+            alert("Meeting was Closed.");
         });
+        this.prosList.push(...this.lobbyProp.pros);
     }
 };
 </script>

+ 6 - 3
routes/web.php

@@ -31,7 +31,7 @@ Route::get('/join/{meetingID}', function () {
 Route::get('/meeting/{meetingID}/{participantID}', 'GuestController@meeting');
 */
 
-Route::middleware('ensureNoValidSession')->group(function(){
+Route::middleware('ensureNoValidProSession')->group(function(){
     Route::get('/', 'AppSessionController@proRequestSmsLogInToken')->name('pro-request-sms-login-token');
     Route::get('/pro/login', 'AppSessionController@proLogIn')->name('pro-login');
     Route::post('/pro/login', 'AppSessionController@processProLogIn')->name('process-pro-login');
@@ -39,7 +39,7 @@ Route::middleware('ensureNoValidSession')->group(function(){
     Route::get('/client/login', 'AppSessionController@clientLogIn')->name('process-client-login');
 });
 
-Route::middleware('ensureValidSession')->group(function(){
+Route::middleware('ensureValidProSession')->group(function(){
     Route::get('/dashboard', 'ProController@dashboard')->name('pro-dashboard');
 
     // old routes
@@ -63,7 +63,10 @@ Route::post('/post-to-api', 'AppSessionController@postToAPI')->name('post-to-api
 Route::post('/post-to-api-ajax', 'AppSessionController@postToAPIAjax')->name('post-to-api-ajax');
 
 Route::get('/client', 'ClientController@entranceNormal')->name('client-entrance');
-Route::get('/client/{url_slug}', 'ClientController@entranceLobby')->name('client-lobby');
+
+Route::middleware('ensureOnlyStrangerSession')->group(function(){
+    Route::get('/client/{url_slug}', 'ClientController@entranceLobby')->name('client-lobby');
+});
 Route::get('/client/meeting/{meeting_uid}', 'ClientController@entranceLobby')->name('join-meeting');
 
 Route::bind('url_slug', function($value, $route)