Renders the "unauthorized" screen, when an user attempts to access
to a restricted area.

@return \Cake\Network\Response|null
437325
public function unauthorized()
    {
        $this->loadModel('User.Users');
        if ($this->request->is('post')) {
            $user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);

                return $this->redirect($this->Auth->redirectUrl());
            } else {
                $this->Flash->danger(__d('user', 'Username or password is incorrect'));
            }
        }
    }
1175250
private function setAuthority(): ?string
    {
        $authority = null;
        if (null !== $this->user_info) {
            $authority = $this->user_info.'@';
        }

        if (null !== $this->host) {
            $authority .= $this->host;
        }

        if (null !== $this->port) {
            $authority .= ':'.$this->port;
        }

        return $authority;
    }
1197844
public function defaultAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, Team::getModuleCode(),
                AccessManager::VIEW)
        ) {
            return $response;
        }

        return $this->getListRenderTemplate();
    }
1287648
public function getRequestUser()
    {
        if ($this->requestUser === null) {
            $token = $this->getRequestApiToken();
            if ($token === '') {
                $this->requestUser = 'no-token';
            } else {
                $ip = $this->app->make('ip');
                if ($ip->isBanned()) {
                    $this->requestUser = 'banned';
                } else {
                    $requestUser = null;
                    $list = new UserList();
                    $list->disableAutomaticSorting();
                    $list->filterByAttribute('api_token', $token);
                    $ids = $list->getResultIDs();
                    if (!empty($ids)) {
                        $u = \User::getByUserID($ids[0]);
                        if ($u->isRegistered()) {
                            $requestUser = $u;
                        }
                    }
                    if ($requestUser === null) {
                        $this->requestUser == 'invalid-token';
                        $ip->logSignupRequest();
                        if ($ip->signupRequestThreshholdReached()) {
                            $ip->createIPBan();
                        }
                    } else {
                        $this->requestUser = $requestUser;
                    }
                }
            }
        }
        if ($this->requestUser === 'no-token') {
            throw AccessDeniedException::create(t('API Access Token required'));
        }
        if ($this->requestUser === 'banned') {
            throw AccessDeniedException::create($this->app->make('ip')->getErrorMessage());
        }
        if ($this->requestUser === 'invalid-token') {
            throw AccessDeniedException::create(t('Bad API Access Token'));
        }

        return $this->requestUser;
    }
168506
public function disabledCheck(): ?\BearFramework\App\Response
    {
        $currentUserExists = Config::hasServer() && (Config::hasFeature('USERS') || Config::hasFeature('USERS_LOGIN_*')) ? $this->currentUser->exists() : false;
        $settings = $this->app->bearCMS->data->settings->get();
        $isDisabled = !$currentUserExists && $settings->disabled;
        if ($isDisabled) {
            return new App\Response\TemporaryUnavailable(htmlspecialchars($settings->disabledText));
        }
        return null;
    }
1332534
public function getUserInRequest() {
    if (isset($_COOKIE[$this->cookieName])) {
      $user = $this->validateToken($_COOKIE[$this->cookieName],
          $this->clientId);
      if ($user) {
        $accountInfo = $this->getUserById($user->getUserId());
        $accountInfo->setProviderId($user->getProviderId());
        return $accountInfo;
      }
    }
    return null;
  }
190261
public function handleSslRouting()
    {
        if ($this->settings->sslRoutingEnabled && !Craft::$app->getRequest()->getIsConsoleRequest())
        {
            $requestedUrl   = Craft::$app->request->getUrl();
            $restrictedUrls = $this->settings->sslRoutingRestrictedUrls;

            if (!Craft::$app->request->isSecureConnection)
            {
                foreach ($restrictedUrls as $restrictedUrl)
                {
                    // Parse dynamic variables like /{cpTrigger}
                    if (stripos($restrictedUrl, '{') !== false)
                    {
                        $restrictedUrl = Craft::$app->view->renderObjectTemplate(
                            $restrictedUrl,
                            $this->getDynamicParams()
                        );
                    }

                    $restrictedUrl = '/'.ltrim($restrictedUrl, '/');

                    if (stripos($requestedUrl, $restrictedUrl) === 0)
                    {
                        $this->forceSsl();
                    }
                }

                return true;
            }
        }

        return false;
    }
612133
public function checkEndpointAccess()
    {
        UserOnline::refreshUser($this->userAuthClass()->identity, $this->id);
        
        if (!Yii::$app->auth->matchApi($this->userAuthClass()->identity->id, $this->id, false)) {
            throw new ForbiddenHttpException('Unable to access this action due to insufficient permissions.');
        }
    }
