-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
210 lines (186 loc) · 6.49 KB
/
index.php
File metadata and controls
210 lines (186 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
use Comp\Kacky\DB;
use Comp\Kacky\Model\User;
use Comp\GameManager\Message;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
include('vendor/autoload.php');
// prepare Session
$dbConfig = DB::getConfig();
$session = new Session(new NativeSessionStorage([], new PdoSessionHandler(DB::getPDO($dbConfig), ['db_table'=>$dbConfig['session_table']])));
$session->setName($dbConfig['session_name']);
$gameId = $_GET['gid'] ?? 0;
$gameId*=1;
function redirect($url) {
echo "<script>window.location.replace('$url')</script>";
exit();
}
// handle login form submission
if (isset($_POST['login'])) {
header('Content-Type: application/json');
$user = new User(null);
try {
switch($_POST['login']) {
case 'form':
$username = substr($_POST['uname'], 0, 16);
$password = substr($_POST['upass'], 0, 16);
$user->verifyFromDB($username, $password);
break;
case 'facebook':
$user->verifyFacebook($_POST['token']);
break;
case 'google':
$user->verifyGoogle($_POST['token']);
break;
}
$session->set('isLogged', true);
$session->set('username', $user->getName());
$session->set('userId', $user->getId());
echo Message::ok('Logged in');
}
catch (\Exception $e) {
$session->set('isLogged', false);
echo Message::error($e->getMessage());
sleep(3);
}
exit();
}
// handle logout
if (isset($_POST['logout'])) {
$session->clear();
$session->set('isLogged', false);
exit();
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" type="image/png" href="assets/i/duck.png">
<link rel="stylesheet" type="text/css" href="assets/style.css?v=3">
<title>Kačice z našej police</title>
<link rel="stylesheet" href="assets/jquery/jquery-ui.min.css">
<script src="assets/jquery/jquery-2.1.4.min.js"></script>
<script src="assets/jquery/jquery-ui.min.js"></script>
<script src="assets/jquery/jquery.ui.touch-punch.min.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=initGLogin" async defer></script>
<script src="assets/login.js?v=1"></script>
<script src="assets/gui.js?v=7"></script>
</head>
<body>
<!-- FB login support code -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/sk_SK/sdk.js#xfbml=1&version=v2.8&appId=1833022813615910";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- End of FB login support code -->
<?php
if (!$session->get('isLogged', false)) {
?>
<div class="maincontent" style="width:266px">
<h2>Kačice z našej police</h2>
<?php
if (count($session->getFlashBag()->get('login_errors'))) {
echo '<p>' . implode('<br>', $session->getFlashBag()->get('login_errors')) . '</p>';
}
?>
<form method="post">
<input id="uname" type="text" name="uname" size="16" value="" placeholder="Prihlasovacie meno"><br>
<input id="upass" type="password" name="upass" size="16" value="" placeholder="Heslo"><br>
<button id="loginButton" type="button" name="lsub" style="width: 266px" onclick="submitFormLogin()">Prihlásiť sa</button>
</form>
<hr>
<button type="button" class="button-fb" onclick="submitFBLogin()"><img src="assets/i/fb-logo.png" alt="f-logo"/><span>Facebook prihlásenie</span></button>
<button type="button" class="button-g" onclick="submitGLogin()"><img src="assets/i/g-logo.svg" alt="g-logo"/><span>Google+ prihlásenie</span></button>
</div>
<?php
}
else {
?>
<div class="menicko">
<a href="?"><img src="assets/i/duck_logo_flip.png" alt="logo"/> <?= $session->get('username') ?></a>
<a href="javascript:back_to_gameList()">Zoznam hier</a>
<a href="javascript:logout()">Logout</a>
<a href="?"><img src="assets/i/duck_logo.png" alt="logo"/></a>
</div>
<div id="conn-alert" style="display: none">Pripojenie k serveru zlyhalo. <a id="conn-alert-try" href="javascript:ws_connect()">Skúsiť znova</a></div>
<!-- Herna plocha pocas hry -->
<div data-phase="inGame" style="display:none">
<!-- statusbar -->
<div class="statusbar">
<table class="lives">
<tr id="lives-row">
<td class="player"></td>
<td class="player"></td>
<td class="player"></td>
<td class="player"></td>
<td class="player"></td>
<td class="player"></td>
</tr>
</table>
</div>
<!-- column 1 - game -->
<table class="content">
<tr>
<td class="column1">
<!-- river -->
<div id="river" class="river"></div>
<!-- pile -->
<div id="pile" class="pile">
<div class="pile-card"></div>
</div>
<!-- hand -->
<div class="hand">
<div id="hand-inner" class="hand-inner"></div>
</div>
<!-- deck -->
<div id="deck" class="deck">
<div class="deck-card"></div>
</div>
<!-- debug -->
<div id="debug0" class="debug"></div>
</td>
<!-- end column 1 - game -->
<!-- column 2 - messages -->
<td class="column2">
<!-- text messaging -->
<div id="message-box" class="message-box"></div>
<div class="message-input">
<input id="message-input" type="text" name="msg-input" value="" placeholder="vylej si srdce…">
</div>
</td>
<!-- column 2 -->
</tr>
</table>
</div>
<!-- Cakanie na vsetkych hracov pred spustenim hry -->
<div class="maincontent" data-phase="beforeGame" style="display:none">
<h2 id="gtitle"></h2>
<table id="tplayers"></table>
<br>
<button type="button" onclick="unsubscribe()">Odhlásiť sa z hry</button>
<button id="bstart" type="button" style="display:none" onclick="game_start()">Začať hru</button>
</div>
<!-- Zoznam hier -->
<div class="maincontent" data-phase="noGame">
<h2>Kačice z našej police</h2>
<table class="simple">
<tbody id="tb-game-list">
</tbody>
</table>
<br><button id="btNew" type="button" onclick="game_new()" style="display:none">Nová hra</button>
</div>
<script>
$(function() {
gui_start(<?= $gameId ?>, '<?= $dbConfig['ws_uri'] ?>');
});
</script>
<?php
}
?>
</body>
</html>