Completed
Push — master ( 45d072...34f708 )
by Matt
11:07
created

QuizController::enterQuizPin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
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([
0 ignored issues
show
Unused Code introduced by
The assignment to $validatedData is dead and can be removed.
Loading history...
40
            'pin'      => 'required|string'
41
        ]);
42
43
        // FIX XSS HERE ALSO
44
        $quiz = Quiz::where('quiz_pin', $request->get('pin'))
45
                    ->where('active', 1)
46
                    ->first();
47
48
        if (!$quiz->exists()) {
49
            return back()->with('pin_error', 'Either the quiz doesn\'t exist, or it hasn\'t been activated');
50
        } else {
51
            //Add user to the socket.io stuff!
52
            event(new \App\Events\addUser($request->get('username'))); //Adds the user to the socket stuff
53
            return redirect()->route('quiz_user.showSplash')->with('quizData', $quiz);
54
        }
55
    }
56
}
57