Stops masquerading as another user if we are currently masquerading.
Returns true on success or false otherwise.

@return boolean
195814
public function stopMasquerading() {
        if($this->isMasquerading()) {
            // become the real user again
            Auth::logout();
            Auth::login(session('masquerading_user'));
            session(['masquerading_user' => null]);

            // success!
            return true;
        }

        return false;
    }
888525
public function accept()
    {
        $path = $this->getInnerIterator()->key();
        $result = $this->visitor->isAccepted($path);

        if ($result === PathVisitor::PATH_ACCEPTED) {
            return true;
        }
        if ($result === PathVisitor::FAKE_CONTENT) {
            $this->toFake[] = $path;
        }

        return false;
    }
1245167
public function accept()
    {
        if (!$this->matchRegexps && !$this->noMatchRegexps) {
            return true;
        }

        $fileinfo = $this->current();

        if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
            return false;
        }

        $content = $fileinfo->getContents();
        if (!$content) {
            return false;
        }

        return $this->isAccepted($content);
    }
1102482
public function stop()
    {
        // Create a new profile based upon the data of the adapter
        $profile = $this->getProfileFactory()->create(
            $this->getProfilerAdapter()->stop(),
            $this->getApplicationData(),
            $_SERVER // TODO: Don't want to use this directly, do something smarter
        );

        // Notify and persist the profile on the persistence service
        $this->getPersistenceService()->persist($profile);

        // Return the profile for further handling
        return $profile;
    }
69514
public function ingameCoop()
    {
        foreach ($this->owner->players as $player) {
            if ($player->isCooping) {
                return true;
            }
        }
        return false;
    }
444056
public function checkAuthentication()
    {
        if (self::isAuthenticated()) {
            return true;
        } elseif (self::isGatewayed()) {
            return $this->validateCas();
        }
        self::setGatewayed(true);
        session_write_close();
        $this->redirectToCas(true);
        // never reached
        return true;
    }
231903
private function canPurge()
    {
        // check if purge header exists
        if (!$this->request->matchHeader(self::H_PURGE)) {
            return false;
        }

        if ($this->controlKey == '') {
            return true; // everybody can purge
        }

        // only users with valid control key can purge
        if ($this->request->matchHeader(self::H_CKEY, $this->controlKey)) {
            return true;
        }

        return false;
    }
107074
public function onStopImpersonating()
    {
        if (!Auth::isImpersonator()) {
            return $this->onLogout();
        }

        Auth::stopImpersonate();

        $url = post('redirect', Request::fullUrl());

        Flash::success(Lang::get('rainlab.user::lang.session.stop_impersonate_success'));

        return Redirect::to($url);
    }
373202
public function isAuthenticated()
    {
        if (!$this->session->has('usr_id')) {
            return false;
        }

        if ($this->session->has('session_id')) {
            if (null !== $this->app['repo.sessions']->find($this->session->get('session_id'))) {
                return true;
            }
        }

        $this->session->invalidate();
        $this->reinitUser();

        return false;
    }
202984
public function unimpersonateUser()
    {
        $realId = $this->session->remove('__realId');
        if ($realId !== null) {
            $this->user->identity->remove();
            $this->session->set($this->user->idParam, $realId);
            $identity = User::findOne($realId);
            $this->user->setIdentity($identity);
            $this->restoreBackedUpToken();
        }
    }
642774
public function clearIdentity()
    {
        $this->getStorage()->clear();

        //all identies go - it's done that way now at least
        $ids = $this->getContainer()->getIdentities();
        $sessionIds = array();
        foreach($ids as $id) {
            $sessionIds[] = $id->getSessionId();
        }
        $this->getSessionProvider()->clear($sessionIds);
        
        $this->getEventManager()->trigger('clearIdentity.post', $this, array(
            'identities' => $ids
        ));
        
        return $ids;
    }
829113
protected function detectFake()
    {
        $facade = $this->facade;
        
        if (!method_exists($facade, 'fake')) {
            return;
        }

        $real = $facade::getFacadeRoot();
        
        try {
            $facade::fake();
            $fake = $facade::getFacadeRoot();
            if ($fake !== $real) {
                $this->addClass(get_class($fake));
            }
        } finally {
            $facade::swap($real);
        }
    }
489362
public function check()
	{
		if ($this->isBanned())
		{
			throw new UserBannedException(sprintf(
				'User [%s] has been banned.',
				$this->getUser()->getLogin()
			));
		}

		if ($this->isSuspended())
		{
			throw new UserSuspendedException(sprintf(
				'User [%s] has been suspended.',
				$this->getUser()->getLogin()
			));
		}

		return true;
	}
1180366
public function isBot(): bool
    {
        if (null === $this->isBot) {
            $this->isBot = false;
            foreach ($this->botSignatures as $botSignature) {
                if (preg_match($botSignature, $this->name) === 1) {
                    $this->isBot = true;
                    break;
                }
            }
        }

        return $this->isBot;

    }
1048451
def can_cloak_as(user, other_user):
    
    # check to see if the user is allowed to do this
    can_cloak = False
    try:
        can_cloak = user.can_cloak_as(other_user)
    except AttributeError as e:
        try:
            can_cloak = user.is_staff
        except AttributeError as e:
            pass

    return can_cloak
1120672
public function __isAllowed()
    {
        if ($this->checkAuthentication !== true) {
            // this controller is not responsible for the authentication
            return false;
        }

        $this->typo3Loader->initializeBackendEndUser();

        $beUser = $this->typo3Loader->getBackEndUser();
        if (false === is_array($beUser->user) || empty($beUser->user['uid'])) {
            return false;
        }
        return true;
    }
700023
public static function hasUser()
    {

        if (!(Yii::$app instanceof Application)) {
            return false;
        }
        if (!Yii::$app->db->getTableSchema(User::tableName())) {
            return false;
        }
        try {
            $identityClass = Yii::$app->user->identityClass;
        } catch (\Exception $e) {
            $identityClass = false;
        }

        if (!$identityClass) {
            return false;
        }

        return !Yii::$app->user->isGuest;
    }