/*
get user login info, set cookie and session
@return bool
423639
public function login($request)
	{
		// check Server Signature
		if(!$this->checkSignature($request))
			return false;
		logger('获取用户信息...');
		$this->setTicket($request);
		logger('设置用户登录信息完成...'."\n");
		return true;
	}
446221
public function isLoggedIn() {
        $hasUserData    = isset($this->_store->userData);
        $hasLoginMethod = isset($this->_store->method);
        $hasValidToken  = isset($this->_store->token) && $this->validateToken();
        $isLoggedIn     = $hasUserData && $hasLoginMethod && $hasValidToken;

        // Don't leave invalid cookies laying around.
        // Clear data only when data is present, but it is invalid.
        if ($hasUserData && $hasLoginMethod && !$hasValidToken) {
            $this->_store->userData = null;
            $this->_store->method   = null;
        }
        return $isLoggedIn;
    }
976102
public function login()
    {
        if ($this->validate()) {
            UserLoginHistory::createAsync(['user_id' => $this->user->getId(), 'ip' => Yii::$app->request->userIP]);
            return Yii::$app->user->login($this->user, $this->rememberMe ? Yii::$app->settings->get('rememberFor', 'user') : 0);
        } else {
            return false;
        }
    }
685160
public function login() {
        $state = Str::randomNumber(7);
        Factory::session()->set('state', $state);
        $this->set('state', $state);
        return $this->getLogin()->getUrl();
    }
136834
public function check()
	{
		if (is_null($this->user))
		{
			// Check session first, follow by cookie
			if ( ! $userArray = $this->session->get() and ! $userArray = $this->cookie->get())
			{
				return false;
			}

			// Now check our user is an array with two elements,
			// the username followed by the persist code
			if ( ! is_array($userArray) or count($userArray) !== 2)
			{
				return false;
			}

			list($id, $persistCode) = $userArray;

			// Let's find our user
			try
			{
				$user = $this->getUserProvider()->findById($id);
			}
			catch (UserNotFoundException $e)
			{
				return false;
			}

			// Great! Let's check the session's persist code
			// against the user. If it fails, somebody has tampered
			// with the cookie / session data and we're not allowing
			// a login
			if ( ! $user->checkPersistCode($persistCode))
			{
				return false;
			}

			// Now we'll set the user property on Sentry
			$this->user = $user;
		}

		// Let's check our cached user is indeed activated
		if ( ! $user = $this->getUser() or ! $user->isActivated())
		{
			return false;
		}
		// If throttling is enabled we check it's status
		if( $this->getThrottleProvider()->isEnabled())
		{
			// Check the throttle status
			$throttle = $this->getThrottleProvider()->findByUser( $user );

			if( $throttle->isBanned() or $throttle->isSuspended())
			{
				$this->logout();
				return false;
			}
		}

		return true;
	}
1016664
public function getLoggedUser() {
		$session = BUsersSession::getInstanceAndStart();
		if (empty($session)) {
			return NULL;
		}
		return $this->itemGet($session->userid);
	}
630088
public function isLoggedIn()
    {
        $response = $this->client->get($this->uri());

        try {
            $body = $this->handleResponse($response)->getDecodedData();
        } catch (ClientException $exception) {
            return false;
        }

        return property_exists(
            $body,
            'user'
        );
    }
46397
public function login()
    {
        if ($this->validate()) {
            $user = $this->getUser();
            $user->detachBehavior('LogBehavior');
            
            // update user model
            $user->updateAttributes([
                'force_reload' => false,
                'login_attempt' => 0,
                'login_attempt_lock_expiration' => null,
                'auth_token' => Yii::$app->security->hashData(Yii::$app->security->generateRandomString(), $user->password_salt),
            ]);
            
            // kill prev user logins
            UserLogin::updateAll(['is_destroyed' => true], ['user_id' => $user->id]);
            
            // create new user login
            $login = new UserLogin([
                'auth_token' => $user->auth_token,
                'user_id' => $user->id,
                'is_destroyed' => false,
            ]);
            $login->save();
            
            // refresh user online list
            UserOnline::refreshUser($user, 'login');
            return $user;
        }
        
        return false;
    }
392915
public function userInfo()
    {
        $this->startBrokerSession();
        $user = null;

        $username = $this->getSessionData('sso_user');

        if ($username) {
            $user = $this->getUserInfo($username);
            if (!$user) return $this->fail("User not found", 500); // Shouldn't happen
        }

        header('Content-type: application/json; charset=UTF-8');
        echo json_encode($user);
    }
1054543
protected function loginWithCookie()
    {
        $username = $this->request->getCookie('login.username');
        $password = $this->request->getCookie('login.password');

        //Checks if the cookies exist
        if (!$username || !$password) {
            return;
        }

        //Tries to login
        $this->request = $this->request->withParsedBody(compact('username', 'password'));
        $user = $this->Auth->identify();
        if (!$user || !$user['active'] || $user['banned']) {
            return $this->buildLogout();
        }

        $this->Auth->setUser($user);
        $this->LoginRecorder->setConfig('user', $user['id'])->write();

        return $this->redirect($this->Auth->redirectUrl());
    }
768776
public function initSession ()
	{
		
		// Get session
		
		$session	= $this->getSessionData ();
		
		// Check session is valid
		
		if ($this->checkSession ($session) !== TRUE)
		{
			return $this->Logout ('invalid_session');
		}
		
		// Load user from session
		
		$this->fromSessionData ();
		
		// Read user

		if (!$this->Read ())
		{
			return $this->Logout ('user_read_error');
		}
		
		// Reset password
		
		$this->reset ('password');
		
		// If the user is not active or the active status has changed
		
		if ($session['active'] != $this->iget ('active') || !$this->iget ('active'))
		{
			return $this->Logout ('inactive');
		}
		
		// Check if the session has timed out
		
		if ($this->session ()->timedOut ($session['last_action']))
		{
			return $this->Logout ('timeout');
		}
		
		// Update action time
		
		$this->updateLastAction ();
		
		// Set login status
		
		$this->loggedIn	= TRUE;
		
		// Redirect to originally requested URL
		
		if ($this->session ()->get ('requested_url'))
		{
			$url = $this->session ()->get ('requested_url');
			$this->session ()->set ('requested_url', FALSE);
			new Redirect ($url);
		}
		
		// return TRUE
		
		return TRUE;
		
	}
1349275
public function login()
    {
        if ($this->validate() && $this->user) {
            $isLogged = Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0);

            if ($isLogged) {
                $this->user->updateAttributes(['last_login_at' => time()]);
            }

            return $isLogged;
        }

        return false;
    }
447418
protected function _hasSession()
    {
        return !ini_get('session.use_cookies')
            || isset($_COOKIE[session_name()])
            || $this->_isCLI
            || (ini_get('session.use_trans_sid') && isset($_GET[session_name()]));
    }
1038900
public function login()
    {
        $_SESSION['auth'] = 'login';

        if ($this->userStore->find()->count() === 0) {
            return $this->redirect('/setup');
        }

        Event::trigger('beforeLogin', $this);

        if ($this->request->getMethod() == 'POST') {
            $user = Store::get('User')->getByEmail($this->getParam('email'));

            if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
                $_SESSION['user_id'] = $user->getId();

                $url = $this->config->get('site.full_admin_url');

                if (isset($_SESSION['previous_url'])) {
                    $url = $_SESSION['previous_url'];
                }

                return $this->redirect($url);
            } else {
                Event::trigger('loginFailed', $this->view);
                $this->template->errorMessage = 'Your email address or password were incorrect.';
            }
        }
    }
558795
public function isActualSidInCookie()
    {
        return isset($_COOKIE[$this->getName()]) && ($_COOKIE[$this->getName()] == $this->getId());
    }
382670
public function loginAction()
    {
        $request = $this->getRequest();
        $session = $request->getSession();
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
            $session->remove(SecurityContext::AUTHENTICATION_ERROR);
        }

        $view = $this
            ->view()
            ->setTemplate($this->config->getTemplate('login.html'))
            ->setTemplateVar($this->config->getPluralResourceName())
            ->setData(array(
                'last_username' => $session->get(SecurityContext::LAST_USERNAME),
                'error'         => $error
            ));

        return $this->handleView($view);
    }
926566
private function _retrieve_session(){
    if ( !$this->id ){
      // The user ID must be in the session
      $id_session = $this->get_id_session();
      $id = $this->get_session('id');
      if ( $id_session && $id ){
        $this->_sess_info($id_session);
        if (
          isset($this->sess_cfg['fingerprint']) &&
          ($this->get_print($this->_get_session('fingerprint')) === $this->sess_cfg['fingerprint'])
        ){
          $this
            ->_authenticate($id)
            ->_user_info()
            ->_init_dir()
            ->save_session();
        }
        else{
          $this->set_error(19);
        }
      }
      else{
        //$this->set_error(15);
      }
    }
    return $this;
  }