-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.php
51 lines (44 loc) · 1.17 KB
/
auth.php
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
<?php
header('Content-type: application/javascript');
chdir("/usr/share/mediawiki/");
require_once("/usr/share/mediawiki/includes/WebStart.php");
require_once("/usr/share/mediawiki/includes/Exception.php");
require_once("/usr/share/mediawiki/includes/User.php");
require_once("/usr/share/mediawiki/includes/Setup.php");
#echo "/*\n";
#var_dump($_SESSION);
#echo "*/\n";
function userData($user) {
echo json_encode(array(
'id' => $user->getId(),
'name' => $user->getName()
));
}
/* User logging in with POST? */
if (isset($_POST["user"]) && isset($_POST["password"])) {
$user = User::newFromName($_POST["user"]);
if ($user && $user->checkPassword($_POST["password"]) && $user->getId() !== 0) {
/* login ok */
//$_SESSION["wsUserID"] = $user->getId();
//$_SESSION["wsUserName"] = $user->getName();
$user->setCookies();
userData($user);
} else {
/* login failed */
echo json_encode("fail");
}
/* User logging in with session? */
} else {
$user = User::newFromSession();
if ($user->getId() !== 0) {
if (isset($_POST["logout"])) {
$user->logout();
echo json_encode("logout");
} else {
userData($user);
}
} else {
echo json_encode("no");
}
}
?>