Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "nusoap.php";
- $namespace = "http://rtouch.fr/Soap/AppMarket.php";
- $db_type = 'mysql'; //set $db_type to pgsql to use postgresql
- //Function provided by service
- function AppMarket($user, $password, $method, $pattern_id = NULL, $rating = NULL, $uploaded_pattern = NULL) {
- //code to connect to database
- if ($db_type === 'mysql') {
- $ret = new PDO('mysql:host=mysql51-65.pro;dbname=rtouch', 'rtouch', 'eZn8hVfSuh4x');
- }
- else
- {
- $ret = new PDO("pgsql:host=postgresql84-1.pro;dbname=rtouchpgs", "rtouchpgs", "ufy2FnNsP9Rt");
- }
- //TODO: Add postgres support
- if ($ret == true) {
- //prepare query
- //check if auth is valid/
- $pass = $password;
- $query_salt = $ret->query("SELECT salt FROM Member WHERE email = '".$user."' OR username = '".$user."'");
- $salt = $query_salt->fetch();
- $salt = $salt['salt'];
- if (!$salt) {
- return ('NOK_USERNAME_MARKET');
- }
- $iterations = 5000; // Default
- $result = '';
- $salted = $pass.'{'.$salt.'}';
- $digest = hash('sha512', $salted, true);
- for ($i = 1; $i < $iterations; $i++) {
- $digest = hash('sha512', $digest.$salted, true);
- }
- $cryptedPass = base64_encode($digest);
- $query_auth = $ret->query('SELECT * FROM Member WHERE (email = "'.$user.'" OR username = "'.$user.'") AND password = "'.$cryptedPass.'"');
- $query_fetched = $query_auth->fetch();
- if ($query_fetched && $method == 'query_public_patterns') {
- $query_patterns_list = $ret->query('SELECT id, name, description, member_id Patterns');
- $query_list_fetched = $query_patterns_list->fetchAll(PDO::FETCH_ASSOC);
- //TODO: string contatenation of the array
- if ($query_list_fetched) {
- $count = count($query_list_fetched);
- $i = 0;
- while($i < $count)
- {
- $str = $str . '|' . implode(';', $query_list_fetched[$i]);
- $i = $i + 1;
- }
- return ($str);
- }
- else {
- return("NO_PUBLIC_PATTERNS_MARKET");
- }
- }
- if ($query_fetched && ($method == 'query_own_patterns')) {
- // send mail to admin
- $query_patterns_list = $ret->query('SELECT id, name, description, member_id FROM Patterns WHERE member_id = '.$query_fetched['id'].'');
- $query_list_fetched = $query_patterns_list->fetchAll(PDO::FETCH_ASSOC);
- //TODO: string contatenation of the array
- if ($query_list_fetched) {
- $count = count($query_list_fetched);
- $i = 0;
- while($i < $count)
- {
- $str = $str . '|' . implode(';', $query_list_fetched[$i]);
- $i = $i + 1;
- }
- return ($str);
- }
- else {
- return("NO_PRIVATE_PATTERNS_MARKET");
- }
- }
- if ($query_fetched && ($method == 'download_selected_pattern') && ($pattern_id !== NULL)) {
- // send mail to admin
- $query_patterns_list = $ret->query('SELECT * FROM Patterns WHERE id = '.$pattern_id.'');
- $query_list_fetched = $query_patterns_list->fetchAll(PDO::FETCH_ASSOC);
- //TODO: string contatenation of the array
- if ($query_list_fetched) {
- $count = count($query_list_fetched);
- $i = 0;
- while($i < $count)
- {
- $str = $str . '|' . implode(';', $query_list_fetched[$i]);
- $i = $i + 1;
- }
- return ($str);
- }
- //update amount of downloads into database
- }
- else {
- return("PATTERN_DOWNLOAD_FAILED_MARKET");
- }
- if ($query_fetched && ($method == 'rate_selected_pattern') && ($pattern_id !== NULL) && ($rating !== NULL)) {
- // send mail to admin
- $query_patterns_list = $ret->query('SELECT * FROM Patterns WHERE id = '.$pattern_id.'');
- $query_list_fetched = $query_patterns_list->fetch();
- if ($query_list_fetched) {
- return('PATTERN_RATING_DONE_MARKET');
- }
- else {
- return("PATTERN_RATING_FAILED_MARKET");
- }
- }
- if ($query_fetched && ($method == 'upload_selected_pattern') && ($uploaded_pattern !== NULL)) {
- //$query_list_feteched = //cut string into the different needed elements
- //$query_list_fetched = //insert into database
- if ($query_list_fetched) {
- return('PATTERN_UPLOAD_DONE_MARKET');
- }
- else {
- return("PATTERN_UPLOAD_FAILED_MARKET");
- }
- }
- }
- else {
- return("ERROR DATABASE CONNECTION FAILED");
- }
- }
- $server = new soap_server();
- //WSDL configuration to provide method and ser AND password = "'.$password.'"ver informations to VisualStudio
- $server->configureWSDL("SimpleService");
- $server->register(
- // method name:
- 'getPatternList',
- // parameter list:
- array('user' => 'xsd:string','password'=>'xsd:string', 'method'=>'xsd:string', 'pattern_id'=>'xsd:string', 'rating'=>'xsd:string', 'uploaded_pattern' => 'xsd:string'),
- // return value(s):
- array('return'=>'xsd:string'),
- // namespace:
- $namespace,
- // soapaction: (use default)
- false,
- // style: rpc or document
- 'rpc',
- // use: encoded or literal
- 'encoded',
- // description: documentation for the method
- 'Market Webservice, is used as a function pointer.');
- //Provide service as HTTP
- $server->service($HTTP_RAW_POST_DATA);
- ?>
Add Comment
Please, Sign In to add comment