Ejemplo n.º 1
0
 /**
  * Validates the username.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	JSON	A jsong encoded string.
  *
  * @author	Jason Rey <*****@*****.**>
  */
 public function isValid()
 {
     // Render the ajax lib.
     $ajax = FD::getInstance('Ajax');
     // Get the userid
     $userid = JRequest::getInt('userid', 0);
     // Get the event
     $event = JRequest::getString('event');
     // Set the current username
     $current = '';
     if (!empty($userid)) {
         $user = FD::user($userid);
         $current = $user->username;
     }
     // Get the provided username that the user has typed.
     $username = JRequest::getVar('username', '');
     // Username is required, check if username is empty
     if (JString::strlen($username) < $this->params->get('min')) {
         return $ajax->reject(JText::sprintf('PLG_FIELDS_JOOMLA_USERNAME_MIN_CHARACTERS', $this->params->get('min')));
     }
     // Test if username is allowed (by pass for adminedit).
     if ($event !== 'onAdminEdit' && !SocialFieldsUserJoomlaUsernameHelper::allowed($username, $this->params)) {
         return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_ALLOWED'));
     }
     // Test if username exists.
     if (SocialFieldsUserJoomlaUsernameHelper::exists($username, $current)) {
         return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_AVAILABLE'));
     }
     // Test if the username is valid
     if (!SocialFieldsUserJoomlaUsernameHelper::isValid($username, $this->params)) {
         return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_IS_INVALID'));
     }
     $text = JText::_('PLG_FIELDS_JOOMLA_USERNAME_AVAILABLE');
     return $ajax->resolve($text);
 }
Ejemplo n.º 2
0
 public function validateUsername($username, $current = '')
 {
     $config = FD::config();
     // If settings is set to use email as username, then we bypass this check
     if ($config->get('registrations.emailasusername')) {
         return true;
     }
     // Test the username length
     if (JString::strlen($username) < $this->params->get('min')) {
         return $this->setError(JText::sprintf('PLG_FIELDS_JOOMLA_USERNAME_MIN_CHARACTERS', $this->params->get('min')));
     }
     // Test if the username is allowed
     if (!SocialFieldsUserJoomlaUsernameHelper::allowed($username, $this->params, $current)) {
         $this->setError(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_ALLOWED'));
         return false;
     }
     // Test if the username provided is valid.
     if (!SocialFieldsUserJoomlaUsernameHelper::isValid($username, $this->params)) {
         $this->setError(JText::_('PLG_FIELDS_JOOMLA_USERNAME_PLEASE_ENTER_VALID_USERNAME'));
         return false;
     }
     // Test if the username is available.
     if (SocialFieldsUserJoomlaUsernameHelper::exists($username, $current)) {
         $this->setError(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_AVAILABLE'));
         return false;
     }
     return true;
 }