Passed
Branch feature/testserver (9727dc)
by Pieter van der
08:04
created

TestServerView::StartEnrollment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
@license New BSD License - See LICENSE file for details.
5
@copyright (C) 2022 SURF BV
6
*/
7
8
namespace TestServer;
9
10
class TestServerView
11
{
12
    public function ShowRoot($args = array()) : void {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

12
    public function ShowRoot(/** @scrutinizer ignore-unused */ $args = array()) : void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
        $this->begin();
14
        echo <<<HTML
15
<h1>Tiqr Test Server</h1>
16
<a href="/start-enrollment">Enroll new user</a><br /><br />
17
<a href="/start-authenticate">Authenticate user</a><br /><br />
18
<a href="/list-users">list users</a><br /><br />
19
HTML;
20
        $this->end();
21
    }
22
23
    public function ListUsers($users) {
24
        $this->begin();
25
        echo <<<HTML
26
<h1>List of users</h1>
27
<p>This is the list of user IDs that are registered on this server. Click a user ID to start an authentication for that user.</p>
28
<table border="1">
29
<tr>
30
    <th>userId</th>    
31
    <th>displayName (version | User-Agent)</th>
32
    <th>notificationType</th>
33
    <th>notificationAddress</th>
34
    <th>secret</th>
35
</tr>
36
HTML;
37
        foreach ($users as $user) {
38
            $user['userId'] = $user['userId'] ?? '—';
39
            $user['displayName'] = $user['displayName'] ?? '—';
40
            $user['notificationType'] = $user['notificationType'] ?? '—';
41
            $user['notificationAddress'] = $user['notificationAddress'] ?? '—';
42
            $user['secret'] = $user['secret'] ?? '—';
43
            echo <<<HTML
44
<tr>
45
    <td><a href="/start-authenticate?user_id=${user['userId']}"><code>${user['userId']}</code></a></td>
46
    <td><code>${user['displayName']}</code></td>
47
    <td><code>${user['notificationType']}</code></td>
48
    <td><code>${user['notificationAddress']}</code></td>
49
    <td><code>${user['secret']}</code></td>
50
</tr>
51
HTML;
52
        }
53
        echo "</table>";
54
        $this->end();
55
    }
56
57
    public function StartEnrollment($enroll_string, $image_url) : void {
58
        $this->begin();
59
        echo <<<HTML
60
<h1>Enroll a new user</h1>
61
<p>Scan the QR code below using the Tiqr app. When using the smart phone's browser you can tap on the QR code to open the link it contains.</p>
62
<p>You can use this QR code only once.</p>
63
<a href="$enroll_string"><img src="$image_url" /></a> <br />
64
<br />
65
<code>$enroll_string</code>
66
<br />
67
<br />
68
<a href="/start-enrollment">Refresh enrollemnt QR code</a><br />
69
HTML;
70
        $this->end();
71
    }
72
73
    private function begin() {
74
        echo <<<HTML
75
<!doctype html>
76
<html lang=en>
77
<head>
78
<meta charset=utf-8>
79
<meta name="viewport" content="width=device-width, initial-scale=1">
80
<title>TiqrTestServer</title>
81
</head>
82
<body>
83
HTML;
84
    }
85
86
    private function end() {
87
        echo <<<HTML
88
<br />
89
<a href="/">Home</a><br />
90
</body>
91
</html>
92
HTML;
93
    }
94
95
    public function StartAuthenticate(string $authentication_URL, string $image_url, string $user_id, string $response)
96
    {
97
        $refreshurl = '/start-authenticate';
98
        if (strlen($user_id) > 0) {
99
            $refreshurl.= "?user_id=$user_id";
100
        }
101
        $this->begin();
102
        echo <<<HTML
103
        <h1>Authenticate user $user_id</h1>
104
<p>Scan the QR code below using the Tiqr app. When using the smart phone's browser you can tap on the QR code to open the link it contains.</p>
105
<a href="$authentication_URL"><img src="$image_url" /></a> <br />
106
<br />
107
<code>$authentication_URL</code>
108
<br />
109
HTML;
110
        if (strlen($response)>0) {
111
            echo <<<HTML
112
<p>The response (for offline validation) is: <code>$response</code></p>
113
HTML;
114
115
        }
116
        echo <<<HTML
117
<br />
118
<a href="$refreshurl">Refresh authentication QR code</a><br />
119
HTML;
120
        $this->end();
121
    }
122
}