Validates a user.

@param AnCommandContext $context

@return bool
177401
public function validateUser(AnCommandContext $context)
    {
        $package = $this->getItem();

        //validate user
        if (get_viewer()->guest() && !$this->person->validateEntity()) {
            $url = route('option=com_subscriptions&view=signup&layout=login&id='.$package->id);
            $context->response->setRedirect($url);
            return false;
        }

        return true;
    }
96856
protected function _actionSignup(AnCommandContext  $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeAddPerson', array('data' => $context->data));

        $isFirstUser = !(bool) $this->getService('repos:people.person')
                                    ->getQuery(true)
                                    ->fetchValue('id');

        $person = parent::_actionAdd($context);

        $this->getRepository()
        ->getValidator()
        ->addValidation('givenName', 'required')
        ->addValidation('familyName', 'required')
        ->addValidation('username', 'uniqueness')
        ->addValidation('email', 'uniqueness');

        if ($person->validate() === false) {
            throw new AnErrorException($person->getErrors(), AnHttpResponse::BAD_REQUEST);
        }

        $viewer = get_viewer();

        if ($isFirstUser) {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR;
        } else {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_REGISTERED;
        }

        dispatch_plugin('user.onAfterAddPerson', array('person' => $person));

        if ($isFirstUser) {
            $this->registerCallback('after.signup', array($this, 'activateFirstAdmin'));
        } else {
            $context->response->setHeader('X-User-Activation-Required', true);
            $this->setMessage(AnTranslator::sprintf('COM-PEOPLE-PROMPT-ACTIVATION-LINK-SENT', $person->name), 'success');
        }
        
        $this->getResponse()->status = AnHttpResponse::OK;

        return $person;
    }
432403
public function match(Context $context)
    {
        $name = $this->getName($context);

        if ($this->map->hasRoute($name)) {
            return $this->map->getRoute($name);
        }

        return false;
    }
512732
public function validateDni(ExecutionContextInterface $context)
    {
        $dni = $this->getDni();

        if(0 === preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni) & 0 === preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni) & 0 === preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $dni)  & strlen($dni)>0){
            $context->addViolationAt('dni', 'Formato incorrecto');
            return;
        }

        //DNI & NIE
        if(preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni) || preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni)){
            //Posibles valores para la letra final
            $letters = array(
                0 => 'T', 1 => 'R', 2 => 'W', 3 => 'A', 4 => 'G', 5 => 'M',
                6 => 'Y', 7 => 'F', 8 => 'P', 9 => 'D', 10 => 'X', 11 => 'B',
                12 => 'N', 13 => 'J', 14 => 'Z', 15 => 'S', 16 => 'Q', 17 => 'V',
                18 => 'H', 19 => 'L', 20 => 'C', 21 => 'K',22 => 'E'
            );

            //Comprobar si es un DNI
            if (preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni))
            {
                if (strtoupper($dni[strlen($dni) - 1]) != $letters[((int) substr($dni, 0, strlen($dni) - 1)) % 23]){
                    $context->addViolationAt('dni', 'dni.invalid.number');
                    return;
                }
            }
            //Comprobar si es un NIE
            else if (preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni))
            {
                //Comprobar letra
                if (strtoupper($dni[strlen($dni) - 1]) !=$letters[((int) substr($dni, 1, strlen($dni) - 2)) % 23]){
                    $context->addViolationAt('dni', 'nie.invalid.number');
                    return;
                }
            }
        }
        //CIF
        if(preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $dni)){
            $sum = 0;
            for ($i=2; $i<strlen($dni)-1; $i+=2) {
                $sum += substr($dni, $i, 1);
            }

            for ($i=1; $i<strlen($dni)-1; $i+=2) {
                $t = substr($dni, $i, 1) * 2;
                $sum += ($t>9)?($t-9):$t;
            }

            $control = 10 - ($sum % 10);

            if ( !(substr($dni, 8, 1) == $control || strtoupper(substr($dni, 8, 1)) == substr('JABCDEFGHI', $control, 1 ))){
                $context->addViolationAt('dni', 'cif.invalid');

                return;
            }
        }

    }
