Esempio n. 1
0
 /**
  * Check if a group alias is valid
  *
  * @param 		integer 	$cname 			Group alias
  * @param 		boolean		$allowDashes 	Allow dashes in cn
  * @return 		boolean		True if valid, false if not
  */
 private function _validCn($cn, $allowDashes = false)
 {
     $regex = '/^[0-9a-zA-Z]+[_0-9a-zA-Z]*$/i';
     if ($allowDashes) {
         $regex = '/^[0-9a-zA-Z]+[-_0-9a-zA-Z]*$/i';
     }
     if (\Hubzero\Utility\Validate::reserved('group', $cn)) {
         return false;
     }
     if (preg_match($regex, $cn)) {
         if (is_numeric($cn) && intval($cn) == $cn && $cn >= 0) {
             return false;
         } else {
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Check if a group exists.
  * Given the group id, returns true if group exists.
  *
  * @param   integer  $group         The group id number (GID) of the group being verified.
  * @param   boolean  $check_system  Boolean for checking against POSIX user.
  * @return  boolean  Returns false if group does not exist; true if group exists.
  */
 public static function exists($group, $check_system = false)
 {
     $db = \App::get('db');
     if (empty($group)) {
         return false;
     }
     if ($check_system) {
         if (is_numeric($group) && posix_getgrgid($group)) {
             return true;
         }
         if (!is_numeric($group) && posix_getgrnam($group)) {
             return true;
         }
     }
     // check reserved
     if (Validate::reserved('group', $group)) {
         return true;
     }
     if (is_numeric($group)) {
         $query = 'SELECT gidNumber FROM `#__xgroups` WHERE gidNumber=' . $db->quote($group);
     } else {
         $query = 'SELECT gidNumber FROM `#__xgroups` WHERE cn=' . $db->quote($group);
     }
     $db->setQuery($query);
     if (!$db->query()) {
         return false;
     }
     if ($db->loadResult() > 0) {
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Check data
  *
  * @param   string   $task
  * @param   integer  $id
  * @return  boolean
  */
 public function check($task = 'create', $id = 0, $field_to_check = array())
 {
     $sitename = Config::get('sitename');
     if ($id == 0) {
         $id = User::get('id');
     }
     $registration = $this->_registration;
     if ($task == 'proxy') {
         $task = 'proxycreate';
     }
     $this->_missing = array();
     $this->_invalid = array();
     $registrationUsername = $this->registrationField('registrationUsername', 'RROO', $task);
     $registrationPassword = $this->registrationField('registrationPassword', 'RRHH', $task);
     $registrationConfirmPassword = $this->registrationField('registrationConfirmPassword', 'RRHH', $task);
     $registrationFullname = $this->registrationField('registrationFullname', 'RRRR', $task);
     $registrationEmail = $this->registrationField('registrationEmail', 'RRRR', $task);
     $registrationConfirmEmail = $this->registrationField('registrationConfirmEmail', 'RRRR', $task);
     $registrationOptIn = $this->registrationField('registrationOptIn', 'HHHH', $task);
     $registrationCAPTCHA = $this->registrationField('registrationCAPTCHA', 'HHHH', $task);
     $registrationTOU = $this->registrationField('registrationTOU', 'HHHH', $task);
     if ($task == 'update') {
         if (empty($registration['login'])) {
             $registrationUsername = REG_REQUIRED;
         } else {
             $registrationUsername = REG_READONLY;
         }
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
         if (empty($registration['email'])) {
             $registrationEmail = REG_REQUIRED;
         }
     }
     if ($task == 'edit') {
         $registrationUsername = REG_READONLY;
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
     }
     if (User::get('auth_link_id') && $task == 'create') {
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
     }
     $login = $registration['login'];
     $email = $registration['email'];
     $confirmEmail = $registration['confirmEmail'];
     if ($registrationUsername == REG_REQUIRED) {
         if (empty($login)) {
             $this->_missing['login'] = '******';
             $this->_invalid['login'] = '******';
         }
     }
     if ($registrationUsername != REG_HIDE) {
         $allowNumericFirstCharacter = $task == 'update' ? true : false;
         if (!empty($login) && !Helpers\Utility::validlogin($login, $allowNumericFirstCharacter)) {
             $this->_invalid['login'] = '******';
         }
     }
     if (!empty($login) && ($task == 'create' || $task == 'proxycreate' || $task == 'update')) {
         $uid = User::getInstance($login)->get('id');
         if ($uid && $uid != $id) {
             $this->_invalid['login'] = '******' . htmlentities($login) . '" already exists. Please try another.';
         }
         if (\Hubzero\Utility\Validate::reserved('username', $login)) {
             $this->_invalid['login'] = '******' . htmlentities($login) . '" already exists. Please try another.';
         }
         // system username check
         $puser = posix_getpwnam($login);
         if (!empty($puser) && $uid && $uid != $puser['uid']) {
             // log error and display error to user
             \Log::error('System username/userid does not match DB username/password for user: '******'login'] = '******';
         }
     }
     if ($registrationPassword == REG_REQUIRED) {
         if (empty($registration['password'])) {
             $this->_missing['password'] = '******';
             $this->_invalid['password'] = '******';
         }
     }
     /*
     if ($registrationPassword != REG_HIDE)
     {
     	if (!empty($registration['password']))
     	{
     		$result = Helpers\Utility::valid_password($registration['password']);
     
     		if ($result)
     			$this->_invalid['password'] = $result;
     	}
     }
     */
     if ($registrationConfirmPassword == REG_REQUIRED) {
         if (empty($registration['confirmPassword'])) {
             $this->_missing['confirmPassword'] = '******';
             $this->_invalid['confirmPassword'] = '******';
         }
     }
     if ($registrationPassword != REG_HIDE && $registrationConfirmPassword != REG_HIDE) {
         if ($registration['password'] != $registration['confirmPassword']) {
             $this->_invalid['confirmPassword'] = '******';
         }
     }
     if ($registrationPassword == REG_REQUIRED) {
         $score = $this->scorePassword($registration['password'], $registration['login']);
         if ($score < PASS_SCORE_MEDIOCRE) {
             $this->_invalid['password'] = '******';
         } else {
             if ($score >= PASS_SCORE_MEDIOCRE && $score < PASS_SCORE_GOOD) {
                 // Mediocre pass
             } else {
                 if ($score >= PASS_SCORE_GOOD && $score < PASS_SCORE_STRONG) {
                     // Good pass
                 } else {
                     if ($score >= PASS_SCORE_STRONG) {
                         // Strong pass
                     }
                 }
             }
         }
         $rules = \Hubzero\Password\Rule::all()->whereEquals('enabled', 1)->rows();
         $msg = \Hubzero\Password\Rule::verify($registration['password'], $rules, $login, $registration['name']);
         if (!empty($msg)) {
             $this->_invalid['password'] = $msg;
         }
     }
     if ($registrationFullname == REG_REQUIRED) {
         if (empty($registration['name'])) {
             $this->_missing['name'] = 'Full Name';
             $this->_invalid['name'] = 'Please provide a name.';
         } else {
             $bits = explode(' ', $registration['name']);
             $surname = null;
             $middleName = null;
             $givenName = null;
             if (count($bits) == 1) {
                 $givenName = array_shift($bits);
             } else {
                 $surname = array_pop($bits);
                 if (count($bits) >= 1) {
                     $givenName = array_shift($bits);
                 }
                 if (count($bits) >= 1) {
                     $middleName = implode(' ', $bits);
                 }
             }
             if (!$givenName || !$surname) {
                 $this->_missing['name'] = 'Full Name';
                 $this->_invalid['name'] = 'Please provide a name.';
             }
         }
     }
     if ($registrationFullname != REG_HIDE) {
         if (!empty($registration['name']) && !Helpers\Utility::validname($registration['name'])) {
             $this->_invalid['name'] = 'Invalid name. You may be using characters that are not allowed.';
         }
     }
     if ($registrationEmail == REG_REQUIRED) {
         if (empty($email)) {
             $this->_missing['email'] = 'Valid Email';
             $this->_invalid['email'] = 'Please provide a valid e-mail address.';
         }
     }
     if ($registrationEmail != REG_HIDE) {
         if (empty($email)) {
             $this->_missing['email'] = 'Valid Email';
         } elseif (!Helpers\Utility::validemail($email)) {
             $this->_invalid['email'] = 'Invalid email address. Please correct and try again.';
         } else {
             $usersConfig = \Component::params('com_users');
             $allow_duplicate_emails = $usersConfig->get('allow_duplicate_emails');
             // Check if the email is already in use
             $row = \Hubzero\User\User::all()->whereEquals('email', $email)->where('id', '!=', (int) $id)->row();
             $xid = intval($row->get('id'));
             // 0 = not allowed
             // 1 = allowed (i.e. no check needed)
             // 2 = only existing accounts (grandfathered)
             if ($xid && ($allow_duplicate_emails == 0 || $allow_duplicate_emails == 2)) {
                 if ($allow_duplicate_emails == 0) {
                     $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                 } else {
                     if ($allow_duplicate_emails == 2) {
                         // If duplicates are only allowed in grandfathered accounts,
                         // then new accounts shouldn't be created with the same email.
                         if ($task == 'create' || $task == 'proxycreate') {
                             $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                         } else {
                             // We also need to catch existing users who might try to change their
                             // email to an existing email address on the hub. For that, we need to
                             // check and see if their email address is changing with this save.
                             $row = \Hubzero\User\User::oneOrNew((int) $id);
                             $currentEmail = $row->get('email');
                             if ($currentEmail != $email) {
                                 $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($registrationConfirmEmail == REG_REQUIRED) {
         if (empty($confirmEmail) && empty($this->_invalid['email'])) {
             $this->_missing['confirmEmail'] = 'Valid Email Confirmation';
             $this->_invalid['confirmEmail'] = 'Please provide a valid e-mail address again.';
         }
     }
     if ($registrationConfirmEmail != REG_HIDE) {
         if ($email != $confirmEmail) {
             if (empty($this->_invalid['email'])) {
                 $this->_invalid['confirmEmail'] = 'Email addresses do not match. Please correct and try again.';
                 $this->_invalid['email'] = 'Email addresses do not match. Please correct and try again.';
             }
         }
     }
     if ($registrationOptIn == REG_REQUIRED) {
         if (is_null($registration['sendEmail']) || intval($registration['sendEmail']) < 0) {
             $this->_missing['sendEmail'] = 'Receive Email Updates';
             $this->_invalid['sendEmail'] = 'Receive Email Updates has not been selected';
         }
     }
     if ($registrationCAPTCHA == REG_REQUIRED) {
         $botcheck = Request::getVar('botcheck', '');
         if ($botcheck) {
             $this->_invalid['captcha'] = 'Error: Invalid CAPTCHA response.';
         }
         $validcaptchas = Event::trigger('captcha.onCheckAnswer');
         if (count($validcaptchas) > 0) {
             foreach ($validcaptchas as $validcaptcha) {
                 if (!$validcaptcha) {
                     $this->_invalid['captcha'] = 'Error: Invalid CAPTCHA response.';
                 }
             }
         }
     }
     if ($registrationTOU == REG_REQUIRED) {
         if (empty($registration['usageAgreement'])) {
             $this->_missing['usageAgreement'] = 'Usage Agreement';
             $this->_invalid['usageAgreement'] = 'Registration requires acceptance of the usage agreement';
         }
     }
     /* Everything below is currently done elsewhere
     		   @TODO  Move code to here or refactor?
     
     		if ($registrationAddress == REG_REQUIRED)
     		{
     			if (count($registration['address']) == 0)
     			{
     				$this->_missing['address'] = 'Member Address';
     				$this->_invalid['address'] = 'Member Address';
     			}
     		}
     
     		// Load all fields not hidden
     		$fields = Field::all()
     			->including(['options', function ($option){
     				$option
     					->select('*')
     					->ordered();
     			}])
     			->where('action_' . $task, '!=', Field::STATE_HIDDEN)
     			->ordered()
     			->rows();
     
     		if (!isset($registration['_profile']))
     		{
     			$registration['_profile'] = array();
     		}
     
     		// Find missing required fields
     		foreach ($fields as $field)
     		{
     			if ($field->get('type') != 'hidden')
     			{
     				if (!isset($registration['_profile'][$field->get('name')]))
     				{
     					continue;
     				}
     
     				$value = $registration['_profile'][$field->get('name')];
     
     				if (empty($value) && $field->get('action_' . $task) == Field::STATE_REQUIRED)
     				{
     					$this->_missing[$field->get('name')] = $field->get('label');
     				}
     			}
     		}
     
     		// Validate input
     		$form = new \Hubzero\Form\Form('profile', array('control' => 'profile'));
     		$form->load(Field::toXml($fields, $action));
     		$form->bind(new \Hubzero\Config\Registry($registration['_profile']));
     
     		if (!$form->validate($registration['_profile']))
     		{
     			foreach ($form->getErrors() as $error)
     			{
     				$this->_invalid[] = $error;
     			}
     		}*/
     // Filter out fields
     if (!empty($field_to_check)) {
         if ($this->_missing) {
             foreach ($this->_missing as $k => $v) {
                 if (!in_array($k, $field_to_check)) {
                     unset($this->_missing[$k]);
                 }
             }
         }
         if ($this->_invalid) {
             foreach ($this->_invalid as $k => $v) {
                 if (!in_array($k, $field_to_check)) {
                     unset($this->_invalid[$k]);
                 }
             }
         }
     }
     if (empty($this->_missing) && empty($this->_invalid)) {
         return true;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Short description for 'check'
  *
  * Long description (if any) ...
  *
  * @param      string $task Parameter description (if any) ...
  * @param      integer $id Parameter description (if any) ...
  * @return     boolean Return description (if any) ...
  */
 public function check($task = 'create', $id = 0, $field_to_check = array())
 {
     $sitename = Config::get('sitename');
     if ($id == 0) {
         $id = User::get('id');
     }
     $registration = $this->_registration;
     if ($task == 'proxy') {
         $task = 'proxycreate';
     }
     $this->_missing = array();
     $_invalid = array();
     $registrationUsername = $this->registrationField('registrationUsername', 'RROO', $task);
     $registrationPassword = $this->registrationField('registrationPassword', 'RRHH', $task);
     $registrationConfirmPassword = $this->registrationField('registrationConfirmPassword', 'RRHH', $task);
     $registrationFullname = $this->registrationField('registrationFullname', 'RRRR', $task);
     $registrationEmail = $this->registrationField('registrationEmail', 'RRRR', $task);
     $registrationConfirmEmail = $this->registrationField('registrationConfirmEmail', 'RRRR', $task);
     $registrationURL = $this->registrationField('registrationURL', 'HHHH', $task);
     $registrationPhone = $this->registrationField('registrationPhone', 'HHHH', $task);
     $registrationEmployment = $this->registrationField('registrationEmployment', 'HHHH', $task);
     $registrationOrganization = $this->registrationField('registrationOrganization', 'HHHH', $task);
     $registrationCitizenship = $this->registrationField('registrationCitizenship', 'HHHH', $task);
     $registrationResidency = $this->registrationField('registrationResidency', 'HHHH', $task);
     $registrationSex = $this->registrationField('registrationSex', 'HHHH', $task);
     $registrationDisability = $this->registrationField('registrationDisability', 'HHHH', $task);
     $registrationHispanic = $this->registrationField('registrationHispanic', 'HHHH', $task);
     $registrationRace = $this->registrationField('registrationRace', 'HHHH', $task);
     $registrationInterests = $this->registrationField('registrationInterests', 'HHHH', $task);
     $registrationReason = $this->registrationField('registrationReason', 'HHHH', $task);
     $registrationOptIn = $this->registrationField('registrationOptIn', 'HHHH', $task);
     $registrationCAPTCHA = $this->registrationField('registrationCAPTCHA', 'HHHH', $task);
     $registrationTOU = $this->registrationField('registrationTOU', 'HHHH', $task);
     $registrationAddress = $this->registrationField('registrationAddress', 'OOOO', $task);
     $registrationORCID = $this->registrationField('registrationORCID', 'HHHO', $task);
     if ($task == 'update') {
         if (empty($registration['login'])) {
             $registrationUsername = REG_REQUIRED;
         } else {
             $registrationUsername = REG_READONLY;
         }
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
         if (empty($registration['email'])) {
             $registrationEmail = REG_REQUIRED;
         }
     }
     if ($task == 'edit') {
         $registrationUsername = REG_READONLY;
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
     }
     if (User::get('auth_link_id') && $task == 'create') {
         $registrationPassword = REG_HIDE;
         $registrationConfirmPassword = REG_HIDE;
     }
     $login = $registration['login'];
     $email = $registration['email'];
     $confirmEmail = $registration['confirmEmail'];
     if ($registrationUsername == REG_REQUIRED) {
         if (empty($login)) {
             $this->_missing['login'] = '******';
             $this->_invalid['login'] = '******';
         }
     }
     if ($registrationUsername != REG_HIDE) {
         $allowNumericFirstCharacter = $task == 'update' ? true : false;
         if (!empty($login) && !Helpers\Utility::validlogin($login, $allowNumericFirstCharacter)) {
             $this->_invalid['login'] = '******';
         }
     }
     if (!empty($login) && ($task == 'create' || $task == 'proxycreate' || $task == 'update')) {
         jimport('joomla.user.helper');
         $uid = \JUserHelper::getUserId($login);
         if ($uid && $uid != $id) {
             $this->_invalid['login'] = '******' . htmlentities($login) . '" already exists. Please try another.';
         }
         if (\Hubzero\Utility\Validate::reserved('username', $login)) {
             $this->_invalid['login'] = '******' . htmlentities($login) . '" already exists. Please try another.';
         }
         // system username check
         $puser = posix_getpwnam($login);
         if (!empty($puser) && $uid && $uid != $puser['uid']) {
             // log error and display error to user
             \Log::error('System username/userid does not match DB username/password for user: '******'login'] = '******';
         }
     }
     if ($registrationPassword == REG_REQUIRED) {
         if (empty($registration['password'])) {
             $this->_missing['password'] = '******';
             $this->_invalid['password'] = '******';
         }
     }
     /*
     if ($registrationPassword != REG_HIDE)
     {
     	if (!empty($registration['password']))
     	{
     		$result = Helpers\Utility::valid_password($registration['password']);
     
     		if ($result)
     			$this->_invalid['password'] = $result;
     	}
     }
     */
     if ($registrationConfirmPassword == REG_REQUIRED) {
         if (empty($registration['confirmPassword'])) {
             $this->_missing['confirmPassword'] = '******';
             $this->_invalid['confirmPassword'] = '******';
         }
     }
     if ($registrationPassword != REG_HIDE && $registrationConfirmPassword != REG_HIDE) {
         if ($registration['password'] != $registration['confirmPassword']) {
             $this->_invalid['confirmPassword'] = '******';
         }
     }
     if ($registrationPassword == REG_REQUIRED) {
         $score = $this->scorePassword($registration['password'], $registration['login']);
         if ($score < PASS_SCORE_MEDIOCRE) {
             $this->_invalid['password'] = '******';
         } else {
             if ($score >= PASS_SCORE_MEDIOCRE && $score < PASS_SCORE_GOOD) {
                 // Mediocre pass
             } else {
                 if ($score >= PASS_SCORE_GOOD && $score < PASS_SCORE_STRONG) {
                     // Good pass
                 } else {
                     if ($score >= PASS_SCORE_STRONG) {
                         // Strong pass
                     }
                 }
             }
         }
         $rules = \Hubzero\Password\Rule::getRules();
         $msg = \Hubzero\Password\Rule::validate($registration['password'], $rules, $login, $registration['name']);
         if (!empty($msg)) {
             $this->_invalid['password'] = $msg;
         }
     }
     if ($registrationFullname == REG_REQUIRED) {
         if (empty($registration['name'])) {
             $this->_missing['name'] = 'Full Name';
             $this->_invalid['name'] = 'Please provide a name.';
         } else {
             $bits = explode(' ', $registration['name']);
             $surname = null;
             $middleName = null;
             $givenName = null;
             if (count($bits) == 1) {
                 $givenName = array_shift($bits);
             } else {
                 $surname = array_pop($bits);
                 if (count($bits) >= 1) {
                     $givenName = array_shift($bits);
                 }
                 if (count($bits) >= 1) {
                     $middleName = implode(' ', $bits);
                 }
             }
             if (!$givenName) {
                 $this->_missing['name'] = 'Full Name';
                 $this->_invalid['name'] = 'Please provide a name.';
             }
         }
     }
     if ($registrationFullname != REG_HIDE) {
         if (!empty($registration['name']) && !Helpers\Utility::validname($registration['name'])) {
             $this->_invalid['name'] = 'Invalid name. You may be using characters that are not allowed.';
         }
     }
     if ($registrationEmail == REG_REQUIRED) {
         if (empty($email)) {
             $this->_missing['email'] = 'Valid Email';
             $this->_invalid['email'] = 'Please provide a valid e-mail address.';
         }
     }
     if ($registrationEmail != REG_HIDE) {
         if (empty($email)) {
             $this->_missing['email'] = 'Valid Email';
         } elseif (!Helpers\Utility::validemail($email)) {
             $this->_invalid['email'] = 'Invalid email address. Please correct and try again.';
         } else {
             $usersConfig = \Component::params('com_users');
             $allow_duplicate_emails = $usersConfig->get('allow_duplicate_emails');
             // Check if the email is already in use
             $db = \App::get('db');
             $query = "SELECT `id` FROM `#__users` WHERE `email` = " . $db->quote($email) . " AND `id` != " . (int) $id;
             $db->setQuery($query);
             $xid = intval($db->loadResult());
             // 0 = not allowed
             // 1 = allowed (i.e. no check needed)
             // 2 = only existing accounts (grandfathered)
             if ($xid && ($allow_duplicate_emails == 0 || $allow_duplicate_emails == 2)) {
                 if ($allow_duplicate_emails == 0) {
                     $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                 } else {
                     if ($allow_duplicate_emails == 2) {
                         // If duplicates are only allowed in grandfathered accounts,
                         // then new accounts shouldn't be created with the same email.
                         if ($task == 'create' || $task == 'proxycreate') {
                             $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                         } else {
                             // We also need to catch existing users who might try to change their
                             // email to an existing email address on the hub. For that, we need to
                             // check and see if their email address is changing with this save.
                             $db = \App::get('db');
                             $query = "SELECT `email` FROM `#__users` WHERE `id` = " . (int) $id;
                             $db->setQuery($query);
                             $currentEmail = $db->loadResult();
                             if ($currentEmail != $email) {
                                 $this->_invalid['email'] = 'An existing account is already using this e-mail address.';
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($registrationConfirmEmail == REG_REQUIRED) {
         if (empty($confirmEmail) && empty($this->_invalid['email'])) {
             $this->_missing['confirmEmail'] = 'Valid Email Confirmation';
             $this->_invalid['confirmEmail'] = 'Please provide a valid e-mail address again.';
         }
     }
     if ($registrationConfirmEmail != REG_HIDE) {
         if ($email != $confirmEmail) {
             if (empty($this->_invalid['email'])) {
                 $this->_invalid['confirmEmail'] = 'Email addresses do not match. Please correct and try again.';
                 $this->_invalid['email'] = 'Email addresses do not match. Please correct and try again.';
             }
         }
     }
     if ($registrationURL == REG_REQUIRED) {
         if (empty($registration['web'])) {
             $this->_missing['web'] = 'Personal Web Page';
             $this->_invalid['web'] = 'Please provide a valid website URL';
         }
     }
     if ($registrationURL != REG_HIDE) {
         $registration['web'] = trim($registration['web']);
         if (!empty($registration['web']) && (strstr($registration['web'], ' ') || !Helpers\Utility::validurl($registration['web']))) {
             $this->_invalid['web'] = 'Invalid web site URL. You may be using characters that are not allowed.';
         }
     }
     if ($registrationORCID == REG_REQUIRED) {
         if (empty($registration['orcid'])) {
             $this->_missing['orcid'] = 'ORCID';
             $this->_invalid['orcid'] = 'Please provide a valid ORCID';
         }
     }
     if ($registrationORCID != REG_HIDE) {
         if (!empty($registration['orcid']) && !Helpers\Utility::validorcid($registration['orcid'])) {
             $this->_invalid['orcid'] = 'Invalid ORCID. It should be in the form of XXXX-XXXX-XXXX-XXXX.';
         }
     }
     if ($registrationPhone == REG_REQUIRED) {
         if (empty($registration['phone'])) {
             $this->_missing['phone'] = 'Phone Number';
             $this->_invalid['phone'] = 'Please provide a valid phone number';
         }
     }
     if ($registrationPhone != REG_HIDE) {
         if (!empty($registration['phone']) && !Helpers\Utility::validphone($registration['phone'])) {
             $this->_invalid['phone'] = 'Invalid phone number. You may be using characters that are not allowed.';
         }
     }
     if ($registrationEmployment == REG_REQUIRED) {
         if (empty($registration['orgtype'])) {
             $this->_missing['orgtype'] = 'Employment Type';
             $this->_invalid['orgtype'] = 'Please make an employment type selection';
         }
     }
     /*
     if ($registrationEmployment != REG_HIDE)
     	if (empty($registration['orgtype']))
     	{
     		//if (!Helpers\Utility::validateOrgType($registration['orgtype']) )
     			$this->_invalid['orgtype'] = 'Invalid employment status. Please make a new selection.';
     	}
     */
     if ($registrationOrganization == REG_REQUIRED) {
         if (empty($registration['org']) && empty($registration['orgtext'])) {
             $this->_missing['org'] = 'Organization';
             $this->_invalid['org'] = 'Invalid affiliation';
         }
     }
     if ($registrationOrganization != REG_HIDE) {
         if (!empty($registration['org']) && !Helpers\Utility::validtext($registration['org'])) {
             $this->_invalid['org'] = 'Invalid affiliation. You may be using characters that are not allowed.';
         } elseif (!empty($registration['orgtext']) && !Helpers\Utility::validtext($registration['orgtext'])) {
             $this->_invalid['org'] = 'Invalid affiliation. You may be using characters that are not allowed.';
         }
     }
     if ($registrationCitizenship == REG_REQUIRED) {
         if (empty($registration['countryorigin'])) {
             $this->_missing['countryorigin'] = 'Country of Citizenship / Permanent Residence';
             $this->_invalid['countryorigin'] = 'Invalid country of origin.';
         }
     }
     if ($registrationCitizenship != REG_HIDE) {
         if (!empty($registration['countryorigin']) && !Helpers\Utility::validtext($registration['countryorigin'])) {
             $this->_invalid['countryorigin'] = 'Invalid country of origin. You may be using characters that are not allowed.';
         }
     }
     if ($registrationResidency == REG_REQUIRED) {
         if (empty($registration['countryresident'])) {
             $this->_missing['countryresident'] = 'Country of Current Residence';
             $this->_invalid['countryresident'] = 'Invalid country of residency';
         }
     }
     if ($registrationResidency != REG_HIDE) {
         if (!empty($registration['countryresident']) && !Helpers\Utility::validtext($registration['countryresident'])) {
             $this->_invalid['countryresident'] = 'Invalid country of residency. You may be using characters that are not allowed.';
         }
     }
     if ($registrationSex == REG_REQUIRED) {
         if (empty($registration['sex'])) {
             $this->_missing['sex'] = 'Gender';
             $this->_invalid['sex'] = 'Please select gender.';
         }
     }
     if ($registrationSex != REG_HIDE) {
         if (!empty($registration['sex']) && !Helpers\Utility::validtext($registration['sex'])) {
             $this->_invalid['sex'] = 'Invalid gender selection.';
         }
     }
     if ($registrationDisability == REG_REQUIRED) {
         if (empty($registration['disability'])) {
             $this->_missing['disability'] = 'Disability Information';
             $this->_invalid['disability'] = 'Please indicate any disabilities you may have.';
         }
     }
     if ($registrationDisability != REG_HIDE) {
         if (!empty($registration['disability']) && in_array('yes', $registration['disability'])) {
             $this->_invalid['disability'] = 'Invalid disability selection.';
         }
     }
     if ($registrationHispanic == REG_REQUIRED) {
         if (empty($registration['hispanic'])) {
             $this->_missing['hispanic'] = 'Hispanic Ethnic Heritage';
             $this->_invalid['hispanic'] = 'Please make a selection or choose not to reveal.';
         }
     }
     /*
     if ($registrationHispanic != REG_HIDE)
     {
     	if (empty($registration['hispanic']))
     	{
     		$this->_invalid['hispanic'] = 'Invalid hispanic heritage selection.';
     	}
     }
     */
     if ($registrationRace == REG_REQUIRED) {
         if ($task == 'edit') {
             $corigin_incoming = in_array('countryorigin', $field_to_check) ? true : false;
             $profile = \Hubzero\User\Profile::getInstance(User::get('id'));
         } else {
             $corigin_incoming = true;
         }
         if (empty($registration['race']) && ($corigin_incoming && strtolower($registration['countryorigin']) == 'us' || !$corigin_incoming && isset($profile) && strtolower($profile->get('countryorigin')) == 'us')) {
             $this->_missing['race'] = 'Racial Background';
             $this->_invalid['race'] = 'Please make a selection or choose not to reveal.';
         }
     }
     /*
     if ($registrationRace != REG_HIDE)
     {
     	if (!empty($registration['race']) || !Helpers\Utility::validtext($registration['race']))
     	{
     		$this->_invalid['race'] = 'Invalid racial selection.';
     	}
     }
     */
     if ($registrationInterests == REG_REQUIRED) {
         if (empty($registration['interests']) || $registration['interests'] == '') {
             $this->_missing['interests'] = 'Interests';
             $this->_invalid['interests'] = 'Please select materials your are interested in';
         }
     }
     /*
     if ($registrationInterests != REG_HIDE)
     {
     	if (!empty($registration['edulevel']) && !Helpers\Utility::validtext($registration['edulevel']))
     		$this->_invalid['interests'] = 'Invalid interest selection.';
     	if (!empty($registration['role']) && !Helpers\Utility::validtext($registration['role']))
     		$this->_invalid['interests'] = 'Invalid interest selection.';
     }
     */
     if ($registrationReason == REG_REQUIRED) {
         if (empty($registration['reason']) && empty($registration['reasontxt'])) {
             $this->_missing['reason'] = 'Reason for registering';
             $this->_invalid['reason'] = 'Reason for registering';
         }
     }
     if ($registrationReason != REG_HIDE) {
         if (!empty($registration['reason']) && !Helpers\Utility::validtext($registration['reason'])) {
             $this->_invalid['reason'] = 'Invalid reason text. You may be using characters that are not allowed.';
         }
         if (!empty($registration['reasontxt']) && !Helpers\Utility::validtext($registration['reasontxt'])) {
             $this->_invalid['reason'] = 'Invalid reason text. You may be using characters that are not allowed.';
         }
     }
     if ($registrationOptIn == REG_REQUIRED) {
         if (is_null($registration['mailPreferenceOption']) || intval($registration['mailPreferenceOption']) < 0) {
             $this->_missing['mailPreferenceOption'] = 'Receive Email Updates';
             $this->_invalid['mailPreferenceOption'] = 'Receive Email Updates has not been selected';
         }
     }
     if ($registrationCAPTCHA == REG_REQUIRED) {
         $botcheck = Request::getVar('botcheck', '');
         if ($botcheck) {
             $this->_invalid['captcha'] = 'Error: Invalid CAPTCHA response.';
         }
         $validcaptchas = Event::trigger('hubzero.onValidateCaptcha');
         if (count($validcaptchas) > 0) {
             foreach ($validcaptchas as $validcaptcha) {
                 if (!$validcaptcha) {
                     $this->_invalid['captcha'] = 'Error: Invalid CAPTCHA response.';
                 }
             }
         }
     }
     if ($registrationTOU == REG_REQUIRED) {
         if (empty($registration['usageAgreement'])) {
             $this->_missing['usageAgreement'] = 'Usage Agreement';
             $this->_invalid['usageAgreement'] = 'Registration requires acceptance of the usage agreement';
         }
     }
     /*
     if ($registrationTOU != REG_HIDE)
     	if (!empty($registration['usageAgreement']))
     		$this->_invalid['usageAgreement'] = 'Usage Agreement has not been Read and Accepted';
     */
     if ($registrationAddress == REG_REQUIRED) {
         if (count($registration['address']) == 0) {
             $this->_missing['address'] = 'Member Address';
             $this->_invalid['address'] = 'Member Address';
         }
     }
     if (!empty($field_to_check)) {
         if ($this->_missing) {
             foreach ($this->_missing as $k => $v) {
                 if (!in_array($k, $field_to_check)) {
                     unset($this->_missing[$k]);
                 }
             }
         }
         if ($this->_invalid) {
             foreach ($this->_invalid as $k => $v) {
                 if (!in_array($k, $field_to_check)) {
                     unset($this->_invalid[$k]);
                 }
             }
         }
     }
     if (empty($this->_missing) && empty($this->_invalid)) {
         return true;
     }
     return false;
 }