Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
prakash
committed
Sep 3, 2017
1 parent
d1b4068
commit 0e4c01d
Showing
6 changed files
with
247 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
/** | ||
* Example of using the ServiceServer class | ||
* | ||
* Returns welcome service message | ||
* | ||
* @author Prakash | ||
*/ | ||
|
||
require_once('config.php'); | ||
require_once('serverservice.php'); | ||
require_once('userservice.php'); | ||
require_once('logservice.php'); | ||
require_once('bin/access.php'); | ||
|
||
class CreateAccountServer extends ServiceServer | ||
{ | ||
//use logger service trait | ||
use LogService; | ||
|
||
public $data=array(); | ||
private $auth; | ||
//initialize constructor | ||
|
||
public function __construct() | ||
{ | ||
$this->data=array(); | ||
} | ||
|
||
} | ||
|
||
try{ | ||
//create object for print welcome | ||
|
||
$objCreateAccountServer=new CreateAccountServer(); | ||
|
||
//log service request | ||
|
||
$logfile=get_class($objCreateAccountServer).'.txt'; | ||
$objCreateAccountServer->logToFile($logfile,json_encode($_SERVER)); | ||
|
||
//check validity | ||
|
||
if (!empty($_GET['token'])) | ||
{ | ||
$auth = new userAuth(); | ||
if( $auth->validToken($_GET['token'])) | ||
{ | ||
$objuserService=new userService(); | ||
|
||
//to validate user id | ||
|
||
$uid=$_GET['uid']; | ||
if($uid=='') | ||
{ | ||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"added", | ||
"version"=>VERSION, | ||
"message"=>"Please provide User ID. ", | ||
"time"=>TIME | ||
); | ||
|
||
|
||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
exit(); | ||
|
||
} | ||
|
||
if($objuserService->validUserId($uid)) | ||
{ | ||
//check if user exists | ||
if($objuserService->createUser($uid)) | ||
{ | ||
|
||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"added", | ||
"version"=>VERSION, | ||
"message"=>"Account created for user ".$uid, | ||
"time"=>TIME | ||
); | ||
|
||
|
||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
} | ||
else | ||
{ | ||
|
||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"success", | ||
"version"=>VERSION, | ||
"message"=>"Account exists already for user ".$uid, | ||
"time"=>TIME | ||
); | ||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
} | ||
} | ||
else | ||
{ | ||
|
||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"notadded", | ||
"version"=>VERSION, | ||
"message"=>"Account was not created for user ".$uid, | ||
"time"=>TIME | ||
); | ||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
} | ||
|
||
} | ||
else | ||
{ | ||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"notauthorised", | ||
"version"=>VERSION, | ||
"message"=>"Unauthorised Access ", | ||
"time"=>TIME | ||
); | ||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
} | ||
} | ||
else | ||
{ | ||
$data=array( | ||
"server"=>SERVERNAME, | ||
"status"=>"notauthorised", | ||
"version"=>VERSION, | ||
"message"=>"Unauthorised Access ", | ||
"time"=>TIME | ||
); | ||
//return data | ||
$objCreateAccountServer->displayJSONResult($data); | ||
} | ||
|
||
} | ||
catch(Exception $e){ | ||
echo $e->getMessage(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Example of using the UserService class | ||
* | ||
* User service request | ||
* | ||
* @author Prakash | ||
*/ | ||
class userService { | ||
|
||
//this is the user id | ||
|
||
private $uid; | ||
|
||
//constructor for the user service | ||
|
||
public function __construct() | ||
{ | ||
//default value not set | ||
} | ||
|
||
//check if uid is valid | ||
|
||
public function validUserId($uid) | ||
{ | ||
// check for valid characters | ||
//if (!preg_match('/[^A-Za-z0-9]/', $uid)) | ||
if (!preg_match('/[\'\/\*\<\>\?:"\|\\\]/', $uid)) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
//create user if user id is valid | ||
|
||
public function createUser($uid) | ||
{ | ||
if (!file_exists($uid)) | ||
{ | ||
mkdir($uid, 0777, true); | ||
mkdir($uid.'/Bank', 0777, true); | ||
mkdir($uid.'/Broke', 0777, true); | ||
mkdir($uid.'/Counterfeit', 0777, true); | ||
mkdir($uid.'/Export', 0777, true); | ||
mkdir($uid.'/Fracked', 0777, true); | ||
mkdir($uid.'/Import', 0777, true); | ||
mkdir($uid.'/Imported', 0777, true); | ||
mkdir($uid.'/Logs', 0777, true); | ||
mkdir($uid.'/Lost', 0777, true); | ||
mkdir($uid.'/Suspect', 0777, true); | ||
mkdir($uid.'/Templates', 0777, true); | ||
mkdir($uid.'/Trash', 0777, true); | ||
mkdir($uid.'/Waiting', 0777, true); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
?> |
0e4c01d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