function validateForm(&$errors) { global $username, $password, $rePassword; $errors = []; if (!validateRequired($username)) { $errors['username'][] = 'User Name is required'; } else { if (!validateLen($username, 4)) { $errors['username'][] = 'User Name must be at least 4 characters long'; } } if (!validateRequired($password)) { $errors['password'][] = 'Password is required'; } else { if (!validateLen($password, 5)) { $errors['password'][] = 'Password must be at least 5 characters long'; } if (!validateNonAlphaNumeric($password)) { $errors['password'][] = 'Password must contain at least 1 non alphanumeric character'; } if ($password !== $rePassword) { $errors['rePassword'][] = 'Password not match'; } } return empty($errors); }
function validateData() { $required = $_GET["required"]; $type = $_GET["type"]; $value = $_GET["value"]; validateRequired($required, $value, $type); switch ($type) { case 'number': validateNumber($value); break; case 'alphanum': validateAlphanum($value); break; case 'alpha': validateAlpha($value); break; case 'date': validateDate($value); break; case 'email': validateEmail($value); break; case 'url': validateUrl($value); case 'all': validateAll($value); break; } }
function detailsValidation(&$errors) { global $firstName, $lastName, $day, $month, $year; $errors = []; if (!validateRequired($firstName)) { $errors['firstname'][] = 'First Name is required'; } else { if (!validateLongerOrEqualString($firstName, 2)) { $errors['firstname'][] = 'First Name must be at least 2 characters long'; } } if (!validateRequired($lastName)) { $errors['lastname'][] = 'Last Name is required'; } else { if (!validateLongerOrEqualString($lastName, 2)) { $errors['lastname'][] = 'Last Name must be at least 2 characters long'; } } if (!validateRequired($month)) { $errors['DOBMonth'][] = 'Month is required'; } if (!validateRequired($day)) { $errors['DOBDay'][] = 'Day is required'; } if (!validateRequired($year)) { $errors['DOBYear'][] = 'Year is required'; } return empty($errors); }
function validateForm(&$errors) { global $firstName, $lastName, $birth_day, $birth_mount, $birth_year; $errors = []; if (!validateRequired($firstName)) { $errors['first_name'][] = 'First Name is required'; } else { if (!validateLen($firstName, 2)) { $errors['first_name'][] = 'First Name must be at least 2 characters long'; } } if (!validateRequired($lastName)) { $errors['last_name'][] = 'Last Name is required'; } else { if (!validateLen($lastName, 2)) { $errors['last_name'][] = 'Last Name must be at least 2 characters long'; } } if (!validateRequired($birth_day)) { $errors['birthDay'][] = 'Form Of Address is required'; } if (!validateRequired($birth_mount)) { $errors['birthMount'][] = 'Form Of Address is required'; } if (!validateRequired($birth_year)) { $errors['birthYear'][] = 'Form Of Address is required'; } return empty($errors); }
function validateForm(&$errors) { global $firstname, $surname, $birthdate; ## firstname ## if (!validateRequired($firstname)) { $errors['firstname'][] = 'First name is required.'; } else { if (!validateLength($firstname, 2)) { $errors['firstname'][] = 'Minimum length is 2.'; } } ## surname ## if (!validateRequired($surname)) { $errors['surname'][] = 'Surname is required.'; } else { if (!validateLength($surname, 2)) { $errors['surname'][] = 'Minimum length is 2.'; } } ## date ## if (!validateRequired($birthdate)) { $errors['birthdate'][] = 'Date of Birth is required.'; } else { if (!validateDate($birthdate)) { $errors['birthdate'][] = 'Wrong date.'; } } ## return ## return empty($errors) ? true : false; }
function validateForm(&$errors) { global $username, $password, $confirm_password; $errors = []; if (!validateRequired($username)) { $errors['username'][] = 'Username is required'; } else { if (!validateLongerOrEqualString($username, 4)) { $errors['username'][] = 'Username must be at least 4 characters long'; } } if (!validateRequired($password)) { $errors['password'][] = 'Password is required'; } else { if (!validateLongerOrEqualString($password, 5)) { $errors['password'][] = 'Password must be at least 5 characters long'; } else { if (!validateNonAlphaNumeric($password)) { $errors['password'][] = 'Password must contain at least 1 non alphanumeric character'; } } } if ($confirm_password !== $password) { $errors['confirm_password'][] = 'Password and Confirm Password doesn\'t match'; } return empty($errors); }
function validateSecondForm(&$errors) { global $month, $day, $year, $user_format; if (!validateRequired($month)) { $errors['month'][] = 'Please enter a month.'; } else { if (!validateNumeric($month)) { $errors['month'][] = 'This must be a number!'; } } if (!validateRequired($day)) { $errors['day'][] = 'Please enter a day.'; } else { if (!validateNumeric($day)) { $errors['day'][] = 'This must be a number!'; } } if (!validateRequired($year)) { $errors['year'][] = 'Please enter a year.'; } else { if (!validateNumeric($year)) { $errors['year'][] = 'This must be a number!'; } } if (!validateRequired($user_format)) { $errors['user_format'][] = 'Please enter the format!'; } return empty($errors); }
function validateForm(&$error) { global $number, $numbersArray; $error = []; if (!validateRequired($number)) { $error['number'][] = 'Number can not be null.'; } if (count($numbersArray) > 10) { $error['count'][] = 'Number must be 10'; } return empty($error); }
function validateForm(&$errors) { global $temperature, $conversion; if (!validateRequired($temperature)) { $errors['temperature'][] = 'Please enter the temperature.'; } else { if (!validateNumeric($temperature)) { $errors['temperature'][] = 'This must be a number!'; } } return empty($errors); }
function validateForm(&$error) { global $inputTemperature, $temperature; $error = []; if (!validateRequired($temperature)) { $error['temperature'][] = 'Temperature can not be null.'; } if (!validateRequired($inputTemperature)) { $error['inputTemperature'][] = 'Choosing temperature type is required'; } return empty($error); }
function validateForm(&$errors) { global $firstNumber, $secondNumber, $chooseAction; $errors = []; foreach (['firstNumber', 'secondNumber'] as $value) { if (!validateRequired(${$value})) { $errors[$value][] = "Number is required"; } } if (!validateRequired($chooseAction)) { $errors['chooseAction'][] = "Action is required"; } return empty($errors); }
function validateForm(&$errors) { global $product, $brand, $size, $gender, $quantity; $errors = []; foreach (['product', 'brand', 'gender', 'size', 'quantity'] as $value) { if (!validateRequired(${$value})) { $errors[$value][] = "{$value} is required"; } if (!validateString(${$value})) { $errors[$value][] = "{$value} must be a string"; } } return empty($errors); }
function validateForm(&$errors) { global $firstname, $lastname, $day, $month, $year; $errors = []; foreach (['firstname', 'lastname', 'day', 'month', 'year'] as $value) { if (!validateRequired(${$value})) { $errors[$value][] = "{$value} is required"; } if (!validateString(${$value})) { $errors[$value][] = "{$value} must be a string"; } } return empty($errors); }
function validateForm(&$errors) { global $number, $op; ## num1 ## if (!validateRequired($number)) { $errors['num1'][] = 'Temperature 1 is required.'; } else { if (!validateNumber($number)) { $errors['num1'][] = 'Temperature must be a number.'; } } ## op ## if (!validateRequired($op)) { $errors['op'][] = 'Operation is required.'; } else { if (!validateNumber($op)) { $errors['op'][] = 'Pls no hackerino.'; } } ## math ## if (empty($errors)) { switch ($op) { case 1: $result = $number * (9 / 5) + 32; break; case 2: $result = ($number - 32) * (5 / 9); break; default: $result = false; } if (is_float($result)) { $result = round($result, 2); } if ($op == 1) { $result .= '℉'; } else { if ($op == 2) { $result .= '℃'; } } } else { $result = false; } ## return ## return $result; }
function validateForm(&$errors) { global $username, $password1, $password2; ## username ## if (!validateRequired($username)) { $errors['username'][] = 'Username is required.'; } else { if (!validateLength($username, 4)) { $errors['username'][] = 'Minimum username length is 4.'; } } ## password1 ## if (!validateRequired($password1)) { $errors['password1'][] = 'Password is required.'; } else { if (!validateLength($password1, 6)) { $errors['password1'][] = 'Minimum password length is 6.'; } else { if (!validateNonAlphaNum($password1)) { $errors['password1'][] = 'Password must contain at least 1 non-alphanumeric character.'; } else { if (!validateIdentical($password1, $password2)) { $errors['password1'][] = 'Passwords don\'t match.'; } } } } ## password2 ## if (!validateRequired($password2)) { $errors['password2'][] = 'Password is required.'; } else { if (!validateLength($password2, 6)) { $errors['password2'][] = 'Minimum password length is 6.'; } else { if (!validateNonAlphaNum($password2)) { $errors['password2'][] = 'Password must contain at least 1 non-alphanumeric character.'; } else { if (!validateIdentical($password1, $password2)) { $errors['password2'][] = 'Passwords don\'t match.'; } } } } ## return ## return empty($errors) ? true : false; }
function validateForm(&$errors) { global $character; $errors = []; foreach (['character'] as $value) { if (!validateRequired(${$value})) { $errors[$value][] = "{$value} is required"; } if (!validateString(${$value})) { $errors[$value][] = "{$value} must be a string"; } } if (!validateEqualString($character, 1)) { $errors['character'][] = "You must enter a single character"; } return empty($errors); }
function calculate() { global $firstInput, $secondInput, $operation, $result, $validationErrors; if (!validateRequired($firstInput)) { $validationErrors['firstInput'][] = 'First number is required'; } else { if (preg_match('/[^0-9]/', $firstInput)) { $validationErrors['firstInput'][] = 'Please, enter numbers only'; } } if (!validateRequired($secondInput)) { $validationErrors['secondInput'][] = 'Second number is required'; } else { if (preg_match('/[^0-9]/', $secondInput)) { $validationErrors['secondInput'][] = 'Please, enter numbers only'; } else { if ($secondInput == 0 && $operation == '/') { $validationErrors['secondInput'][] = 'The divisor cannot be zero'; } } } if (!validateRequired($operation)) { $validationErrors['operation'][] = 'Operation is required'; } if ($operation == '+') { $result = $firstInput + $secondInput; } else { if ($operation == '-') { $result = $firstInput - $secondInput; } else { if ($operation == '*') { $result = $firstInput * $secondInput; } else { if ($operation == '/') { $result = $firstInput / $secondInput; } else { $result = 100; } } } } return $result; }
function validateForm(&$errors) { global $firstNumber, $secondNumber, $operation; if (!validateRequired($firstNumber)) { $errors['firstNumber'][] = 'Please enter a number.'; } else { if (!validateNumeric($firstNumber)) { $errors['firstNumber'][] = 'This must be a number!'; } } if (!validateRequired($secondNumber)) { $errors['secondNumber'][] = 'Please enter a number.'; } else { if (!validateNumeric($secondNumber)) { $errors['secondNumber'][] = 'This must be a number!'; } } return empty($errors); }
function validateForm(&$errors) { global $firstName, $lastName, $username, $password, $gender, $formOfAddress; $errors = []; if (!validateRequired($firstName)) { $errors['firstName'][] = 'First Name is required'; } else { if (!validateLongerOrEqualString($firstName, 2)) { $errors['firstName'][] = 'First Name must be at least 2 characters long'; } } if (!validateRequired($lastName)) { $errors['lastName'][] = 'Last Name is required'; } else { if (!validateLongerOrEqualString($lastName, 2)) { $errors['lastName'][] = 'Last Name must be at least 2 characters long'; } } if (!validateRequired($username)) { $errors['username'][] = 'User Name is required'; } else { if (!validateLongerOrEqualString($username, 4)) { $errors['username'][] = 'User Name must be at least 4 characters long'; } } if (!validateRequired($password)) { $errors['password'][] = 'Password is required'; } else { if (!validateLongerOrEqualString($password, 5)) { $errors['password'][] = 'Password must be at least 5 characters long'; } if (!validateNonAlphaNumeric($password)) { $errors['password'][] = 'Password must contain at least 1 non alphanumeric character'; } } if (!validateRequired($gender)) { $errors['gender'][] = 'Gender is required'; } if (!validateRequired($formOfAddress)) { $errors['form_of_address'][] = 'Form Of Address is required'; } return empty($errors); }
function calc() { global $first, $second, $sing, $validationErrors; if (!validateRequired($first)) { $validationErrors['firstNumber'][] = 'Field is required'; } else { if (preg_match('/[^0-9]/i', $first)) { $validationErrors['firstNumber'][] = 'wrong input value, value must by number'; } } if (!validateRequired($second)) { $validationErrors['secondNumber'][] = 'Field is required'; } else { if (preg_match('/[^0-9]/i', $second)) { $validationErrors['secondNumber'][] = 'wrong input value, value must by number'; } } if (!validateRequired($sing)) { $validationErrors['mathSing'][] = 'Field is required'; } switch ($sing) { case 1: $result = $first + $second; $sing = '+'; break; case 2: $result = $first - $second; $sing = '-'; break; case 3: $result = $first / $second; $sing = '/'; break; case 4: $result = $first * $second; $sing = '*'; break; default: $result = null; } return array($result, $sing); }
function validateForm(&$errors) { global $username, $password, $reppassword; if (!validateRequired($username)) { $errors['username'][] = 'User Name is required.'; } else { if (!validateLongerOrEqualString($username, 4)) { $errors['username'][] = 'Last Name must be at least 4 characters.'; } } if (!validateRequired($password)) { $errors['password'][] = 'Password is required.'; } else { if (!validateLongerOrEqualString($password, 4)) { $errors['password'][] = 'Password must be at least 4 characters.'; } if (!validateNonAlphanumeric($password)) { $errors['password'][] = 'Password must contain one non-alphanumeric character.'; } } if (!validateRequired($reppassword)) { $errors['reppassword'][] = 'Repeat Password is required.'; } else { if (!validateLongerOrEqualString($password, 4)) { $errors['reppassword'][] = 'Password must be at least 4 characters.'; } if (!validateNonAlphanumeric($password)) { $errors['reppassword'][] = 'Password must contain one non-alphanumeric character.'; } if (validateRequired($reppassword)) { if (!validateMatchingPasswords($password, $reppassword)) { $errors['reppassword'][] = "Password do not match!"; } else { $password = md5($password); } } else { $errors['reppassword'][] = 'Password needs to be filled!'; } } }
function validateForm(&$errors) { global $username, $password, $confirmPassword; $errors = []; foreach (['username', 'password'] as $value) { if (!validateRequired(${$value})) { $errors[$value][] = "{$value} is required"; } if (!validateString(${$value})) { $errors[$value][] = "{$value} must be a string"; } } if (!validateRequired($confirmPassword)) { $errors['confirmPassword'][] = '"Confirm Password" is required'; } if (!validateString($confirmPassword)) { $errors['confirmPassword'][] = "\"Confirm Password\" must be a string"; } if (!validateLongerOrEqualString($username, 6)) { $errors['username'][] = "Username must be minimum 6 symbols long"; } if (!validateLongerOrEqualString($password, 8)) { $errors['password'][] = "Password must be minimum 6 symbols long"; } if (!validateNonAlphaNumeric($password)) { $errors['password'][] = 'Password must contain at least 1 non alphanumeric character'; } if (!validateLongerOrEqualString($confirmPassword, 8)) { $errors['confirmPassword'][] = "Password must be minimum 6 symbols long"; } if (!validateNonAlphaNumeric($confirmPassword)) { $errors['confirmPassword'][] = 'Password must contain at least 1 non alphanumeric character'; } if (strcmp($password, $confirmPassword) !== 0) { $errors['confirmPassword'][] = 'Confirm Password and Password must be equal'; } return empty($errors); }
function validateForm(&$errors) { global $string; ## string ## if (!validateRequired($string)) { $errors['string'][] = 'This field is required.'; } else { if (!validateSequence($string, 10)) { $errors['string'][] = 'Allowed symbols: <b>1234567890-,</b>'; } } ## math ## $result = false; if (empty($errors)) { $array = explode(',', $string); sort($array); $min = min($array); $max = max($array); $result = implode(', ', $array) . "<br>min = {$min} <br>max = {$max}"; } ## return ## return $result; }
<?php $user = new \HttpStub\Storage\FileStorage('users'); $usersArray = $user->readAll(); $errors = []; if (!empty($_POST['register'])) { if (!validateLen($_POST['first_name'], 3)) { $errors['first_name'][] = 'First name is required and length must be at least 3 chars'; } if (!validateLen($_POST['last_name'], 3)) { $errors['last_name'][] = 'Last name is required and length must be at least 3 chars'; } if (!validateLen($_POST['username'], 3)) { $errors['username'][] = 'Username is required and length must be at least 3 chars'; } if (!validateRequired($_POST['reg_email'])) { $errors['reg_email'][] = 'Email is required'; } if (!validateLen($_POST['reg_password'], 3)) { $errors['reg_password'][] = 'Password is required and length must be at least 3 chars'; } if (!confirmPassword($_POST['reg_password'], $_POST['reg_password_confirmation'])) { $errors['reg_password_confirmation'][] = 'Password doesn\'t match'; } else { $_POST['password'] = confirmPassword($_POST['reg_password'], $_POST['reg_password_confirmation']); } if (!$_POST['agree']) { $errors['agree'][] = 'You must check agree checkbox'; } if (!$errors) { $user->insert($_POST);
/** * * * @param bool $UserID * @throws Exception * @throws Gdn_UserException */ public function sso($UserID = false) { $this->permission('Garden.Users.Edit'); $ProviderModel = new Gdn_AuthenticationProviderModel(); $Form = new Gdn_Form(); if ($this->Request->isAuthenticatedPostBack()) { // Make sure everything has been posted. $Form->validateRule('ClientID', 'ValidateRequired'); $Form->validateRule('UniqueID', 'ValidateRequired'); if (!validateRequired($Form->getFormValue('Username')) && !validateRequired($Form->getFormValue('Email'))) { $Form->addError('Username or Email is required.'); } $Provider = $ProviderModel->getProviderByKey($Form->getFormValue('ClientID')); if (!$Provider) { $Form->addError(sprintf('%1$s "%2$s" not found.', t('Provider'), $Form->getFormValue('ClientID'))); } if ($Form->errorCount() > 0) { throw new Gdn_UserException($Form->errorString()); } // Grab the user. $User = false; if ($Email = $Form->getFormValue('Email')) { $User = Gdn::userModel()->GetByEmail($Email); } if (!$User && ($Username = $Form->getFormValue('Username'))) { $User = Gdn::userModel()->GetByUsername($Username); } if (!$User) { throw new Gdn_UserException(sprintf(t('User not found.'), strtolower(t(UserModel::SigninLabelCode()))), 404); } // Validate the user's password. $PasswordHash = new Gdn_PasswordHash(); $Password = $this->Form->getFormValue('Password', null); if ($Password !== null && !$PasswordHash->CheckPassword($Password, val('Password', $User), val('HashMethod', $User))) { throw new Gdn_UserException(t('Invalid password.'), 401); } // Okay. We've gotten this far. Let's save the authentication. $User = (array) $User; Gdn::userModel()->saveAuthentication(array('UserID' => $User['UserID'], 'Provider' => $Form->getFormValue('ClientID'), 'UniqueID' => $Form->getFormValue('UniqueID'))); $Row = Gdn::userModel()->getAuthentication($Form->getFormValue('UniqueID'), $Form->getFormValue('ClientID')); if ($Row) { $this->setData('Result', $Row); } else { throw new Gdn_UserException(t('There was an error saving the data.')); } } else { $User = Gdn::userModel()->getID($UserID); if (!$User) { throw notFoundException('User'); } $Result = Gdn::sql()->select('ua.ProviderKey', '', 'ClientID')->select('ua.ForeignUserKey', '', 'UniqueID')->select('ua.UserID')->select('p.Name')->select('p.AuthenticationSchemeAlias', '', 'Type')->from('UserAuthentication ua')->join('UserAuthenticationProvider p', 'ua.ProviderKey = p.AuthenticationKey')->where('UserID', $UserID)->get()->resultArray(); $this->setData('Result', $Result); } $this->render('Blank', 'Utility', 'Dashboard'); }
/** * * * @param array $User * @return bool|string * @since 2.1 */ public function validateSpamRegistration($User) { $DiscoveryText = val('DiscoveryText', $User); $Log = validateRequired($DiscoveryText); $Spam = SpamModel::isSpam('Registration', $User, ['Log' => $Log]); if ($Spam) { if ($Log) { // The user entered discovery text. return self::REDIRECT_APPROVE; } else { $this->Validation->addValidationResult('DiscoveryText', 'Tell us why you want to join!'); return false; } } return true; }
/** * Connect the user with an external source. * * This controller method is meant to be used with plugins that set its data array to work. * Events: ConnectData * * @since 2.0.0 * @access public * * @param string $Method Used to register multiple providers on ConnectData event. */ public function connect($Method) { $this->addJsFile('entry.js'); $this->View = 'connect'; $IsPostBack = $this->Form->isPostBack() && $this->Form->getFormValue('Connect', null) !== null; $UserSelect = $this->Form->getFormValue('UserSelect'); if (!$IsPostBack) { // Here are the initial data array values. that can be set by a plugin. $Data = array('Provider' => '', 'ProviderName' => '', 'UniqueID' => '', 'FullName' => '', 'Name' => '', 'Email' => '', 'Photo' => '', 'Target' => $this->target()); $this->Form->setData($Data); $this->Form->addHidden('Target', $this->Request->get('Target', '/')); } // The different providers can check to see if they are being used and modify the data array accordingly. $this->EventArguments = array($Method); // Fire ConnectData event & error handling. $currentData = $this->Form->formValues(); // Filter the form data for users here. SSO plugins must reset validated data each postback. $filteredData = Gdn::userModel()->filterForm($currentData, true); $filteredData = array_replace($filteredData, arrayTranslate($currentData, ['TransientKey', 'hpt'])); unset($filteredData['Roles'], $filteredData['RoleID']); $this->Form->formValues($filteredData); try { $this->EventArguments['Form'] = $this->Form; $this->fireEvent('ConnectData'); $this->fireEvent('AfterConnectData'); } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); return $this->render('ConnectError'); } catch (Exception $Ex) { if (Debug()) { $this->Form->addError($Ex); } else { $this->Form->addError('There was an error fetching the connection data.'); } return $this->render('ConnectError'); } if (!UserModel::noEmail()) { if (!$this->Form->getFormValue('Email') || $this->Form->getFormValue('EmailVisible')) { $this->Form->setFormValue('EmailVisible', true); $this->Form->addHidden('EmailVisible', true); if ($IsPostBack) { $this->Form->setFormValue('Email', val('Email', $currentData)); } } } $FormData = $this->Form->formValues(); // debug // Make sure the minimum required data has been provided to the connect. if (!$this->Form->getFormValue('Provider')) { $this->Form->addError('ValidateRequired', t('Provider')); } if (!$this->Form->getFormValue('UniqueID')) { $this->Form->addError('ValidateRequired', t('UniqueID')); } if (!$this->data('Verified')) { // Whatever event handler catches this must Set the data 'Verified' to true to prevent a random site from connecting without credentials. // This must be done EVERY postback and is VERY important. $this->Form->addError('The connection data has not been verified.'); } if ($this->Form->errorCount() > 0) { return $this->render(); } $UserModel = Gdn::userModel(); // Check to see if there is an existing user associated with the information above. $Auth = $UserModel->getAuthentication($this->Form->getFormValue('UniqueID'), $this->Form->getFormValue('Provider')); $UserID = val('UserID', $Auth); // Check to synchronise roles upon connecting. if (($this->data('Trusted') || c('Garden.SSO.SyncRoles')) && $this->Form->getFormValue('Roles', null) !== null) { $SaveRoles = $SaveRolesRegister = true; // Translate the role names to IDs. $Roles = $this->Form->getFormValue('Roles', null); $Roles = RoleModel::getByName($Roles); $RoleIDs = array_keys($Roles); if (empty($RoleIDs)) { // The user must have at least one role. This protects that. $RoleIDs = $this->UserModel->newUserRoleIDs(); } if (c('Garden.SSO.SyncRolesBehavior') === 'register') { $SaveRoles = false; } $this->Form->setFormValue('RoleID', $RoleIDs); } else { $SaveRoles = false; $SaveRolesRegister = false; } if ($UserID) { // The user is already connected. $this->Form->setFormValue('UserID', $UserID); if (c('Garden.Registration.ConnectSynchronize', true)) { $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY); $Data = $this->Form->formValues(); // Don't overwrite the user photo if the user uploaded a new one. $Photo = val('Photo', $User); if (!val('Photo', $Data) || $Photo && !isUrl($Photo)) { unset($Data['Photo']); } // Synchronize the user's data. $UserModel->save($Data, array('NoConfirmEmail' => true, 'FixUnique' => true, 'SaveRoles' => $SaveRoles)); } // Always save the attributes because they may contain authorization information. if ($Attributes = $this->Form->getFormValue('Attributes')) { $UserModel->saveAttribute($UserID, $Attributes); } // Sign the user in. Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true)); Gdn::userModel()->fireEvent('AfterSignIn'); // $this->_setRedirect(TRUE); $this->_setRedirect($this->Request->get('display') == 'popup'); } elseif ($this->Form->getFormValue('Name') || $this->Form->getFormValue('Email')) { $NameUnique = c('Garden.Registration.NameUnique', true); $EmailUnique = c('Garden.Registration.EmailUnique', true); $AutoConnect = c('Garden.Registration.AutoConnect'); if ($IsPostBack && $this->Form->getFormValue('ConnectName')) { $searchName = $this->Form->getFormValue('ConnectName'); } else { $searchName = $this->Form->getFormValue('Name'); } // Get the existing users that match the name or email of the connection. $Search = false; if ($searchName && $NameUnique) { $UserModel->SQL->orWhere('Name', $searchName); $Search = true; } if ($this->Form->getFormValue('Email') && ($EmailUnique || $AutoConnect)) { $UserModel->SQL->orWhere('Email', $this->Form->getFormValue('Email')); $Search = true; } if (is_numeric($UserSelect)) { $UserModel->SQL->orWhere('UserID', $UserSelect); $Search = true; } if ($Search) { $ExistingUsers = $UserModel->getWhere()->resultArray(); } else { $ExistingUsers = array(); } // Check to automatically link the user. if ($AutoConnect && count($ExistingUsers) > 0) { if ($IsPostBack && $this->Form->getFormValue('ConnectName')) { $this->Form->setFormValue('Name', $this->Form->getFormValue('ConnectName')); } foreach ($ExistingUsers as $Row) { if (strcasecmp($this->Form->getFormValue('Email'), $Row['Email']) === 0) { $UserID = $Row['UserID']; $this->Form->setFormValue('UserID', $UserID); $Data = $this->Form->formValues(); if (c('Garden.Registration.ConnectSynchronize', true)) { // Don't overwrite a photo if the user has already uploaded one. $Photo = val('Photo', $Row); if (!val('Photo', $Data) || $Photo && !stringBeginsWith($Photo, 'http')) { unset($Data['Photo']); } $UserModel->save($Data, array('NoConfirmEmail' => true, 'FixUnique' => true, 'SaveRoles' => $SaveRoles)); } if ($Attributes = $this->Form->getFormValue('Attributes')) { $UserModel->saveAttribute($UserID, $Attributes); } // Save the userauthentication link. $UserModel->saveAuthentication(array('UserID' => $UserID, 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID'))); // Sign the user in. Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true)); Gdn::userModel()->fireEvent('AfterSignIn'); // $this->_setRedirect(TRUE); $this->_setRedirect($this->Request->get('display') == 'popup'); $this->render(); return; } } } $CurrentUserID = Gdn::session()->UserID; // Massage the existing users. foreach ($ExistingUsers as $Index => $UserRow) { if ($EmailUnique && $UserRow['Email'] == $this->Form->getFormValue('Email')) { $EmailFound = $UserRow; break; } if ($UserRow['Name'] == $this->Form->getFormValue('Name')) { $NameFound = $UserRow; } if ($CurrentUserID > 0 && $UserRow['UserID'] == $CurrentUserID) { unset($ExistingUsers[$Index]); $CurrentUserFound = true; } } if (isset($EmailFound)) { // The email address was found and can be the only user option. $ExistingUsers = array($UserRow); $this->setData('NoConnectName', true); } elseif (isset($CurrentUserFound)) { $ExistingUsers = array_merge(array('UserID' => 'current', 'Name' => sprintf(t('%s (Current)'), Gdn::session()->User->Name)), $ExistingUsers); } if (!isset($NameFound) && !$IsPostBack) { $this->Form->setFormValue('ConnectName', $this->Form->getFormValue('Name')); } $this->setData('ExistingUsers', $ExistingUsers); if (UserModel::noEmail()) { $EmailValid = true; } else { $EmailValid = validateRequired($this->Form->getFormValue('Email')); } if ((!$UserSelect || $UserSelect == 'other') && $this->Form->getFormValue('Name') && $EmailValid && (!is_array($ExistingUsers) || count($ExistingUsers) == 0)) { // There is no existing user with the suggested name so we can just create the user. $User = $this->Form->formValues(); $User['Password'] = randomString(50); // some password is required $User['HashMethod'] = 'Random'; $User['Source'] = $this->Form->getFormValue('Provider'); $User['SourceID'] = $this->Form->getFormValue('UniqueID'); $User['Attributes'] = $this->Form->getFormValue('Attributes', null); $User['Email'] = $this->Form->getFormValue('ConnectEmail', $this->Form->getFormValue('Email', null)); $UserID = $UserModel->register($User, array('CheckCaptcha' => false, 'ValidateEmail' => false, 'NoConfirmEmail' => true, 'SaveRoles' => $SaveRolesRegister)); $User['UserID'] = $UserID; $this->Form->setValidationResults($UserModel->validationResults()); if ($UserID) { $UserModel->saveAuthentication(array('UserID' => $UserID, 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID'))); $this->Form->setFormValue('UserID', $UserID); $this->Form->setFormValue('UserSelect', false); Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true)); Gdn::userModel()->fireEvent('AfterSignIn'); // Send the welcome email. if (c('Garden.Registration.SendConnectEmail', false)) { try { $UserModel->sendWelcomeEmail($UserID, '', 'Connect', array('ProviderName' => $this->Form->getFormValue('ProviderName', $this->Form->getFormValue('Provider', 'Unknown')))); } catch (Exception $Ex) { // Do nothing if emailing doesn't work. } } $this->_setRedirect(true); } } } // Save the user's choice. if ($IsPostBack) { // The user has made their decision. $PasswordHash = new Gdn_PasswordHash(); if (!$UserSelect || $UserSelect == 'other') { // The user entered a username. $ConnectNameEntered = true; if ($this->Form->validateRule('ConnectName', 'ValidateRequired')) { $ConnectName = $this->Form->getFormValue('ConnectName'); $User = false; if (c('Garden.Registration.NameUnique')) { // Check to see if there is already a user with the given name. $User = $UserModel->getWhere(array('Name' => $ConnectName))->firstRow(DATASET_TYPE_ARRAY); } if (!$User) { $this->Form->validateRule('ConnectName', 'ValidateUsername'); } } } else { // The user selected an existing user. $ConnectNameEntered = false; if ($UserSelect == 'current') { if (Gdn::session()->UserID == 0) { // This shouldn't happen, but a use could sign out in another browser and click submit on this form. $this->Form->addError('@You were unexpectedly signed out.'); } else { $UserSelect = Gdn::session()->UserID; } } $User = $UserModel->getID($UserSelect, DATASET_TYPE_ARRAY); } if (isset($User) && $User) { // Make sure the user authenticates. if (!$User['UserID'] == Gdn::session()->UserID) { if ($this->Form->validateRule('ConnectPassword', 'ValidateRequired', sprintf(t('ValidateRequired'), t('Password')))) { try { if (!$PasswordHash->checkPassword($this->Form->getFormValue('ConnectPassword'), $User['Password'], $User['HashMethod'], $this->Form->getFormValue('ConnectName'))) { if ($ConnectNameEntered) { $this->Form->addError('The username you entered has already been taken.'); } else { $this->Form->addError('The password you entered is incorrect.'); } } } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); } } } } elseif ($this->Form->errorCount() == 0) { // The user doesn't exist so we need to add another user. $User = $this->Form->formValues(); $User['Name'] = $User['ConnectName']; $User['Password'] = randomString(50); // some password is required $User['HashMethod'] = 'Random'; $UserID = $UserModel->register($User, array('CheckCaptcha' => false, 'NoConfirmEmail' => true, 'SaveRoles' => $SaveRolesRegister)); $User['UserID'] = $UserID; $this->Form->setValidationResults($UserModel->validationResults()); if ($UserID && c('Garden.Registration.SendConnectEmail', false)) { // Send the welcome email. $UserModel->sendWelcomeEmail($UserID, '', 'Connect', array('ProviderName' => $this->Form->getFormValue('ProviderName', $this->Form->getFormValue('Provider', 'Unknown')))); } } if ($this->Form->errorCount() == 0) { // Save the authentication. if (isset($User) && val('UserID', $User)) { $UserModel->saveAuthentication(array('UserID' => $User['UserID'], 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID'))); $this->Form->setFormValue('UserID', $User['UserID']); } // Sign the appropriate user in. Gdn::session()->start($this->Form->getFormValue('UserID'), true, (bool) $this->Form->getFormValue('RememberMe', true)); Gdn::userModel()->fireEvent('AfterSignIn'); $this->_setRedirect(true); } } $this->render(); }
/** * Validate that a value is one of the values allowed in an enum. * * @param mixed $value The value to validate. * @param object $field The object must contain an `Enum` property which is an array of valid choices for * {@link $value}. * @return bool Returns true of the value is valid or false otherwise. */ function validateEnum($value, $field) { return in_array($value, $field->Enum) || $field->AllowNull && !validateRequired($value); }
<head> <meta charset="UTF-8"> <title>Home2</title> </head> <body> <?php if ($_POST && validateRequired($name)) { ?> <p>Име: <?php echo $name; ?> <p>Парола: <?php echo passCheck($pass, $pass2); ?> <?php } elseif ($_POST && !validateRequired($name)) { ?> </p>Грешно въведено име.</p> <?php } ?> <form method="post"> <div> <label for="userName">User Name</label> <input type="text" id="userName" name="userName" > </div> <div> <label for="pass">Password</label> <input type="password" id="pass" name="pass" > </div> <div>
function ProcessItem($formid, $fvalue, $params, $output_type) { global $TOOL_SHORT; $PASS_VALUE = "ok"; $FAIL_VALUE = "error"; global $VALIDATE_TEXT; $failed = false; $VALIDATE_TEXT = ""; // clear before doing the validation if (!validateRequired($fvalue) && !array_key_exists("required", $params)) { // blank and not required return ""; } // do the validation foreach ($params as $value) { if ($failed) { break; } $type = $value; if (strpos($value, ";") !== false) { // get the special rule type $type = substr($value, 0, strpos($value, ";")); } writeLog($TOOL_SHORT, "ajax", "validate:" . $type . ":" . $fvalue); if ($type == "required" || $type == "notblank") { if (!validateRequired($fvalue)) { $failed = true; } } else { if ($type == "email") { if (!validateEmail($fvalue)) { $failed = true; } } else { if ($type == "phone") { if (!validatePhone($fvalue)) { $failed = true; } } else { if ($type == "date") { if (!validateDate($fvalue)) { $failed = true; } } else { if ($type == "time") { if (!validateTime($fvalue)) { $failed = true; } } else { if ($type == "zip" || $type == "zipcode") { if (!validateZip($fvalue)) { $failed = true; } } else { if ($type == "nospaces" || $type == "password") { if (!validateNoSpaces($fvalue)) { $failed = true; } } else { if ($type == "alpha") { if (!validateAlpha($fvalue)) { $failed = true; } } else { if ($type == "alphanum") { if (!validateAlphaNumeric($fvalue)) { $failed = true; } } else { if ($type == "number") { if (!validateNumeric($fvalue)) { $failed = true; } } else { if ($type == "name") { if (!validateAlphaName($fvalue)) { $failed = true; } } else { if ($type == "namespaces") { if (!validateAlphaNameSpaces($fvalue)) { $failed = true; } } else { if ($type == "uniquesql") { // should be uniquesql;(columnname);(tablename);(tableid);(userid) $parts = split(';', $value); if (!validateUniqueSQL($parts[1], $parts[2], $fvalue, $parts[3], $parts[4])) { $VALIDATE_TEXT = $formid . " already used"; $failed = true; } } else { if ($type == "uniqueinstp") { // should be uniqueinstp;(value);($field);(idval) $parts = split(';', $value); if (!validateUniqueInst($fvalue, $parts[1], $parts[2])) { $VALIDATE_TEXT = $formid . " already used"; $failed = true; } } else { if ($type == "uniqueuserp") { // should be uniqueuserp;(value);($field);(idval) $parts = split(';', $value); if (!validateUniqueUser($fvalue, $parts[1], $parts[2])) { $VALIDATE_TEXT = $formid . " already used"; $failed = true; } } } } } } } } } } } } } } } } } if ($output_type == "ajax") { $status = $PASS_VALUE; if ($failed) { $status = $FAIL_VALUE; } $ajaxReturn = "{$status}|{$formid}|{$VALIDATE_TEXT}"; echo $ajaxReturn; writeLog($TOOL_SHORT, "ajax", "return={$ajaxReturn}"); } else { if ($output_type == "print") { if ($failed) { print $VALIDATE_TEXT . "<br>"; } } else { if ($output_type == "array") { if ($failed) { return $VALIDATE_TEXT; } } } } // defaults to "return" if ($failed) { return $VALIDATE_TEXT . "<br>"; } return ""; }