|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Models\Quiz; |
|
7
|
|
|
|
|
8
|
|
|
class QuizController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
public function showIndexWelcome() |
|
11
|
|
|
{ |
|
12
|
|
|
return view('index.welcome'); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function showHostDashboard() |
|
16
|
|
|
{ |
|
17
|
|
|
return view('quiz_host.dashboard.index'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function showQuestion() |
|
21
|
|
|
{ |
|
22
|
|
|
return view('quiz_user.question'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function showPin() |
|
26
|
|
|
{ |
|
27
|
|
|
return view('quiz_user.pin'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function showSplash() |
|
31
|
|
|
{ |
|
32
|
|
|
return view('quiz_user.splash'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function enterQuizPin(Request $request) |
|
36
|
|
|
{ |
|
37
|
|
|
// @TODO - PIN max length needs to be dynamic with trait |
|
38
|
|
|
// will sort out soon - Matt. |
|
39
|
|
|
$validatedData = $request->validate([ |
|
|
|
|
|
|
40
|
|
|
'username' => 'required|string', |
|
41
|
|
|
'pin' => 'required|string' |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
// if (Quiz::where('quiz_pin', $request->get('pin'))->where('active', 1)->get()->isEmpty()) { |
|
|
|
|
|
|
45
|
|
|
// return back()->with('errors', 'The quiz PIN does not exist'); |
|
|
|
|
|
|
46
|
|
|
// } else { |
|
|
|
|
|
|
47
|
|
|
// return back()->with('success', 'Whoa, the quiz exists'); |
|
|
|
|
|
|
48
|
|
|
// } |
|
49
|
|
|
|
|
50
|
|
|
// FIX XSS HERE ALSO |
|
51
|
|
|
$quiz = Quiz::where('quiz_pin', $request->get('pin')) |
|
52
|
|
|
->where('active', 1) |
|
53
|
|
|
->first(); |
|
54
|
|
|
|
|
55
|
|
|
if (!$quiz->exists()) { |
|
56
|
|
|
return back()->with('pin_error', 'Either the quiz doesn\'t exits, or it hasn\'t been activated'); |
|
57
|
|
|
} else { |
|
58
|
|
|
//return back()->with('success', 'The quiz ' . $quiz->quiz_name . ' exits and is ready to play.'); |
|
|
|
|
|
|
59
|
|
|
return redirect()->route('quiz_user.showSplash'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|