This repository has been archived by the owner on Dec 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timekeeperServer.php
90 lines (81 loc) · 2.11 KB
/
timekeeperServer.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
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
<?php
include_once "User.php";
include_once "FileTools.php";
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$hash = "";
$username = "";
$password = "";
$jsonString = "";
$complete = "";
$saltFilename = "salt.txt";
//hash can be "true" or "false"
if(isset($_POST['hash']))
$hash = $_POST['hash'];
if(isset($_POST['username']))
$username = $_POST['username'];
if(isset($_POST['password']))
$password = $_POST['password'];
if(isset($_POST['jsonString']))
$jsonString = $_POST['jsonString'];
if(isset($_POST['complete']))
$complete = $_POST['complete'];
if(!isset($username) || !isset($password))
{
echo "Invalid data";
return;
}
FileTools::mkUserDir();
FileTools::generateSalt($saltFilename);
if(User::userExists($username))
{
$user = User::fromFile($username);
if($hash != "" && $hash != NULL)
{
echo $user->getHash();
return;
}
if($user->getPassword() == User::getCryptPassword($password, $saltFilename))
{
if(empty($jsonString))
{
echo $user->getJsonString();
}
else
{
if(isset($complete) && isset($jsonString))
{
if ($complete == "true")
{
$user->setJSONString($jsonString);
$user->save();
}
else
{
$user->addToJSON($jsonString);
$user->save();
}
}
}
}
else
{
echo "401 Unauthorized\n";
}
}
else
{
if(!empty($jsonString))
{
$user = new User($username, User::getCryptPassword($password, $saltFilename));
$user->setJSONString($jsonString);
$user->save();
}
else
{
echo "No data";
return;
}
}
}