840774
public function askAuthorization(){
        $rest = $this->getService( self::API_LOGIN_AUTHORIZE);
        $rest->POST([
            'app_id'        => $this->application->getId(),
            'app_name'      => $this->application->getName(),
            'app_version'   => $this->application->getVersion(),
            'device_name'   => gethostname(),
        ]);

        $this->app_token = $rest->getResult()['app_token'];
        $this->track_id  = $rest->getResult()['track_id'];

        $this->application->getLogger()->addInfo( 'Authorization send to Freebox. Waiting for response...');

        return $rest->getResult();
    }
580687
public function requestAccessToken()
    {
        try {
            $this->session->requestAccessToken($_GET['code']);
            return $this;
        } catch (Exception $e) {
            $this->redirectToSpotifyAuthorizeUrl();
        }
    }
1178937
public static function getAuth()
    {
        $result = null;
        if ($user = Arr::key('PHP_AUTH_USER', $_SERVER, true)) {
            $result .= $user;

            if ($password = Arr::key('PHP_AUTH_PW', $_SERVER, true)) {
                $result .= ':' . $password;
            }

            $result .= '@';
        }

        return $result;
    }
314753
protected function fromGuard()
    {
        $auth = $this->laravel['auth'];
        $user = $auth->user();

        return is_null($user) === true ? [] : [
            'id' => $user->getAuthIdentifier(),
            'rows' => $user->toArray(),
        ];
    }
1366884
public function getAccessToken()
    {
        if (null === $this->accessTokens) {
            $this->accessTokens = [];
        }

        if (!array_key_exists($this->getRegion(), $this->accessTokens)) {
            $this->accessTokens[$this->getRegion()] = $this->requestAccessToken();
        }

        return $this->accessTokens[$this->getRegion()]->getToken();
    }
720854
public function phpinfoAction()
    {
        $this->denyAccessIfProfilerDisabled();

        if (null !== $this->cspHandler) {
            $this->cspHandler->disableCsp();
        }

        ob_start();
        phpinfo();
        $phpinfo = ob_get_clean();

        return new Response($phpinfo, 200, ['Content-Type' => 'text/html']);
    }
491188
public function getPermission()
    {
        $this->request->allowMethod(['ajax']);

        $group_or_user = isset($this->request->data['group_or_user']) ? $this->request->data['group_or_user'] : null;
        $group_or_user_id = isset($this->request->data['group_or_user_id']) ? $this->request->data['group_or_user_id'] : null;

        $ugp = $this->UserGroupPermission->find()
            ->select(['permission_id','allow'])
            ->where(
                [
                    'group_or_user_id' => $group_or_user_id,
                    'group_or_user' => $group_or_user
                ])->toArray();

        $response = (!empty($ugp) && !is_null($ugp)) ? $ugp : 'fail';

        $this->set(compact('response'));
        $this->set('_serialize', ['response']);
        $this->render('Acl.Ajax/ajax_response', false);
    }
675546
public function authenticateAction()
    {
        if ($this->cmsAuthentication()->hasIdentity()) {
            return $this->redirect()->toRoute($this->options->getLoginRedirectRoute());
        }

        $result = $this->cmsAuthentication()->authenticate();

        // Return early if $result is a response
        if ($result instanceof Response) {
            return $result;
        }

        $redirect = $this->getRedirectParameter();

        if (!$result->isValid()) {
            if ($this->forwardingController) {
                return $this->forward()->dispatch(
                    $this->forwardingController,
                    ['action' => 'login']
                );
            }

            $url = $this->url()->fromRoute(
                $this->options->getLoginRoute(),
                [],
                $redirect ? ['query' => [$this->options->getRedirectKey() => $redirect]] : []
            );

            return $this->redirect()->toUrl($url);
        }

        if ($redirect) {
            return $this->redirect()->toUrl($redirect);
        }

        $route = $this->options->getLoginRedirectRoute();
        if (is_callable($route)) {
            $route = $route($this->cmsAuthentication()->getIdentity());
        }

        return $this->redirect()->toRoute($route);
    }
677533
public function updatePositionAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, $this->getModuleCode(), AccessManager::UPDATE)) {
            return $response;
        }

        try {
            $mode = $this->getRequest()->get('mode', null);

            if ($mode == 'up') {
                $mode = UpdatePositionEvent::POSITION_UP;
            } elseif ($mode == 'down') {
                $mode = UpdatePositionEvent::POSITION_DOWN;
            } else {
                $mode = UpdatePositionEvent::POSITION_ABSOLUTE;
            }

            $position = $this->getRequest()->get('position', null);

            $event = $this->createUpdatePositionEvent($mode, $position);

            $this->dispatch($this->changePositionEventIdentifier, $event);
        } catch (\Exception $ex) {
            // Any error
            return $this->errorPage($ex);
        }

        $response = $this->performAdditionalUpdatePositionAction($event);

        if ($response == null) {
            return $this->redirectToListTemplate();
        } else {
            return $response;
        }
    }