Пример #1
0
 public function signUp(Request $request, Response $response, $args)
 {
     $this->logger->info("SignUp page action dispatched");
     $uri = $request->getUri();
     if ($request->getMethod() == 'POST') {
         $data = $request->getParsedBody();
         $v = new $this->validator($data);
         $v->lang('es');
         $v->rule('required', array('email', 'username', 'password', 'company'));
         if ($v->validate()) {
             try {
                 $this->logger->info("Signup with parameters: " . $data['email'] . " - " . $data['username'] . " - " . $data['password'] . " - " . $data['company']);
                 $newUser = new User();
                 $newUser->setUsername($data['username']);
                 $newUser->setEmail($data['email']);
                 $newUser->setPassword($data['password']);
                 $newUser->signUp();
                 if ($newUser != null && $newUser->isAuthenticated()) {
                     $result = ParseCloud::run('addUserToRole', ['roleName' => 'Manager'], false);
                     $this->logger->info("User added to Manager Role? " . $result);
                     $company = new Company();
                     $company->setName($data['company']);
                     $company->save();
                     $this->flash->addMessage('info', 'Sample flash message');
                     return $response->withStatus(302)->withHeader('Location', $uri->withPath(''));
                 }
             } catch (ParseException $e) {
                 ParseErrorHandler::handleParseError($e);
                 $this->flash->addMessage('error', $e->getMessage());
                 return $response->withStatus(302)->withHeader('Location', $uri->withPath('signup'));
             }
         }
         foreach ($v->errors() as $field => $errors) {
             foreach ($errors as $error) {
                 $this->flash->addMessage('error', $error);
             }
         }
         return $response->withStatus(302)->withHeader('Location', $uri->withPath('signup'));
     }
     // Get Messages
     $messages = $this->flash->getMessages();
     // Fetch Template
     $body = $this->view->fetch('login/signup.twig', ['flash' => $messages]);
     // Write Response
     return $response->write($body);
 }
Пример #2
0
 public function testFunctions()
 {
     $params = array('key1' => 'value1', 'key2' => array(1, 2, 3));
     $response = ParseCloud::run('foo', $params);
     $obj = $response['object'];
     $this->assertTrue($obj instanceof ParseObject);
     $this->assertEquals('Foo', $obj->className);
     $this->assertEquals(2, $obj->get('x'));
     $relation = $obj->get('relation');
     $this->assertTrue($relation instanceof ParseObject);
     $this->assertEquals('Bar', $relation->className);
     $this->assertEquals(3, $relation->get('x'));
     $obj = $response['array'][0];
     $this->assertTrue($obj instanceof ParseObject);
     $this->assertEquals('Bar', $obj->className);
     $this->assertEquals(2, $obj->get('x'));
     $response = ParseCloud::run('foo', array('key1' => 'value1'));
     $this->assertEquals(2, $response['a']);
     try {
         $response = ParseCloud::run('bar', array('key1' => 'value1'));
         $this->fail('Should have thrown an exception.');
     } catch (Parse\ParseException $ex) {
         // A parse exception should occur.
     }
     $response = ParseCloud::run('bar', array('key2' => 'value1'));
     $this->assertEquals('Foo', $response);
     $obj = ParseObject::create('SomeClass');
     $obj->set('name', 'Zanzibar');
     $obj->save();
     $params = array('key2' => 'value1', 'key1' => $obj);
     try {
         $response = ParseCloud::run('foo', $params);
         $this->fail('Should have thrown an exception.');
     } catch (\Exception $ex) {
         // An exception should occur.
     }
 }
Пример #3
0
 public function testUnknownFunctionFailure()
 {
     $params = ['key1' => 'value1'];
     $this->setExpectedException('Parse\\ParseException', 'function not found');
     ParseCloud::run('unknown_function', $params);
 }