338430
protected function _authorizeAction(AnCommandContext $context)
    {
        //if entity is not privatable then it doesn't have access to allow method
        if (!$this->_entity->isPrivatable()) {
            return true;
        }

        //if viewer is admin then return true on the action
        if ($this->_viewer->admin()) {
            return true;
        }

        $action = $context->action;

        //any action on the actor requires being a follower by default
        $context->append(array(
            'default' => LibBaseDomainBehaviorPrivatable::FOLLOWER,
        ));

        //not access to the entiy
        if (! $this->_entity->authorize('access')) {
            return false;
        }

        $parts = explode(':', $action);

        $component = array_shift($parts);
        //check if it's a social app then if it's enabled

        if ($component) {

            $component = $this->getService('repos:components.component')->find(array('component' => $component));

            if (
                $component &&
                $component->authorize('action', array(
                                                    'actor' => $this->_entity,
                                                    'action' => $parts[1],
                                                    'resource' => $parts[0],
                                                    )) === false
            ) {
                return false;
            }
        }

        return $this->_entity->allows($this->_viewer, $action, $context->default);
    }
346301
protected function checkRules($context = null)
    {
        $rules = $this->getRules();
        $result = false;

        foreach ($rules as $rule) {
            if ($rule->check($context)) {
                $result = true;
                break;
            }
        }

        return $result;
    }
1308215
public function validate ($object = null)
	{
		if (!isset ($this->context))
		{
			throw new InvalidParameter ("You must set a context before validating or filtering.");
		}

		$result = $this->reduce ($this->context, $object);

		if ($result)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
107811
public function isValid($value, $context = null)
    {
        if (! is_array($value) && ! is_array($context)) {
            $this->error(self::MISSING_VALUE);
            return false;
        }

        if (! is_array($value) && is_array($context)) {
            $value = $context;
        }

        if (empty($value[$this->responseField])) {
            $this->error(self::MISSING_VALUE);
            return false;
        }

        $service = $this->getService();

        $res = $service->verify($value[$this->responseField]);
        if (! $res) {
            $this->error(self::ERR_CAPTCHA);
            return false;
        }

        if (! $res->isSuccess()) {
            $result = $res->getErrorCodes();
            $this->error(self::BAD_CAPTCHA, end($result));
            return false;
        }

        return true;
    }
139690
protected function _actionTokenlogin(AnCommandContext $context)
    {
        if ($this->token == '') {
            throw new AnErrorException(array('No token is provided'), AnHttpResponse::FORBIDDEN);
        }

        $person = $this->getService('repos:people.person')->find(array('activationCode' => $this->token));

        if (! $person) {
            throw new AnErrorException(array('This token is invalid'), AnHttpResponse::NOT_FOUND);
        }

        $newPerson = ($person->registrationDate->compare($person->lastVisitDate)) ? true : false;

        if ($newPerson) {
            $person->enable();
        }

        $person->activationCode = '';
        $this->token = '';
        $this->_request->token = '';

        if ($this->reset_password) {
            AnRequest::set('session.reset_password_prompt', 1);
        }

        $credentials = array(
            'username' => $person->username,
            'password' => $person->password
        );

        dispatch_plugin('user.onBeforeLoginPerson', array('credentials' => $credentials));

        $this->getService('com:people.helper.person')->login($credentials);

        dispatch_plugin('user.onAfterLoginPerson', array('person' => $person));

        if ($this->return) {
            AnRequest::set('session.return', $this->return);
            $returnUrl = base64UrlDecode($this->return);
            $this->getResponse()->setRedirect($returnUrl);
        } else {
            unset($_SESSION['return']);
            if ($this->_request->isFirstPerson) {
                $this->setMessage(sprintf(translate('COM-PEOPLE-PROMPT-WELCOME-SUPERADMIN'), $person->name));
            } else {
                $this->setMessage('COM-PEOPLE-PROMPT-UPDATE-PASSWORD');
            }
            $this->getResponse()->setRedirect(route($person->getURL().'&get=settings&edit=account'));
        }

        $this->getResponse()->status = AnHttpResponse::ACCEPTED;

        return true;
    }
161514
public function isValid($value = null, $context = null)
    {
        if (!is_scalar($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $this->setValue($value);

        $country = $this->getCountry();

        if (!array_key_exists($country, self::$postCodeRegex) && array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!array_key_exists($country, self::$postCodeRegex)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $format = self::$postCodeRegex[$country];

        if ($format[0] !== '/') {
            $format = '/^' . $format;
        }

        if ($format[strlen($format) - 1] !== '/') {
            $format .= '$/';
        }

        if (!preg_match($format, $value)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        return true;
    }
294994
public function validate($context = 'payload')
    {
        $args = func_get_args();
        array_shift($args);

        $this->each(function ($claim) use ($context, $args) {
            call_user_func_array(
                [$claim, 'validate'.Str::ucfirst($context)],
                $args
            );
        });

        return $this;
    }
1053639
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        if(\mb_strlen($value) === 0) {
            return false;
        }
        
        if($arg->min !== null && \mb_strlen($value) < $arg->min) {
            return 'Please enter something above or exactly '.$arg->min.' characters in length.';
        }
        
        if($arg->max !== null && \mb_strlen($value) > $arg->max) {
            return 'Please enter a number below or exactly '.$arg->max.' characters in length.';
        }
        
        return true;
    }
864359
public function isValid($value, $context = null) {
        $this->_setValue((string) $value);

        $token = $this->getToken();
        $pos = strrpos($token, '[');
        if ($pos !== false) {
            $token = rtrim($token, ']');
            $token = substr($token, $pos+1);
        }

        if (($context !== null) && isset($context) && array_key_exists($token, $context)) {
            $token = $context[$token];
        }

        if ($token === null) {
            $this->_error(self::MISSING_TOKEN);
            return false;
        }

        $strict = $this->getStrict();
        if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) {
            $this->_error(self::NOT_SAME);
            return false;
        }

        return true;
    }
152369
protected function _authorizeAdministration(AnCommandContext $context)
    {
        $ret = false;

        if ($this->_entity->authorize('access', $context)) {

            if ($this->_viewer->isAdministrator()) {
                $ret = $this->_viewer->administrator($this->_entity);
            }

            if ($context->strict !== true) {
                $ret = $ret || $this->_viewer->admin();
            }
        }

        return (bool) $ret;
    }
357682
public static function validateUser($userinfo)
	{
		$plugins = Factory::getPlugins();

		foreach($plugins as $plugin) {
			$user = Factory::getUser($plugin->name);
			if (!$user->validateUser($userinfo)) {
				throw new \RuntimeException('unknown validation: ' . $plugin->name);
			}
		}
		return true;
	}
1373554
protected function _beforeControllerGet(AnCommandContext $context)
    {
        if ($this->_mixer->getRequest()->get == 'accesstoken') {
            $this->_mixer->execute('getaccesstoken', $context);
            return false;
        } else {
            $this->api = $this->getAPI();
        }
    }
1052963
protected function validateTooMany(\SwaggerValidator\Common\Context $context)
    {
        $sandBox = $context->getSandBoxKeys();

        foreach ($context->getRequestDataKeys() as $location => $list) {

            if (!array_key_exists($location, $sandBox)) {
                continue;
            }

            if ($location == \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY) {
                $ctx = $context->setLocation($location)->setDataPath($location)->setDataCheck('exist');
                $ctx->loadRequestBody();

                if ($ctx->isDataExists() && !$sandBox[$location]) {
                    $ctx->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_TOOMANY, 'Body is given and not expected', __METHOD__, __LINE__);
                }

                continue;
            }

            foreach ($list as $key) {

                if (in_array($key, $sandBox[$location])) {
                    continue;
                }

                $ctx->setDataPath($key)->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_TOOMANY, $key . ' is given and not expected', __METHOD__, __LINE__);
            }
        }

        $context->setDataPath('CheckTooMany')->logValidate(get_class($this), __METHOD__, __LINE__);
        return true;
    }