将用户写入到Session
{@inheritDoc}
@see \asbamboo\security\user\token\UserTokenInterface::setUser()
428443
public function setUser(UserInterface $user): UserTokenInterface
    {
        $serialize_user = serialize($user);

        $this->Session->set($this->session_key, $serialize_user);

        return $this;
    }
218434
public function setUser(\WobbleCode\UserBundle\Document\User $user)
    {
        $this->user = $user;

        return $this;
    }
1091744
public function setUser(\Amulen\UserBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }
926007
def set_user(self, user):
        
        self.session['user_id'] = user.key
        self.session['user_data'] = user.clean_value()
        role = self.get_role()
        # TODO: this should be remembered from previous login
        # self.session['role_data'] = default_role.clean_value()
        self.session['role_id'] = role.key
        self.current.role_id = role.key
        self.current.user_id = user.key
        # self.perm_cache = PermissionCache(role.key)
        self.session['permissions'] = role.get_permissions()
270938
public function update_token($username) {
        $token = self::hash();

        $query = sprintf(self::UPDATE_VALUE,
            $this->params['table'],
            $this->params['token'],
            $this->pdo->quote($token),
            $this->params['username'],
            $this->pdo->quote($username));

        $stmt = $this->pdo->query($query);

        if($stmt === FALSE || $stmt->rowCount() !== 1) {
            throw new UserException('Token not found');
        }

        return $token;
    }
283118
public function setUser(User $user)
    {
        // Check if user is currently active one
        $isCurrent = ($user->getId() === $this->getMainUser()->getId());
        // Switch identity
        $this->getUser()->switchIdentity($user->identity);
        if (!$isCurrent) {
            Yii::$app->getSession()->set('main_user', $this->getMainUser()->getId());
        } else {
            Yii::$app->getSession()->remove('main_user');
        }
    }
11813
public function getUser(): UserInterface
    {
        $serialize_user     = $this->Session->get($this->session_key);
        if($serialize_user){
            $user           = unserialize($serialize_user);
        }else{
            // 如果用户没有登录，session标记为未登录用户
            $user           = new AnonymousUser($this->anonymous_name);
            $this->setUser($user);
        }
        return $user;
    }
73800
public function setUser(array $user)
    {
        if (in_array('user', $this->persistantMap)) {
            $this->store->set('user', $user);
        }

        $this->user = $user;
        return $this;
    }
421324
protected function setUser(array $userData, & $user = null)
    {
        // Generic birthdate parsing
        $user->birthday = date('Y-m-d H:i:s', strtotime($user->birthday));

        // If no external user is passed set as current user
        if (isset($user)) {
            $this->user = & $user;
        }
    }
1360552
public void setUser(String user)
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "setUser", user);

    this.user = user;

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "setUser");
  }
725227
public function setAuth($user, $pass)
    {
        $this->user = (string) $user;
        $this->pass = (string) $pass;

        return $this->hasAuth();
    }
314156
public function initSessionByUserToken($userToken) {
      $response = $this->request('get', 'initSession', ['headers' => ['Authorization' => "user_token $userToken"]]);
      if ($response->getStatusCode() != 200
         || !$this->sessionToken = json_decode($response->getBody()->getContents(), true)['session_token']) {
         $body = json_decode($response->getBody()->getContents());
         throw new Exception(ErrorHandler::getMessage($body[0]));
      }
      return true;
   }
130949
public static function set_user(\stdClass $user) {
        global $ADMIN;
        $GLOBALS['USER'] = $user;
        unset($GLOBALS['USER']->description); // Conserve memory.
        unset($GLOBALS['USER']->password);    // Improve security.
        if (isset($GLOBALS['USER']->lang)) {
            // Make sure it is a valid lang pack name.
            $GLOBALS['USER']->lang = clean_param($GLOBALS['USER']->lang, PARAM_LANG);
        }

        // Relink session with global $USER just in case it got unlinked somehow.
        $_SESSION['USER'] =& $GLOBALS['USER'];

        // Nullify the $ADMIN tree global. If we're changing users, then this is now stale and must be generated again if needed.
        $ADMIN = null;

        // Init session key.
        sesskey();
    }
342600
public function setUser(\Dacorp\ExtraBundle\Entity\User $user = null)
    {
        $this->user = $user;
    
        return $this;
    }
203915
public function setUserValue(string $value) : self
    {
        $this->user_value = $value;
        $this->is_valid = null;
        return $this;
    }
409656
public function setUserAndGroup()
    {
        // Get uid.
        $user_info = posix_getpwnam($this->user);
        if (!$user_info) {
            static::log("Warning: User {$this->user} not exsits");
            return;
        }
        $uid = $user_info['uid'];
        // Get gid.
        if ($this->group) {
            $group_info = posix_getgrnam($this->group);
            if (!$group_info) {
                static::log("Warning: Group {$this->group} not exsits");
                return;
            }
            $gid = $group_info['gid'];
        } else {
            $gid = $user_info['gid'];
        }

        // Set uid and gid.
        if ($uid != posix_getuid() || $gid != posix_getgid()) {
            if (!posix_setgid($gid) || !posix_initgroups($user_info['name'], $gid) || !posix_setuid($uid)) {
                static::log("Warning: change gid or uid fail.");
            }
        }
    }
741090
protected function setUserFromSession()
    {
        $id = $this->session->get();

        if ($id) {
            $user = $this->repository->getById($this->session->get());
            if ($user instanceof UserInterface) {
                $this->admitUser($user);
                return;
            }
        }

        $this->currentUser = new GuestUser();
    }