Пример #4
0
require '../vendor/autoload.php';
include "../phpfastcache/phpfastcache.php";
use Parse\ParseClient;
use Parse\ParseCloud;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseRelation;
ParseClient::initialize('qjArPWWC0eD8yFmAwRjKkiCQ82Dtgq5ovIbD5ZKW', '9Yl2TD1DcjR6P1XyppzQ9NerO6ZwWBQnpQiM0MkL', 'MjYJYsSjr5wZVntUFxDvv0VpXGqhPOT8YFpULNB2');
$cache = phpFastCache("files");
// $cache->clean();
//remember to check user login
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
    $result = ParseCloud::run('postOnFacebook', ['message' => $_POST['message']]);
    $result = ParseCloud::run('sendSMS', ['message' => $_POST['message']]);
    echo "Posting to social media";
    var_dump($result);
    return;
}
$html = '';
function getEnglishOrder($value)
{
    if ($value == 1) {
        return "first";
    } else {
        if ($value == 2) {
            return "second";
        } else {
            return "third";
        }
function wtd_bus_options($field, $value)
{
    $place = 'business_categories_options';
    $parent_filters = get_option('wtd_excluded_parent_cats');
    if (!empty($parent_filters)) {
        $enabled_parent_cat_filters = json_decode($parent_filters);
    }
    $excluded_cats = get_option('wtd_excluded_cats');
    ?>
	<div ng-controller="categoryExclusion"><?php 
    $query = new ParseQuery('wp_site');
    $query->equalTo('token', get_option('wtd_api_token'));
    $site_results = $query->find();
    $site = $site_results[0];
    $relation = $site->getRelation('resortRelation', 'resort');
    $resorts = $relation->getQuery()->find();
    $query = new ParseQuery('resortParentCategories');
    $query->equalTo('deleted', false);
    $query->containedIn('resortObjectId', $resorts);
    $query->includeKey('resortObjectId');
    $results = $query->find();
    ?>
		<script type="text/javascript"><?php 
    if (empty($enabled_parent_cat_filters)) {
        ?>
				var enabled_parent_filters = null;
				var excluded_cats = null;<?php 
    } else {
        ?>
				var enabled_parent_filters = JSON.parse('<?php 
        echo empty($parent_filters) ? '{"result":true}' : $parent_filters;
        ?>
');<?php 
        if (empty($excluded_cats)) {
            ?>
					var excluded_cats = null;<?php 
        } else {
            ?>
					var excluded_cats = JSON.parse('<?php 
            echo $excluded_cats;
            ?>
');<?php 
        }
    }
    ?>

			jQuery(document).ready(function(){
				if(enabled_parent_filters!= null && enabled_parent_filters!= undefined ){
					for(var i = 0; i < enabled_parent_filters.length; i++){
						var parent_id = enabled_parent_filters[i];
						Parse.Cloud.run('get_subcategory_list_v2', {
							parent_id: parent_id,
							token: token
						}, {
							success: function(result){
								showSubcategoryList(parent_id, result);
							},
							error: function(error){
								console.log(error);
							}
						});
					}
				}
			});
		</script>
		<div data-place="<?php 
    echo $place;
    ?>
"><?php 
    for ($i = 0; $i < count($results); $i++) {
        $cat = $results[$i];
        $cat_id = $cat->getObjectId();
        $cat_enable = '';
        $cat_disable = 'selected';
        if (!empty($enabled_parent_cat_filters)) {
            if (in_array($cat->getObjectId(), $enabled_parent_cat_filters)) {
                $cat_enable = 'selected';
                $cat_disable = '';
            }
        }
        ?>
				<div id="<?php 
        echo $place;
        ?>
_parent_<?php 
        echo $cat_id;
        ?>
">
					<fieldset class="redux-field-container redux-field redux-container-switch" data-id="category-<?php 
        echo $cat->getObjectId();
        ?>
" data-type="switch">
						<div class="switch-options">
							<label id="<?php 
        echo $cat_id;
        ?>
_filter_enabled" class="cb-enable <?php 
        echo $cat_enable;
        ?>
" ng-click="getSubcategories('<?php 
        echo $cat->getObjectId();
        ?>
');" data-val="1">
								<span>Enable</span>
							</label>
							<label id="<?php 
        echo $cat_id;
        ?>
_filter_disabled" class="cb-disable <?php 
        echo $cat_disable;
        ?>
" onclick="disableParentCategoryFilter('<?php 
        echo $cat->getObjectId();
        ?>
', this);" data-place="<?php 
        echo $place;
        ?>
" data-term="<?php 
        $cat_id;
        ?>
" data-val="0">
								<span>Disable</span>
							</label>
						</div>
					</fieldset>
					<span style="font-weight:bold;"><em><?php 
        echo $cat->resortObjectId->name . ' - ' . $cat->get('name');
        ?>
</em> Category Filter</span>
					<div id="<?php 
        echo $cat->getObjectId();
        ?>
_children" layout="row" layout-wrap><?php 
        if (!empty($enabled_parent_cat_filters)) {
            if (in_array($cat->getObjectId(), $enabled_parent_cat_filters)) {
                try {
                    $subcategories = ParseCloud::run("get_subcategory_list_v2", ['parent_id' => $cat_id, 'token' => get_option('wtd_api_token')]);
                } catch (ParseException $ex) {
                    var_dump($cat_id);
                    var_dump($ex);
                }
                $subcategories = json_decode($subcategories);
                for ($j = 0; $j < count($subcategories); $j++) {
                    $sub_cat = $subcategories[$j];
                    $selected = '';
                    if (!empty($excluded_cats)) {
                        if (in_array($sub_cat->objectId, json_decode($excluded_cats))) {
                            $selected = ' checked ';
                        }
                    }
                    echo '<div flex="33"><input type="checkbox" name="excluded_cats[]" id="excluded_cats[]" onchange="saveExcludedCats();" value="' . $sub_cat->objectId . '" ' . $selected . ' />' . $sub_cat->name . '</div>';
                }
            }
        }
        ?>
					</div>
					<hr/>
				</div><?php 
    }
    ?>
		</div>
	</div><?php 
}