public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (!parent::isValid($properties_dictionary, $limit_to_keys, $error)) { return false; } if (ValidationC::should_test_property('rawEmail', $properties_dictionary, true, $limit_to_keys) && !Email::propertyIsValid('rawEmail', $properties_dictionary[USER_KEY_EMAIL], $error)) { // Email was not valid // return false; } if (ValidationC::should_test_property('rawPassword', $properties_dictionary, true, $limit_to_keys) && !Password::propertyIsValid('rawPassword', $properties_dictionary[USER_KEY_PASSWORD], $error)) { // Password was not valid // return false; } if (isset($properties_dictionary[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS])) { if (ValidationC::should_test_property(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $properties_dictionary, true, $limit_to_keys) && !User::propertyIsValid(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $properties_dictionary[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS], $error)) { // Password was not valid // return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === CREATINGUSER_KEY_FIRST_NAME || $property_name === CREATINGUSER_KEY_SURNAME || $property_name === CREATINGUSER_KEY_NAME) { if (isset($property_value) && !(is_string($property_value) && strlen($property_value) > 0)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Names must be a string with at least one character.'); return false; } } if ($property_name === CREATINGUSER_KEY_GENDER) { $property_value = intval($property_value); if (!isset($property_value) || !is_numeric($property_value) || $property_value != 0 && $property_value != 1) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, "Gender must be '0' or '1'."); return false; } } return true; }
public static function authenticate(Inputter $inputter, JSONOutputter $outputter) { // Authenticate // // 1) Test all data is available and valid // $required_dictionary = array(USER_KEY_EMAIL => '', USER_KEY_PASSWORD => ''); $inputter->validate_input($required_dictionary, null); // Validate // // User // $user_error = null; User::propertyIsValid(USER_KEY_EMAIL, $inputter->variables_array[USER_KEY_EMAIL], $user_error); User::propertyIsValid(USER_KEY_PASSWORD, $inputter->variables_array[USER_KEY_PASSWORD], $user_error); if (isset($user_error)) { $outputter->print_error($user_error); return; } // 2) Check email and password against data store // // Query string // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_authenticate_account = 'MATCH (user:User) ' . 'WHERE user.' . USER_KEY_EMAIL . ' = \'' . $inputter->variables_array[USER_KEY_EMAIL] . '\' ' . 'AND user.' . USER_KEY_PASSWORD . ' = \'' . $inputter->variables_array[USER_KEY_PASSWORD] . '\' ' . 'RETURN user'; $query_authenticate_account = new Everyman\Neo4j\Cypher\Query($client, $query_string_authenticate_account); // Run query // $result_authenticate_account = $query_authenticate_account->getResultSet(); if ($result_authenticate_account->count() !== 1) { $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'A user with that email and password does not exist.'); $outputter->print_error($error); } // 3) Output the response // $account_to_authenticate = $result_authenticate_account[0]['user']; $outputter->print_data(array(AttendingUser::printer_dictionary($account_to_authenticate))); }