本文整理汇总了PHP中GUMP::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP GUMP::validate方法的具体用法?PHP GUMP::validate怎么用?PHP GUMP::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GUMP
的用法示例。
在下文中一共展示了GUMP::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submit_registration
/**
* Submit Registration
*
* Controller for the Authenticate module.
*
* @author Goran Halusa <gor@webcraftr.com>
* @since 0.1.0
* @param array $route The route data array
*/
function submit_registration(\Slim\Route $route)
{
$app = \Slim\Slim::getInstance();
$final_global_template_vars = $app->config('final_global_template_vars');
require_once $final_global_template_vars["default_module_list"]["user_account"]["absolute_path_to_this_module"] . "/models/user_account.class.php";
require_once $final_global_template_vars["default_module_list"]["group"]["absolute_path_to_this_module"] . "/models/group.class.php";
require_once $_SERVER["PATH_TO_VENDOR"] . "wixel/gump/gump.class.php";
$env = $app->environment();
$db_conn = new \PHPSkeleton\models\db($final_global_template_vars["db_connection"]);
$db_resource = $db_conn->get_resource();
$user_account = new \PHPSkeleton\UserAccount($db_resource, $final_global_template_vars["session_key"]);
$gump = new GUMP();
$errors = array();
$user_account_id = $_SESSION[$final_global_template_vars["session_key"]]["user_account_id"];
// Check to see if this user is already assigned to a group - they may have been added by another administrator.
$current_groups = $user_account->get_user_account_groups($user_account_id);
if (!$current_groups) {
// Validate the group that they submitted.
$rules = array("group" => "required|integer");
$validated = $gump->validate($app->request()->post(), $rules);
if ($validated !== true) {
$errors = \phpskeleton\models\utility::gump_parse_errors($validated);
}
}
// Validate the acceptable use policy.
$rules = array("acceptable_use_policy" => "required|integer");
$validated = $gump->validate($app->request()->post(), $rules);
if ($validated !== true) {
$errors = array_merge($errors, \phpskeleton\models\utility::gump_parse_errors($validated));
}
if (!$errors) {
// Create the actual user account.
$user_data = array("group_data" => '{"0":{"group_id":"' . $app->request()->post("group") . '","roles":["' . $final_global_template_vars["default_role_id"] . '"]}}');
$update_groups = !empty($current_groups) ? false : true;
// Get the existing user account info.
$existing_user_data = $user_account->get_user_account_info($user_account_id);
// Merge the data.
$user_data = array_merge($user_data, $existing_user_data);
// Insert/update
$user_account->insert_update_user_account($user_data, $user_account_id, $update_groups);
// Update acceptable use policy.
$user_account->update_acceptable_use_policy($user_account_id, 1);
$landing_page = $final_global_template_vars['landing_page'];
if (isset($_COOKIE[$final_global_template_vars["redirect_cookie_key"]]) && $_COOKIE[$final_global_template_vars["redirect_cookie_key"]]) {
$landing_page = $_COOKIE[$final_global_template_vars["redirect_cookie_key"]];
setcookie($final_global_template_vars["redirect_cookie_key"], "", time() - 3600, "/");
unset($_COOKIE[$final_global_template_vars["redirect_cookie_key"]]);
}
// Add role list to session.
$_SESSION[$final_global_template_vars["session_key"]][$final_global_template_vars["current_user_roles_session_key"]] = \phpskeleton\models\utility::array_flatten($user_account->get_user_roles_list($user_account_id));
// Add group to session.
$_SESSION[$final_global_template_vars["session_key"]]["associated_groups"] = array((int) $app->request()->post("group"));
$app->redirect($landing_page);
} else {
$env["default_validation_errors"] = $errors;
}
}
示例2: insert_update_group
/**
* Insert/Update Group
*
* Controller for the Group module.
*
* @param \Slim\Route $route The route data array
* @return void
*/
function insert_update_group(\Slim\Route $route)
{
$app = \Slim\Slim::getInstance();
$final_global_template_vars = $app->config('final_global_template_vars');
require_once $final_global_template_vars["absolute_path_to_this_module"] . "/models/group.class.php";
require_once $_SERVER["PATH_TO_VENDOR"] . "wixel/gump/gump.class.php";
// URL parameters matched in the route.
$params = $route->getParams();
$group_id = isset($params["group_id"]) ? $params["group_id"] : false;
$db_conn = new \PHPSkeleton\models\db($final_global_template_vars["db_connection"]);
$db_resource = $db_conn->get_resource();
$group = new \PHPSkeleton\Group($db_resource, $final_global_template_vars["session_key"]);
$gump = new GUMP();
$rules = array("name" => "required", "abbreviation" => "required|alpha_numeric", "state" => "alpha_numeric", "zip" => "numeric|exact_len,5", "group_parent" => "numeric");
$validated = $gump->validate($app->request()->post(), $rules);
$errors = array();
if ($validated !== true) {
$errors = \phpskeleton\models\utility::gump_parse_errors($validated);
}
if (!$errors) {
$group->insert_update_group($app->request()->post(), $group_id);
// If group_id is true, then the group was modified. Otherwise, it was created.
if ($group_id) {
$app->flash('message', 'The group has been successfully modified.');
} else {
$app->flash('message', 'New group has been successfully created.');
}
$app->redirect($final_global_template_vars["path_to_this_module"]);
} else {
$env = $app->environment();
$env["default_validation_errors"] = $errors;
}
}
示例3: authenticate_user
/**
* Authenticate User
*
* Controller for the Authenticate module.
*
* @author Goran Halusa <gor@webcraftr.com>
* @since 0.1.0
*/
function authenticate_user()
{
$app = \Slim\Slim::getInstance();
$final_global_template_vars = $app->config('final_global_template_vars');
require_once $_SERVER["PATH_TO_VENDOR"] . "wixel/gump/gump.class.php";
require_once $final_global_template_vars["absolute_path_to_this_module"] . "/models/authenticate.class.php";
$db_conn = new \PHPSkeleton\models\db($final_global_template_vars["db_connection"]);
$db_resource = $db_conn->get_resource();
$authenticate = new \PHPSkeleton\Authenticate($db_resource, $final_global_template_vars["session_key"]);
$gump = new GUMP();
$rules = array("user_account_email" => "valid_email", "password" => "min_len,6");
$validated = $gump->validate($app->request()->post(), $rules);
if ($validated === true) {
$validated = array(array("field" => "user_account_email", "value" => "", "rule" => ""));
// Query the database for the user_account_email and password.
try {
$local_validated = $authenticate->authenticate_local($app->request()->post('user_account_email'), $app->request()->post('password'));
} catch (Exception $e) {
$local_validated = false;
}
if ($local_validated) {
$validated = true;
session_regenerate_id();
foreach ($final_global_template_vars["auth_session_keys"] as $single_key) {
$_SESSION[$final_global_template_vars["session_key"]][$single_key] = $local_validated[$single_key];
}
// Log the successful login attempt.
$authenticate->log_login_attempt($local_validated["user_account_email"], "succeeded");
}
}
if ($validated === true) {
// The show_login_form.php redirects to the redirect cookie key instead of doing it here.
} else {
// Log the failed login attempt.
$authenticate->log_login_attempt($app->request()->post("user_account_email"), "failed");
$env = $app->environment();
$env["default_validation_errors"] = $validated;
}
}
示例4: function
#!/usr/bin/php -q
<?php
require "../gump.class.php";
// Add the custom validator
GUMP::add_validator("is_object", function ($field, $input, $param = NULL) {
return is_object($input[$field]);
});
// Generic test data
$input_data = array('not_object' => 5, 'valid_object' => new stdClass());
$rules = array('not_object' => "required|is_object", 'valid_object' => "required|is_object");
// METHOD 1 (Long):
$validator = new GUMP();
$validated = $validator->validate($input_data, $rules);
if ($validated === true) {
echo "Validation passed!";
} else {
echo $validator->get_readable_errors(true);
}
// METHOD 2 (Short):
$is_valid = GUMP::is_valid($input_data, $rules);
if ($is_valid === true) {
echo "Validation passed!";
} else {
print_r($is_valid);
}
示例5: process_submission
public static function process_submission()
{
require_once 'gump.class.php';
$gump = new GUMP();
$_POST = $gump->sanitize($_POST);
global $a;
$a = AC::load_current_activity();
if (isset($_POST['waitlist-submit'])) {
AC::generate_waitlist_fields();
require_once 'wp-content/themes/vetri-master/lib/ReCaptcha/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha('6LendQoTAAAAABQzKPl_3sLPQQkTKMW4DBnIP37R', new \ReCaptcha\RequestMethod\Curl());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
AC::$errors['recaptcha'] = 'Please verify using the ReCaptcha widget';
return false;
}
} else {
if (AC::is_active_timer_expired()) {
AC::$errors[] = 'Your timer has expired. Please start over.';
AC::reset_all();
return false;
}
AC::generate_fields();
$step = $_POST['step'];
foreach ($_POST['form'] as $k => $v) {
$_SESSION['edgimo-reservation-form']['step-' . $step][$k] = $v;
}
}
if (isset($_POST['activity-center-back'])) {
$_SESSION['edgimo-reservation-form']['current-step']--;
if (AC::get_current_step() === 1) {
AC::reset_timer();
}
return true;
}
$validation = array();
$filter = array();
foreach ($_POST['form'] as $field_name => $field_value) {
if (isset(AC::$fields[$field_name]['validate'])) {
$validation[$field_name] = AC::$fields[$field_name]['validate'];
}
if (isset(AC::$fields[$field_name]['filter'])) {
$filter[$field_name] = AC::$fields[$field_name]['filter'];
}
}
$gump->validation_rules($validation);
$gump->filter_rules($filter);
$validated_data = $gump->run($_POST['form']);
if (isset($step) && $step == 1 && !isset($validated_data['terms'])) {
AC::$errors['terms'] = 'You must agree to the terms of registration in order to register for an event. If you have questions about the terms, please feel free to contact us at <a href="mailto:' . $a->service_email . '">' . $a->service_email . '</a>';
return false;
}
if ($validated_data === false) {
$temp = $gump->get_readable_errors();
$i = 0;
foreach ($gump->validate($_POST['form'], $validation) as $error) {
AC::$errors[$error['field']] = $temp[$i];
$i++;
}
return false;
}
if (isset($_POST['waitlist-submit'])) {
$new_waitlist = wp_insert_post(array('post_name' => $validated_data['name'], 'post_title' => $validated_data['name'], 'post_type' => 'waitlist', 'post_status' => 'publish'));
$meta = array('_waitlist_activity' => $validated_data['activity_id'], '_waitlist_created' => time(), '_waitlist_name' => $validated_data['name'], '_waitlist_desired_seats' => $validated_data['desired_seats'], '_waitlist_phone' => $validated_data['phone_1'] . $validated_data['phone_2'] . $validated_data['phone_3'], '_waitlist_email' => $validated_data['email'], '_waitlist_code' => md5(time() . rand() . $validated_data['name']), '_waitlist_redeemed' => 'false');
foreach ($meta as $k => $v) {
add_post_meta($new_waitlist, $k, $v, true);
}
require_once 'wp-content/themes/vetri-master/lib/phpmailer/PHPMailerAutoload.php';
AC::send_admin_waitlist_email($new_waitlist);
AC::send_waitlist_confirmation_email($new_waitlist);
$_SESSION['edgimo-reservation-form']['waitlist-success'] = $new_waitlist;
wp_redirect(AC::get_redirect_url());
exit;
}
switch ($step) {
case 1:
//check to see if the capacity went down after submitting registrant count
if ($a->seats_available < AC::load_saved_data('number_of_registrants') && !AC::current_user_has_pending_reservation() && !AC::valid_waitlist_code()) {
AC::$errors['number_of_registrants'] = 'The number of registrants you selected is no longer available. Please select again.';
return false;
}
$_SESSION['edgimo-reservation-form']['current-step'] = 2;
//in case user clicked back using browser and not button, pending data will still exist. delete it
if (AC::current_user_has_pending_reservation()) {
AC::reset_timer();
}
//by now any old pending data should be gone
//always initiate a new timer when step 1 is submitted
AC::init_timer();
break;
case 2:
$_SESSION['edgimo-reservation-form']['current-step'] = 3;
break;
case 3:
$values = AC::get_all_final_values();
$result = AC::process_transaction($values);
if ($result['success']) {
$new_reservation = wp_insert_post(array('post_name' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_title' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_type' => 'reservation', 'post_status' => 'publish'));
isset($values['donation']) ? $values['donation'] = $values['donation'] : ($values['donation'] = 0);
$meta = array('_reservation_activity' => $a->ID, '_reservation_created' => time(), '_reservation_total' => AC::get_total(), '_reservation_fee' => $a->fee * $values['number_of_registrants'], '_reservation_gratuity' => AC::calculate_gratuity(), '_reservation_tax' => AC::calculate_tax(), '_reservation_donation' => $values['donation'], '_reservation_registrant_count' => $values['number_of_registrants'], '_reservation_optin' => $values['optin'], '_reservation_billing_first_name' => $values['billing_first_name'], '_reservation_billing_last_name' => $values['billing_last_name'], '_reservation_billing_address' => $values['billing_address'], '_reservation_billing_phone' => $values['billing_phone'], '_reservation_billing_city' => $values['billing_city'], '_reservation_billing_state' => $values['billing_state'], '_reservation_billing_zip' => $values['billing_zip'], '_reservation_transaction_id' => $result['RefNum'], '_reservation_auth_code' => $result['AuthCode'], '_reservation_card_type' => AC::card_type($values['cc_number']), '_reservation_last4' => $result['Last4']);
//.........这里部分代码省略.........
示例6: GUMP
# Not logged in
case !is_loggedin():
JSON::parse(100, 'negative', 'You\'re not logged in.', null, true);
break;
# No data
# No data
case !is_form_data():
JSON::parse(100, 'negative', 'Nothing was submitted.', null, true);
break;
}
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('files' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
# Split Base64
$parts = explode(';', $data['files']);
# Split Type
$type = explode('/', $parts[0]);
# File Extension
$ext = $type[1];
# Get File
$file = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $data['files']));
# Set filename
示例7: update_password
/**
* Update Password
*
* Controller for the User Account module.
*
* @author Goran Halusa <gor@webcraftr.com>
* @since 0.1.0
*/
function update_password()
{
$app = \Slim\Slim::getInstance();
$final_global_template_vars = $app->config('final_global_template_vars');
require_once $_SERVER["PATH_TO_VENDOR"] . "wixel/gump/gump.class.php";
require_once $final_global_template_vars["absolute_path_to_this_module"] . "/models/register_account.class.php";
require_once $final_global_template_vars["default_module_list"]["authenticate"]["absolute_path_to_this_module"] . "/models/authenticate.class.php";
require_once $_SERVER["PATH_TO_VENDOR"] . "phpmailer/phpmailer/PHPMailerAutoload.php";
$db_conn = new \PHPSkeleton\models\db($final_global_template_vars["db_connection"]);
$db_resource = $db_conn->get_resource();
$register_account = new \PHPSkeleton\RegisterAccount($db_resource, $final_global_template_vars["session_key"]);
$authenticate = new \PHPSkeleton\Authenticate($db_resource, $final_global_template_vars["session_key"]);
$gump = new GUMP();
$mail = new PHPMailer();
$post = $app->request()->post() ? $app->request()->post() : false;
$account_email_exists = false;
// Is the email address in the database?
if ($post) {
$account_email_exists = $register_account->account_email_exists($post["user_account_email"]);
if (!$account_email_exists) {
$app->flash('message', 'The entered email address was not found in our database.');
$app->redirect($final_global_template_vars["path_to_this_module"] . "/password/");
}
}
$rules = array();
if ($account_email_exists) {
$rules = array("user_account_password" => "required|max_len,100|min_len,6", "password_check" => "required|max_len,100|min_len,6");
}
$validated = $gump->validate($post, $rules);
if ($post["user_account_password"] != $post["password_check"]) {
$validated_password_check = array("field" => "user_account_password_check", "value" => null, "rule" => "validate_required");
if (is_array($validated)) {
array_push($validated, $validated_password_check);
} else {
$validated = array($validated_password_check);
}
}
$errors = array();
if ($validated !== true) {
$errors = \phpskeleton\models\utility::gump_parse_errors($validated);
}
if (isset($errors["user_account_password_check"])) {
$errors["user_account_password_check"] = "Passwords did not match.";
}
// If there are no errors, process posted data and email to user
if (empty($errors) && $post) {
// Attempt to update the user_account_password and set the account to active (returns boolean)
$updated = $register_account->update_password($authenticate->generate_hashed_password($post["user_account_password"]), $account_email_exists['user_account_id'], $post["emailed_hash"]);
if ($updated) {
// Prepare the email...
// The email subject.
$subject = 'Your Password Has Been Reset';
// The message.
$message = '<h2>Your Password Has Been Reset</h2>
<hr>
<p>If you did not execute this change, please contact the site administrator as soon as possible.</p>';
// For the ability to send emails from an AWS EC2 instance
// If you need this functionality, you can configure the settings accordingly in /default_global_settings.php
if ($final_global_template_vars["hosting_vendor"] && $final_global_template_vars["hosting_vendor"] == "aws_ec2") {
$email = array();
require_once $final_global_template_vars["path_to_smtp_settings"];
// SMTP Settings
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = $email['settings']['smtpauth'];
$mail->SMTPSecure = $email['settings']['smtpsecure'];
$mail->Host = $email['settings']['host'];
$mail->Username = $email['settings']['username'];
$mail->Password = $email['settings']['password'];
}
// From (verified email address).
$mail->SetFrom($final_global_template_vars["send_emails_from"], $final_global_template_vars["site_name"] . ' Accounts');
// Subject
$mail->Subject = $subject;
$mail->MsgHTML($message);
// Recipient
$mail->AddAddress($post['user_account_email']);
// Send the email.
$mail->Send();
$app->flash('message', 'Your password has been reset.');
$app->redirect($final_global_template_vars["path_to_this_module"] . "/password/");
} else {
$app->flash('message', 'Processing failed.');
$app->redirect($final_global_template_vars["path_to_this_module"] . "/password/");
}
} else {
$app->flash('message', $errors["user_account_password"]);
$app->redirect($final_global_template_vars["path_to_this_module"] . "/reset/?user_account_email=" . $account_email_exists['user_account_email'] . "&emailed_hash=" . $post["emailed_hash"]);
}
}
示例8: GUMP
<?php
error_reporting(-1);
ini_set('display_errors', 1);
require "gump.class.php";
$validator = new GUMP();
$rules = array('missing' => 'required', 'email' => 'valid_email', 'max_len' => 'max_len,1', 'min_len' => 'min_len,4', 'exact_len' => 'exact_len,10', 'alpha' => 'alpha', 'alpha_numeric' => 'alpha_numeric', 'alpha_dash' => 'alpha_dash', 'numeric' => 'numeric', 'integer' => 'integer', 'boolean' => 'boolean', 'float' => 'float', 'valid_url' => 'valid_url', 'url_exists' => 'url_exists', 'valid_ip' => 'valid_ip', 'valid_ipv4' => 'valid_ipv4', 'valid_ipv6' => 'valid_ipv6', 'valid_name' => 'valid_name', 'contains' => 'contains,free pro basic');
$invalid_data = array('missing' => '', 'email' => "not a valid email\r\n", 'max_len' => "1234567890", 'min_len' => "1", 'exact_len' => "123456", 'alpha' => "*(^*^*&", 'alpha_numeric' => "abcdefg12345+\r\n\r\n\r\n", 'alpha_dash' => "ab<script>alert(1);</script>cdefg12345-_+", 'numeric' => "one, two\r\n", 'integer' => "1,003\r\n\r\n\r\n\r\n", 'boolean' => "this is not a boolean\r\n\r\n\r\n\r\n", 'float' => "not a float\r\n", 'valid_url' => "\r\n\r\nhttp://add", 'url_exists' => "http://asdasdasd354.gov", 'valid_ip' => "google.com", 'valid_ipv4' => "google.com", 'valid_ipv6' => "google.com", 'valid_name' => '*&((*S))(*09890uiadaiusyd)', 'contains' => 'premium');
$valid_data = array('missing' => 'This is not missing', 'email' => 'sean@wixel.net', 'max_len' => '1', 'min_len' => '1234', 'exact_len' => '1234567890', 'alpha' => 'ÈÉÊËÌÍÎÏÒÓÔasdasdasd', 'alpha_numeric' => 'abcdefg12345', 'alpha_dash' => 'abcdefg12345-_', 'numeric' => 2.0, 'integer' => 3, 'boolean' => FALSE, 'float' => 10.1, 'valid_url' => 'http://wixel.net', 'url_exists' => 'http://wixel.net', 'valid_ip' => '69.163.138.23', 'valid_ipv4' => "255.255.255.255", 'valid_ipv6' => "2001:0db8:85a3:08d3:1319:8a2e:0370:7334", 'valid_name' => 'Sean Nieuwoudt', 'contains' => 'free');
echo "\nBEFORE SANITIZE:\n\n";
print_r($invalid_data);
echo "\nAFTER SANITIZE:\n\n";
print_r($validator->sanitize($invalid_data));
echo "\nTHESE ALL FAIL:\n\n";
$validator->validate($invalid_data, $rules);
// Print out the errors using the new get_readable_errors() method:
print_r($validator->get_readable_errors());
if ($validator->validate($valid_data, $rules)) {
echo "\nTHESE ALL SUCCEED:\n\n";
print_r($valid_data);
}
echo "\nDONE\n\n";
示例9: GUMP
<?php
require "gump.class.php";
$validator = new GUMP();
$_POST = $validator->sanitize($_POST);
$rules = array('username' => 'required|alpha_numeric|max_len,100|min_len,6', 'password' => 'required|max_len,100|min_len,6', 'email' => 'required|valid_email', 'gender' => 'required|exact_len,1', 'credit_card' => 'required|valid_cc', 'bio' => 'required', 'birth' => 'required|date');
$validated = @$validator->validate($_POST, $rules);
if ($validated === TRUE) {
$result["result"] = true;
die(json_encode($result));
} else {
$result['error'] = $validator->get_errors_array();
$result["result"] = false;
die(json_encode($result));
}
示例10: array
#!/usr/bin/php -q
<?php
require "gump.class.php";
$rules = array('missing' => 'required', 'email' => 'valid_email', 'max_len' => 'max_len,1', 'min_len' => 'min_len,4', 'exact_len' => 'exact_len,10', 'alpha' => 'alpha', 'alpha_numeric' => 'alpha_numeric', 'alpha_dash' => 'alpha_dash', 'numeric' => 'numeric', 'integer' => 'integer', 'boolean' => 'boolean', 'float' => 'float', 'valid_url' => 'valid_url', 'url_exists' => 'url_exists', 'valid_ip' => 'valid_ip');
$invalid_data = array('missing' => '', 'email' => "not a valid email\r\n", 'max_len' => "1234567890", 'min_len' => "1", 'exact_len' => "123456", 'alpha' => "*(^*^*&", 'alpha_numeric' => "abcdefg12345+\r\n\r\n\r\n", 'alpha_dash' => "ab<script>alert(1);</script>cdefg12345-_+", 'numeric' => "one, two\r\n", 'integer' => "1,003\r\n\r\n\r\n\r\n", 'boolean' => "this is not a boolean\r\n\r\n\r\n\r\n", 'float' => "not a float\r\n", 'valid_url' => "\r\n\r\nhttp://add", 'url_exists' => "http://asdasdasd354.gov", 'valid_ip' => "google.com");
$valid_data = array('missing' => 'This is not missing', 'email' => 'sean@wixel.net', 'max_len' => '1', 'min_len' => '1234', 'exact_len' => '1234567890', 'alpha' => 'abcdefg', 'alpha_numeric' => 'abcdefg12345', 'alpha_dash' => 'abcdefg12345-_', 'numeric' => 2.0, 'integer' => 3, 'boolean' => FALSE, 'float' => 10.1, 'valid_url' => 'http://wixel.net', 'url_exists' => 'http://wixel.net', 'valid_ip' => '69.163.138.62');
echo "\nBEFORE SANITIZE:\n\n";
print_r($invalid_data);
echo "\nAFTER SANITIZE:\n\n";
print_r(GUMP::sanitize($invalid_data));
echo "\nTHESE ALL FAIL:\n\n";
print_r(GUMP::validate($invalid_data, $rules));
if (GUMP::validate($valid_data, $rules)) {
echo "\nTHESE ALL SUCCEED:\n\n";
print_r($valid_data);
}
echo "\nDONE\n\n";
示例11: insert_user_account
/**
* Insert User Account
*
* Controller for the User Account module.
*
* @author Goran Halusa <gor@webcraftr.com>
* @since 0.1.0
*/
function insert_user_account()
{
$app = \Slim\Slim::getInstance();
$env = $app->environment();
$final_global_template_vars = $app->config('final_global_template_vars');
require_once $_SERVER["PATH_TO_VENDOR"] . "wixel/gump/gump.class.php";
require_once $final_global_template_vars["absolute_path_to_this_module"] . "/models/user_account.class.php";
require_once $final_global_template_vars["absolute_path_to_this_module"] . "/models/register_account.class.php";
require_once $final_global_template_vars["default_module_list"]["authenticate"]["absolute_path_to_this_module"] . "/models/authenticate.class.php";
require_once $_SERVER["PATH_TO_VENDOR"] . "phpmailer/phpmailer/PHPMailerAutoload.php";
$db_conn = new \PHPSkeleton\models\db($final_global_template_vars["db_connection"]);
$db_resource = $db_conn->get_resource();
$useraccount = new \PHPSkeleton\UserAccount($db_resource, $final_global_template_vars["session_key"]);
$register_account = new \PHPSkeleton\RegisterAccount($db_resource, $final_global_template_vars["session_key"]);
$authenticate = new \PHPSkeleton\Authenticate($db_resource, $final_global_template_vars["session_key"]);
$gump = new GUMP();
$mail = new PHPMailer();
$errors = false;
$posted_data = $app->request()->post() ? $app->request()->post() : false;
$account_email_exists = $register_account->account_email_exists($posted_data["user_account_email"]);
if ($account_email_exists) {
$app->flash('message', 'It looks like you already have an account. Email address is already in use.');
$app->redirect($final_global_template_vars["path_to_this_module"] . "/register/");
}
// GUMP validation rules
$rules = array("user_account_email" => "required|valid_email", "user_account_password" => "required|max_len,100|min_len,6", "first_name" => "required|alpha_numeric", "last_name" => "required|alpha_numeric");
// Validation using GUMP
if ($posted_data) {
$validated = array();
$errors = array();
$validated = $gump->validate($posted_data, $rules);
if ($validated !== true) {
$errors = \phpskeleton\models\utility::gump_parse_errors($validated);
}
if ($errors) {
$env = $app->environment();
$env["default_validation_errors"] = $errors;
}
}
$default_validation_errors = isset($env["default_validation_errors"]) ? $env["default_validation_errors"] : false;
// If there are no errors, process posted data and email to user
if (!$default_validation_errors && $posted_data) {
$emailed_hash = md5(rand(0, 1000));
// INSERT this user into the user_account table
$statement = $db_resource->prepare("INSERT INTO user_account\n (user_account_email, user_account_password, first_name, last_name, acceptable_use_policy, created_date, active, emailed_hash)\n VALUES ( :user_account_email, :user_account_password, :first_name, :last_name, 1, NOW(), 0, :emailed_hash )");
$statement->bindValue(":user_account_email", $posted_data['user_account_email'], PDO::PARAM_STR);
$statement->bindValue(":user_account_password", $authenticate->generate_hashed_password($posted_data['user_account_password']), PDO::PARAM_STR);
$statement->bindValue(":first_name", $posted_data['first_name'], PDO::PARAM_STR);
$statement->bindValue(":last_name", $posted_data['last_name'], PDO::PARAM_STR);
$statement->bindValue(":emailed_hash", $emailed_hash, PDO::PARAM_STR);
$statement->execute();
$error = $db_resource->errorInfo();
if ($error[0] != "00000") {
die('The INSERT INTO user_account failed.');
}
$last_inserted_user_account_id = $db_resource->lastInsertId();
// INSERT this user into the user_account_groups table with "Author" privileges
$statement = $db_resource->prepare("INSERT INTO user_account_groups\n (role_id, user_account_id, group_id)\n VALUES ( 2, :user_account_id, 1 )");
$statement->bindValue(":user_account_id", $last_inserted_user_account_id, PDO::PARAM_INT);
$statement->execute();
$error = $db_resource->errorInfo();
if ($error[0] != "00000") {
die('The INSERT INTO user_account_groups failed.');
}
// Send emails
// Email setup for user
$to = $posted_data['user_account_email'];
// Send email to our user
$subject = 'Signup | Verification';
// Give the email a subject
$message = '<h2>Hello ' . $posted_data['first_name'] . '!</h2>
<p>Your account has been created, you can login with the following credentials after you have
activated your account by accessing the url below.</p>
<hr>
<p>Username: ' . $posted_data['user_account_email'] . '</p>
<p>Password: (The password you submitted during the registration process.)</p>
<hr>
<p>Please click this link to activate your account:<br />
<a href="http://' . $_SERVER["SERVER_NAME"] . '/user_account/verify/?user_account_email=' . $posted_data['user_account_email'] . '&emailed_hash=' . $emailed_hash . '">http://' . $_SERVER["SERVER_NAME"] . '/user_account/verify/?user_account_email=' . $posted_data['user_account_email'] . '&emailed_hash=' . $emailed_hash . '</a></p>';
// Our message above including the link
// Email setup for Universal Administrators
// First, get all of the "Universal Administrator" email addresses
$admin_emails = array();
$universal_administrator_emails = $useraccount->get_universal_administrator_emails();
// Create a comma-delimited list of email addresses
if (is_array($universal_administrator_emails) && !empty($universal_administrator_emails)) {
foreach ($universal_administrator_emails as $email) {
array_push($admin_emails, $email["user_account_email"]);
}
}
$subject_admins = 'New User Registration';
// Give the email a subject
//.........这里部分代码省略.........
示例12: GUMP
<?php
# Check user & validate data
switch (true) {
# Not logged in
case is_loggedin():
JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> You\'re already logged in!', null, true);
break;
# No post data
# No post data
case !is_form_data():
JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> There was a problem logging you in. (Error: No data received)', null, true);
break;
}
# Create User Object
$_ce_user = new CMSEditor\User($_ce_config);
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('username' => 'required', 'password' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
# Attempt login
$_ce_user->login($data['username'], $data['password']);
}
示例13: GUMP
#!/usr/bin/php -q
<?php
require "../gump.class.php";
$validator = new GUMP();
$_POST = array('url' => 'http://ahakjdhkahddfsdfsdfdkjad.com');
$rules = array('url' => 'url_exists');
print_r($validator->validate($_POST, $rules));
示例14: array
#!/usr/bin/php -q
<?php
require "../gump.class.php";
$_POST = array('url' => 'http://ahakjdhkahddfsdfsdfdkjad.com');
$rules = array('url' => 'url_exists');
print_r(GUMP::validate($_POST, $rules));
示例15: htmlentities
//
if ($app->request->post('password') !== $app->request->post('password_confirm')) {
$validated_data = false;
}
}
/*
if (is_array($validated_data)) {
foreach($validated_data as $key => $val)
{
$validated_data[$key] = htmlentities($val);
}
}
echo '<pre>';var_dump($validated_data);echo '</pre>';
*/
if ($validated_data === false) {
$errors = $gump->validate($app->request->post(), $validation_rules_2);
if (!is_array($errors)) {
$errors = [];
}
$validate_username = GUMP::is_valid(['username' => $app->request->post('username')], ['username' => 'istaken']);
if ($validate_username !== true) {
$errors[] = array('field' => 'username', 'value' => '', 'rule' => 'validate_istaken', 'param' => '');
}
$validate_email = GUMP::is_valid(['email' => $app->request->post('email')], ['email' => 'istaken']);
if ($validate_email !== true) {
$errors[] = array('field' => 'email', 'value' => '', 'rule' => 'validate_istaken', 'param' => '');
}
if ($app->request->post('password') !== $app->request->post('password_confirm')) {
$errors[] = array('field' => 'password_confirm', 'value' => '', 'rule' => 'validate_password_confirm', 'param' => '');
}
if (is_array($errors)) {