Create login logic
This commit is contained in:
parent
68e0312c84
commit
ad4b7fc4e7
9 changed files with 188 additions and 14 deletions
|
@ -41,8 +41,6 @@ function rewriteSystemInclude($psk, $clientPSK)
|
|||
|
||||
if(file_exists("../database.user.php"))
|
||||
require("../database.user.php");
|
||||
else
|
||||
require("Database.php");
|
||||
|
||||
if(file_exists("../system.user.php"))
|
||||
require("../system.user.php");
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
define("DB_HOST", "localhost");
|
||||
define("DB_USER", "root");
|
||||
define("DB_PASS", "changeme");
|
||||
define("DB_NAME", "changeme");
|
||||
|
||||
?>
|
|
@ -6,11 +6,85 @@ if(!defined("COMMON"))
|
|||
$js = getJsonizedInput();
|
||||
|
||||
// Read login parameters
|
||||
$username = $js["username"];
|
||||
$first = $js['first'];
|
||||
$last = $js['last'];
|
||||
$password = $js["password"];
|
||||
|
||||
// Password is hashed
|
||||
// Compare against hash in database + : md5(salt)
|
||||
$DB = get_DB();
|
||||
|
||||
$clientKey = $js['clientKey'];
|
||||
if($clientKey == CLIENTPSK) {
|
||||
// PSK Matches, authorized application
|
||||
|
||||
$res = $DB->query("SELECT * FROM `UserAccounts` INNER JOIN `auth` ON `UserAccounts`.`PrincipalID` = `auth`.`UUID` WHERE `FirstName` = '$first' AND `LastName` = '$last';");
|
||||
/*
|
||||
*
|
||||
return User(
|
||||
ID: UUID.parse(map['id'] as String),
|
||||
FirstName: map['first'] as String,
|
||||
LastName: map['last'] as String,
|
||||
createdAt: map['rezzed'] as int,
|
||||
userTitle: map['title'] as String);
|
||||
return S2CLoginResponsePacket(
|
||||
loggedIn: map['login'] as bool,
|
||||
reason: map['reason'] as String,
|
||||
user: User.parseJson(json.encode(map['user'])));
|
||||
*/
|
||||
$id = NULLKEY;
|
||||
$first = "";
|
||||
$last = "";
|
||||
$rezday = 0;
|
||||
$title = "";
|
||||
$login = false;
|
||||
$reason = "Invalid password";
|
||||
$active = false;
|
||||
|
||||
if($res->num_rows > 0) {
|
||||
$row = $res->fetch_assoc();
|
||||
$pwSalt = $row['passwordSalt'];
|
||||
$pwHash = $row['passwordHash'];
|
||||
|
||||
if(md5($password.":" . $pwSalt) == $pwHash) {
|
||||
// Login Success
|
||||
$_SESSION['login'] = "1";
|
||||
$id = $row['UUID'];
|
||||
$first = $row['FirstName'];
|
||||
$last = $row['LastName'];
|
||||
$rezday = $row['createdAt'];
|
||||
$title = $row['UserTitle'];
|
||||
$active = $row['active'] == 1;
|
||||
|
||||
$reason = "success";
|
||||
$login=true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$reason = "No such user";
|
||||
}
|
||||
|
||||
die(json_encode(
|
||||
array(
|
||||
"login" => $login,
|
||||
"reason" => $reason,
|
||||
"type" => "S2CLoginResponse",
|
||||
"user" => array(
|
||||
"id" => $id,
|
||||
"first" => $first,
|
||||
"last" => $last,
|
||||
"title" => $title,
|
||||
"rez" => $rezday,
|
||||
"active" => $active
|
||||
)
|
||||
)
|
||||
));
|
||||
} else {
|
||||
die(json_encode(array(
|
||||
"login" => false,
|
||||
"reason" => "Unauthorized",
|
||||
"type" => "S2CLoginResponse"
|
||||
)));
|
||||
}
|
||||
|
||||
?>
|
|
@ -26,7 +26,13 @@ if($clientKey == CLIENTPSK) {
|
|||
|
||||
$DB->query("INSERT INTO `UserAccounts` (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created, UserLevel, UserFlags, UserTitle, active) VALUES ('$ID', '".NULLKEY."', '$first', '$last', '$email', '', '".time()."', '$level', '0', '$title', '0');");
|
||||
|
||||
die(json_encode(array("done"=>true, "type"=> "S2CSimpleReply")));
|
||||
die(
|
||||
json_encode(
|
||||
array(
|
||||
"done"=>true,
|
||||
"type"=> "S2CSimpleReply"
|
||||
)
|
||||
));
|
||||
|
||||
}else {
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
if(!defined("COMMON"))
|
||||
require("Common.php");
|
||||
|
||||
if(DB_NAME == "changeme" && DB_PASS == "changeme") {
|
||||
if(!defined("DB_NAME") && !defined("DB_PASS")) {
|
||||
$ret = array (
|
||||
"done" => false,
|
||||
"type" => "S2CSimpleReply"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue