Fetch POST data
Get login by cookie
Get Ip
If check parameters is true, check mandatory parameters

@param bool $check
@return array
@throws \common_exception_MissingParameter
13222
protected function getData($check = false)
    {
        $data = $this->getParameters();

        if ($this->hasRequestParameter('type')) {
            $type = $this->getRequestParameter('type');
            unset($data['type']);

            if ($type !== 'custom_input') {
                foreach ($data as $key => $value) {
                    $data[$type . '_' . $key] = $value;
                    unset($data[$key]);
                }
            }
        }

        $data = $this->mapData($data);

        if ($this->hasRequestParameter('school_name')) {
            $data[Storage::DIAGNOSTIC_SCHOOL_NAME] = \tao_helpers_Display::sanitizeXssHtml(trim($this->getRequestParameter('school_name')));
        }
        if ($this->hasRequestParameter('school_number')) {
            $data[Storage::DIAGNOSTIC_SCHOOL_NUMBER] = \tao_helpers_Display::sanitizeXssHtml(trim($this->getRequestParameter('school_number')));
        }

        if ($check) {
            if (!$this->hasRequestParameter('os')) {
                throw new \common_exception_MissingParameter('os');
            }
            if (!$this->hasRequestParameter('osVersion')) {
                throw new \common_exception_MissingParameter('osVersion');
            }
            if (!$this->hasRequestParameter('browser')) {
                throw new \common_exception_MissingParameter('browser');
            }
            if (!$this->hasRequestParameter('browserVersion')) {
                throw new \common_exception_MissingParameter('browserVersion');
            }
            $data['osVersion'] = preg_replace('/[^\w\.]/', '', $data['osVersion']);
            $data['browserVersion'] = preg_replace('/[^\w\.]/', '', $data['browserVersion']);
        }

        if (isset($_COOKIE['login'])) {
            $data['login'] = $_COOKIE['login'];
        } else {
            $data['login'] = 'Anonymous';
        }

        $user = \common_session_SessionManager::getSession()->getUser();
        if ($user && $user->getIdentifier()) {
            $data['user_id'] = $user->getIdentifier();
        }

        $data['version'] = $this->getServiceLocator()->get(\common_ext_ExtensionsManager::SERVICE_ID)->getExtensionById('taoClientDiagnostic')->getVersion();

        $data['ip'] = (!empty($_SERVER['HTTP_X_REAL_IP'])) ? $_SERVER['HTTP_X_REAL_IP'] : ((!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : 'unknown');
        return $data;
    }
1126325
protected static function _check($check, $regex)
    {
        return is_string($regex) && is_scalar($check) && preg_match($regex, $check);
    }
497062
public function getStatus()
    {
        try {
            if (!$this->hasRequestParameter(self::TASK_ID_PARAM)) {
                throw new \common_exception_MissingParameter(self::TASK_ID_PARAM, $this->getRequestURI());
            }

            $data = $this->getTaskLogReturnData(
                $this->getRequestParameter(self::TASK_ID_PARAM),
                $this->getTaskName()
            );

            $this->returnSuccess($data);
        } catch (\Exception $e) {
            $this->returnFailure($e);
        }
    }
466173
public function checkCss($check = null): bool
    {
        // Css (could be array) and objects css property set?
        if (isset($check) && $this->css) {

            // convert non array css to array
            if (!is_array($check)) {
                $check = (array) $check;
            }

            // Is css to check already in objects css array?
            $check = array_intersect($check, $this->css) ? true : false;
        }
        else {
            // Without set css param we only check if css is used
            $check = $this->css ? true : false;
        }

        return $check;
    }
97819
protected function getCredentials()
    {
        if (empty($this->username) || empty($this->password)) {
            throw new \Exception('Basic authentication requires a $username & $password property.');
        }

        return [$this->username, $this->password];
    }
1076742
public function login()
    {
        try {

            if (!$this->hasRequestParameter('successCallback')) {
                throw new \common_exception_MissingParameter ('Internal error, please retry in few moment');
            }

            if ($this->isRequestPost()) {
                $authorizationService = $this->getServiceLocator()->get(Authorization::SERVICE_ID);

                if (!$authorizationService instanceof RequireUsername) {
                    throw new InvalidCallException('Authenticator need to be call by requireusername');
                }

                if ($authorizationService->validateLogin($this->getRequestParameter('login'))) {
                    $baseUrl = $this->getServiceLocator()
                        ->get(\common_ext_ExtensionsManager::SERVICE_ID)
                        ->getExtensionById('taoClientDiagnostic')
                        ->getConstant('BASE_URL');
                    $elements = parse_url($baseUrl);
                    $this->setCookie('login', $this->getRequestParameter('login'), null, $elements['path']);
                    $this->redirect($this->getRequestParameter('successCallback'));
                }
            }

        } catch (InvalidLoginException $e) {
            $this->setData('errorMessage', $e->getUserMessage());
        }

        $this->setData('successCallback', $this->getRequestParameter('successCallback'));
        $this->setData('client_config_url', $this->getClientConfigUrl());
        $this->setData('content-controller', 'taoClientDiagnostic/controller/Authenticator/login');
        $this->setData('content-template', 'Authenticator' . DIRECTORY_SEPARATOR . 'login.tpl');
        $this->setView('index.tpl');
    }
1175710
function getUserData(data, checks) {
  if (Array.isArray(data) ? data.length === 0 : data.total === 0) {
    throw new errors.BadRequest('User not found.', { errors: { $className: 'badParams' } });
  }
  
  const users = Array.isArray(data) ? data : data.data;
  const user = users[0];
  
  if (users.length !== 1) {
    throw new errors.BadRequest('More than 1 user selected.',
      { errors: { $className: 'badParams' } });
  }

  if (checks.indexOf('isNotVerified') !== -1 && user.isVerified) {
    throw new errors.BadRequest('User is already verified.',
      { errors: { $className: 'isNotVerified' } });
  }

  if (checks.indexOf('isVerified') !== -1 && !user.isVerified) {
    throw new errors.BadRequest('User is not verified.',
      { errors: { $className: 'isVerified' } });
  }
  
  if (checks.indexOf('verifyNotExpired') !== -1 && user.verifyExpires < Date.now()) {
    throw new errors.BadRequest('Verification token has expired.',
      { errors: { $className: 'verifyExpired' } });
  }

  if (checks.indexOf('resetNotExpired') !== -1 && user.resetExpires < Date.now()) {
    throw new errors.BadRequest('Password reset token has expired.',
      { errors: { $className: 'resetExpired' } });
  }

  return user;
}
507979
public function checkParams(array $params, &$error = null)
    {
        $result = array();
        foreach ($this->paramsReq as $param) {
            if (!array_key_exists($param, $params)) {
                $error = 'required '.$param;
                return false;
            }
            $result[$param] = $params[$param];
        }
        foreach ($this->paramsDefault as $param => $default) {
            if (array_key_exists($param, $params)) {
                $result[$param] = $params[$param];
            } else {
                $result[$param] = $default;
            }
        }
        return $result;
    }
1300071
public static function extension($check, $extensions = ['gif', 'jpeg', 'png', 'jpg'])
    {
        if ($check instanceof UploadedFileInterface) {
            return static::extension($check->getClientFilename(), $extensions);
        }
        if (is_array($check)) {
            $check = isset($check['name']) ? $check['name'] : array_shift($check);

            return static::extension($check, $extensions);
        }
        $extension = strtolower(pathinfo($check, PATHINFO_EXTENSION));
        foreach ($extensions as $value) {
            if ($extension === strtolower($value)) {
                return true;
            }
        }

        return false;
    }
761792
public function check()
    {
    	$action = $this->request->param('action');
        $controller = $this->request->param('controller');
        $prefix = ($this->request->param('prefix') === false) ? '/' : $this->request->param('prefix');
        $plugin = ($this->request->param('plugin') === false) ? '' : $this->request->param('plugin');

        $plugin_prefix = (empty($plugin)) ? $prefix : $plugin . '.' . $prefix;
        if( isset($this->_authorized[$plugin_prefix][$controller]) &&
            in_array($action, $this->_authorized[$plugin_prefix][$controller]) ) return true;

        $user_id = $this->request->session()->read('Auth.User.id');
        $group_id = -1;
        if( isset($this->controllers['group']) ) {
            $User = TableRegistry::get($this->controllers['user']);
            $group_id = $User->get($user_id)->group_id;
        }

        $UserGroupPermission = TableRegistry::get('UserGroupPermission');
        $Permission = TableRegistry::get('Permission');

        $unique_string = $this->getUniqueString($controller, $action, $prefix, $plugin);
        $permission_id = $Permission->find()
            ->select(['id'])
            ->where(['unique_string' => $unique_string])->first();
        if( is_null($permission_id) ) return false;

        $allow = $UserGroupPermission->find()
            ->select(['allow'])
            ->where(
                [
                    'group_or_user'     => 'user',
                    'group_or_user_id'  => $user_id,

                ])
            ->orWhere(
                [
                    'group_or_user'     => 'group',
                    'group_or_user_id'  => $group_id
                ])->andWhere(['permission_id' => $permission_id->id])
            ->order(['allow'=>'DESC'])->first();
        if( is_null($allow) ) return false;

        return $allow->allow;
    }
20862
public function getData(): Parameters
	{
		if($this->realMethod === 'GET')
		{
			return $this->getQuery();
		}
		elseif($this->realMethod === 'POST' && $this->hasFormData())
		{
			return $this->getPost();
		}

		return $this->getBody();
	}
289095
public function getChecks()
	{
		$client = new \Guzzle\Service\Client('https://api.pingdom.com/api/2.0');

		/** @var $request \Guzzle\Http\Message\Request */
		$request = $client->get('checks', array('App-Key' => $this->token));
		$request->setAuth($this->username, $this->password);
		$response = $request->send();
		$response = json_decode($response->getBody(), true);

		return $response['checks'];
	}
1186448
public function getCode($set = true)
    {
        $list = $this->getList();
        $code = $this->getFromUrl();

        if (empty($code)) {
            $code = $this->getFromCookie();
        }

        if (empty($list[$code]['status'])) {
            $code = $this->getDefault();
        }

        if ($set) {
            $this->setCookie($code);
        }

        return $code;
    }
228821
public function check() 
    {
        $url = self::HOST . self::CHECK;
        $params = $this->get_default_params();
        $result = $this->request($url, $params);

        return $result;
    }
627213
protected function perform_check()
	{
		// fetch the username and login hash from the session
		$username    = \Session::get('username');
		$login_hash  = \Session::get('login_hash');

		// only worth checking if there's both a username and login-hash
		if ( ! empty($username) and ! empty($login_hash))
		{
			if (is_null($this->user) or ($this->user['username'] != $username and $this->user != static::$guest_login))
			{
				$this->user = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))
					->where('username', '=', $username)
					->from(\Config::get('simpleauth.table_name'))
					->execute(\Config::get('simpleauth.db_connection'))->current();
			}

			// return true when login was verified, and either the hash matches or multiple logins are allowed
			if ($this->user and (\Config::get('simpleauth.multiple_logins', false) or $this->user['login_hash'] === $login_hash))
			{
				return true;
			}
		}

		// not logged in, do we have remember-me active and a stored user_id?
		elseif (static::$remember_me and $user_id = static::$remember_me->get('user_id', null))
		{
			return $this->force_login($user_id);
		}

		// no valid login when still here, ensure empty session and optionally set guest_login
		$this->user = \Config::get('simpleauth.guest_login', true) ? static::$guest_login : false;
		\Session::delete('username');
		\Session::delete('login_hash');

		return false;
	}
