瀏覽代碼

Update ParentalControlsController, redirect to new custom error page on active session when attempting to use child invite link so as to not overwrite parent active session with child session

Daniel Supernault 1 年之前
父節點
當前提交
319a20b473
共有 2 個文件被更改,包括 23 次插入0 次删除
  1. 13 0
      app/Http/Controllers/ParentalControlsController.php
  2. 10 0
      resources/views/errors/custom.blade.php

+ 13 - 0
app/Http/Controllers/ParentalControlsController.php

@@ -87,7 +87,14 @@ class ParentalControlsController extends Controller
 
     public function inviteRegister(Request $request, $id, $code)
     {
+        if($request->user()) {
+            $title = 'You cannot complete this action on this device.';
+            $body = 'Please log out or use a different device or browser to complete the invitation registration.';
+            return view('errors.custom', compact('title', 'body'));
+        }
+
         $this->authPreflight($request, true, false);
+
         $pc = ParentalControls::whereRaw('verify_code = BINARY ?', $code)->whereNull(['email_verified_at', 'child_id'])->findOrFail($id);
         abort_unless(User::whereId($pc->parent_id)->exists(), 404);
         return view('settings.parental-controls.invite-register-form', compact('pc'));
@@ -95,6 +102,12 @@ class ParentalControlsController extends Controller
 
     public function inviteRegisterStore(Request $request, $id, $code)
     {
+        if($request->user()) {
+            $title = 'You cannot complete this action on this device.';
+            $body = 'Please log out or use a different device or browser to complete the invitation registration.';
+            return view('errors.custom', compact('title', 'body'));
+        }
+
         $this->authPreflight($request, true, false);
 
         $pc = ParentalControls::whereRaw('verify_code = BINARY ?', $code)->whereNull('email_verified_at')->findOrFail($id);

+ 10 - 0
resources/views/errors/custom.blade.php

@@ -0,0 +1,10 @@
+@extends('layouts.app')
+
+@section('content')
+<div class="container">
+  <div class="error-page py-5 my-5 text-center">
+    <h3 class="font-weight-bold">{!! $title ?? config('instance.page.404.header')!!}</h3>
+    <p class="lead">{!! $body ?? config('instance.page.404.body')!!}</p>
+  </div>
+</div>
+@endsection