V0 : initial import
This commit is contained in:
22
ProserveAPI/htdocs/proserve/user/get.php
Normal file
22
ProserveAPI/htdocs/proserve/user/get.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_user.php';
|
||||
|
||||
// prepare user object
|
||||
$user = new User($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure userId is passed in $_POST parameters
|
||||
if (isset($_POST['userId']))
|
||||
$user->id = $_POST['userId'];
|
||||
else trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
// create the game session
|
||||
if ($user->load())
|
||||
{
|
||||
$user_arr = $user->getResultArray(true, "User_Found");
|
||||
print_r(json_encode($user_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Occured");
|
||||
?>
|
||||
40
ProserveAPI/htdocs/proserve/user/login.php
Normal file
40
ProserveAPI/htdocs/proserve/user/login.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_user.php';
|
||||
|
||||
// prepare user object
|
||||
$user = new User($db);
|
||||
|
||||
// ensure username and password are passed in $_POST parameters
|
||||
if (isset($_POST['username']))
|
||||
$user->username = $_POST['username'];
|
||||
else trigger_error( missing_parameter_error("username") );
|
||||
|
||||
if (isset($_POST['password']))
|
||||
$user->password = base64_encode($_POST['password']);
|
||||
else trigger_error( missing_parameter_error("password") );
|
||||
|
||||
// read details of user to be edited
|
||||
$stmt = $user->login();
|
||||
if($stmt->rowCount() > 0)
|
||||
{
|
||||
// get retrieved row
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
// retrieve user values
|
||||
$user->readRow($row);
|
||||
// update last connection date
|
||||
$user->refreshConnectionDate();
|
||||
|
||||
// create array
|
||||
/*$user_arr=array (
|
||||
"status" => true,
|
||||
"message" => "Successfully Login!",
|
||||
"user" => $user->toArray()
|
||||
);*/
|
||||
$user_arr = $user->getResultArray(true, "Login_OK");
|
||||
print_r(json_encode($user_arr)); // OK
|
||||
}
|
||||
else trigger_error("Invalid_Username_Password");
|
||||
?>
|
||||
27
ProserveAPI/htdocs/proserve/user/resetpassword.php
Normal file
27
ProserveAPI/htdocs/proserve/user/resetpassword.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_user.php';
|
||||
|
||||
// prepare user object
|
||||
$user = new User($db);
|
||||
$user->id = isset($_POST['userId']) ? $_POST['userId'] : -1;
|
||||
$user->username = isset($_POST['username']) ? $_POST['username'] : '';
|
||||
|
||||
// ensure userId is passed in $_POST parameters
|
||||
if ($user->id <= 0 && $user->username == '')
|
||||
trigger_error( missing_parameter_error("userId or username") );
|
||||
|
||||
if (isset($_POST['password']))
|
||||
$user->password = base64_encode($_POST['password']);
|
||||
else trigger_error( missing_parameter_error("password") );
|
||||
|
||||
// load all info for this user id
|
||||
if ($user->resetPassword())
|
||||
{
|
||||
$user_arr = $user->getResultArray(true, "Password_Updated");
|
||||
print_r(json_encode($user_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Updating_Password");
|
||||
?>
|
||||
29
ProserveAPI/htdocs/proserve/user/signup.php
Normal file
29
ProserveAPI/htdocs/proserve/user/signup.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../objects/db_user.php';
|
||||
include_once '../config/error.php';
|
||||
|
||||
// set user property values
|
||||
$user = new User($db);
|
||||
|
||||
// ensure username is passed in $_POST parameters
|
||||
if (isset($_POST['username']))
|
||||
$user->username = $_POST['username'];
|
||||
else trigger_error( missing_parameter_error("username") );
|
||||
|
||||
// read other $_POST parameters
|
||||
$user->password = base64_encode($_POST['password']);
|
||||
$user->created = date('Y-m-d H:i:s');
|
||||
$user->lastConnection = date('Y-m-d H:i:s');
|
||||
|
||||
// create the user
|
||||
if ($user->signup())
|
||||
{
|
||||
// once signed up, read info from DB to retrieve default values for all fields
|
||||
//$user->load(); // automatically called in $user->signup()
|
||||
$user_arr = $user->getResultArray(true, "Signup_OK");
|
||||
print_r(json_encode($user_arr)); // OK
|
||||
}
|
||||
else trigger_error("Username_Already_Exists");
|
||||
?>
|
||||
35
ProserveAPI/htdocs/proserve/user/update.php
Normal file
35
ProserveAPI/htdocs/proserve/user/update.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../objects/db_user.php';
|
||||
include_once '../config/error.php';
|
||||
|
||||
// prepare user object
|
||||
$user = new User($db);
|
||||
|
||||
// ensure userId is passed in $_POST parameters
|
||||
if (isset($_POST['userId']))
|
||||
$user->id = (int)$_POST['userId'];
|
||||
else trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
// load all info for this user id
|
||||
if ($user->load())
|
||||
{
|
||||
// then update fields with the passed information (and update last connection time)
|
||||
$user->firstName = $_POST['firstName'];
|
||||
$user->lastName = $_POST['lastName'];
|
||||
$user->leftHanded = (strcasecmp( $_POST['leftHanded'], "true" ) == 0) ? 1 : 0;
|
||||
$user->maleGender = (strcasecmp( $_POST['maleGender'], "true" ) == 0) ? 1 : 0;
|
||||
$user->charSkinAssetName = $_POST['charSkinAssetName'];
|
||||
$user->weaponAssetName = $_POST['weaponAssetName'];
|
||||
$user->size = (int)$_POST['size'];
|
||||
|
||||
if ($user->update())
|
||||
{
|
||||
$user_arr = $user->getResultArray(true, "User_Info_Updated");
|
||||
print_r(json_encode($user_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Retrieving_User_Info");
|
||||
}
|
||||
else trigger_error("Unknown_User_ID");
|
||||
?>
|
||||
Reference in New Issue
Block a user