361940
public function get($property = null, $reset = false)
    {
        if (empty($this->data) || $reset === true) {
            $this->makeRequest($this->getUrl(), 'GET');
            $this->data = $this->getResponseBody();
        }
        if ($property !== null) {
            return $this->data->{$property} ?? [];
        }
        return $this->data;
    }
678798
public function getUserData( $ip = "", $force = false ) {
		if ( isset( $_GET['geot_backtrace'] ) || defined( 'GEOT_BACKTRACE' ) ) {
			$this->printBacktrace();
		}
		try {
			$this->check_active_user();

			if ( ! empty( $ip ) ) {
				$this->ip = $ip;
			}

			$this->ip = apply_filters( 'geot/user_ip', $this->ip );

			if ( empty( $this->opts['license'] ) ) {
				throw new InvalidLicenseException( json_encode( [ 'error' => 'License is missing' ] ) );
			}

			$this->cache_key = md5( $this->ip );

			if ( ! empty ( $this->user_data[ $this->cache_key ] ) ) {
				return $this->user_data[ $this->cache_key ];
			}

			$this->initUserData();

			// Easy debug
			if ( isset( $_REQUEST['geot_debug'] ) && ! empty( $_REQUEST['geot_debug'] ) ) {
				return $this->debugData();
			}

			// If user set cookie and not in debug mode. If we pass ip we are forcing to use ip instead of cookies. Eg in dropdown widget
			if ( ! $this->opts['debug_mode'] && ! empty( $_COOKIE[ $this->opts['cookie_name'] ] ) && ! $force ) {
				return $this->setData( 'country', 'iso_code', $_COOKIE[ $this->opts['cookie_name'] ] );
			}

			// If we already calculated on session return (if we are not calling by IP & if cache mode (sessions) is turned on)
			if ( $this->opts['cache_mode'] && ! empty ( $this->session->get( 'geot_data' ) ) ) {
				$this->user_data[ $this->cache_key ] = new GeotRecord( $this->session->get( 'geot_data' ) );
				$this->checkLocale();

				return $this->user_data[ $this->cache_key ];
			}
			// check for whitelist Ips
			if( $this->user_whitelisted()) {
				return $this->getFallbackCountry();
			}
			// check for crawlers
			$CD = new CrawlerDetect();
			if ( $CD->isCrawler() || $this->treatAsBot() ) {
				return $this->setData( 'country', 'iso_code', ! empty( $this->opts['bots_country'] ) ? $this->opts['bots_country'] : 'US' );
			}

			// WP Engine ?
			if ( isset( $this->opts['wpengine'] ) && $this->opts['wpengine'] ) {
				return $this->wpengine();
			}
			// Kingsta ?
			if ( isset( $this->opts['kinsta'] ) && $this->opts['kinsta'] ) {
				return $this->kinsta();
			}
			// maxmind ?
			if ( isset( $this->opts['maxmind'] ) && $this->opts['maxmind'] ) {
				$record = $this->maxmind();
				$this->checkLocale();

				return $record;
			}
			// ip2location ?
			if ( isset( $this->opts['ip2location'] ) && $this->opts['ip2location'] ) {
				return $this->ip2location();
			}
			//last chance filter to cancel query and pass custom data
			if ( ( $custom_data = apply_filters( 'geot/cancel_query', false ) ) ) {
				return $this->cleanResponse( $custom_data );
			}
			// API
			$record = $this->cleanResponse( $this->geotWP->getData( $this->ip ) );
			$this->checkLocale();

			return $record;

		} catch ( OutofCreditsException $e ) {
			GeotEmails::OutOfQueriesException();
			GeotNotifications::notify( $e->getMessage() );

			return $this->getFallbackCountry();
		} catch ( InvalidSubscriptionException $e ) {
			GeotEmails::InvalidSubscriptionException( $e->getMessage() );
			GeotNotifications::notify( $e->getMessage() );

			return $this->getFallbackCountry();
		} catch ( InvalidLicenseException $e ) {
			GeotEmails::AuthenticationException();
			GeotNotifications::notify( $e->getMessage() );

			return $this->getFallbackCountry();
		} catch ( GeotException $e ) {
			GeotNotifications::notify( $e->getMessage() );

			return $this->getFallbackCountry();
		} catch ( \Exception $e ) {
			GeotNotifications::notify( $e->getMessage() );

			return $this->getFallbackCountry();
		}

	}