Save the user in the session.

@param array $user

@return bool
551893
protected static function save_session()
    {
        $saved = [];

        $user = (array) static::$user;

        foreach ($user as $key => $value) {
            if (in_array($key, static::$saved)) {
                $saved[$key] = $value;
            }
        }

        $name = static::resource('session');

        Session::put($name, $saved, config('auth.cookie_lifetime'));

        return true;
    }
255049
public function updateUser(UserInterface $user)
    {
        $user->setChangedValue();
        $this->em->persist($user);
        $this->em->flush();
        return true;
    }
741184
public function isGrantedTo($user): bool
    {
        $userModel = config('auth.providers.users.model');

        if (is_int($user) && !$userModel::find($user)) {
            return false;
        }

        return $this->users()->where('user_id', is_int($user) ? $user : $user->id)->exists();
    }
130121
public function attachUser( $user )
  {
    if( is_object($user))
      $user = $user->getKey();

    if( is_array($user))
      $user = $user['id'];

    $this->users()->attach( $user );
  }
577524
public function persist(UserInterface $user)
    {
        $session = new PersistentSession();
        $session->email = $this->email;
        $session->series = $this->hash($this->series);
        $session->token = $this->hash($this->token);
        $session->user_id = $user->id();
        $session->two_factor_verified = $user->isTwoFactorVerified();

        try {
            $session->save();
        } catch (\Exception $e) {
            throw new \Exception("Unable to save persistent session for user # {$user->id()}: ".$e->getMessage());
        }

        return $session;
    }
712289
protected function doSet(Array $arr)
    {
        foreach ($arr as $name => $data) {
            $this->save($name, $data);
        }

        return true;
    }
30632
public function saveUser($user)
    {

        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        if (is_null($user->created)) {
            $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' .
                   'lti_user_id, lti_result_sourcedid, created, updated) ' .
                   'VALUES (:rlid, :uid, :sourcedid, :created, :updated)';
            $query = $this->db->prepare($sql);
            $query->bindValue('rlid', $user->getResourceLink()->getRecordId(), PDO::PARAM_INT);
            $query->bindValue('uid', $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY), PDO::PARAM_STR);
            $query->bindValue('sourcedid', $user->ltiResultSourcedId, PDO::PARAM_STR);
            $query->bindValue('created', $now, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
        } else {
            $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
                   'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
                   'WHERE (user_pk = :id)';
            $query = $this->db->prepare($sql);
            $query->bindValue('sourcedid', $user->ltiResultSourcedId, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('id', $user->getRecordId(), PDO::PARAM_INT);
        }
        $ok = $query->execute();
        if ($ok) {
            if (is_null($user->created)) {
                $user->setRecordId(intval($this->db->lastInsertId()));
                $user->created = $time;
            }
            $user->updated = $time;
        }

        return $ok;

    }
329159
protected function mapUserToObject(array $user)
    {
        return new User([
            'id' => $this->arrayItem($user, 'open_id'),
            'nickname' => $this->arrayItem($user, 'nick'),
            'name' => $this->arrayItem($user, 'nick'),
            'avatar' => $this->arrayItem($user, 'avatar'),
        ]);
    }
762632
public function save():bool
    {
        $_SESSION = $this->session;
        return (0 === count(array_diff($this->session, $_SESSION)))? true : false;
    }
794589
public function saveSession($user_id = null, $provider = [])
    {
        if (empty($user_id)) {
            $user_id = activeUser('id');
        }

        if (empty($user_id)) {
            $this->setError('Must specify which user ID\'s session to save.');
            return false;
        }

        $oUser = $this->oUserModel->getById($user_id);

        if (!$oUser) {
            $this->setError('Invalid User ID');
            return false;
        }

        // --------------------------------------------------------------------------

        if (!is_array($provider)) {

            $_provider = (array) $provider;
            $_provider = array_unique($_provider);
            $_provider = array_filter($_provider);

        } else {

            $_provider = $provider;
        }

        // --------------------------------------------------------------------------

        $_session     = $this->oHybridAuth->getSessionData();
        $_session     = unserialize($_session);
        $_save        = [];
        $_identifiers = [];

        //  Now we sort the session into individual providers
        foreach ($_session as $key => $value) {

            //  Get the bits
            list($hauth, $provider) = explode('.', $key, 3);

            if (!isset($_save[$provider])) {
                $_save[$provider] = [];
            }

            $_save[$provider][$key] = $value;
        }

        // --------------------------------------------------------------------------

        //  Prune any which aren't worth saving
        foreach ($_save as $provider => $values) {

            //  Are we only interested in a particular provider?
            if (!empty($_provider)) {

                if (array_search($provider, $_provider) === false) {
                    unset($_save[$provider]);
                    continue;
                }
            }

            //  Connected?
            if (!$this->isConnectedWith($provider)) {
                unset($_save[$provider]);
                continue;
            }

            //  Got an identifier?
            try {

                $oAdapter = $this->oHybridAuth->getAdapter($provider);
                $oProfile = $oAdapter->getUserProfile();

                if (!empty($oProfile->identifier)) {
                    $_identifiers[$provider] = $oProfile->identifier;
                }

            } catch (\Exception $e) {
                unset($_save[$provider]);
                continue;
            }
        }

        // --------------------------------------------------------------------------

        /**
         * Get the user's existing data, so we know whether we're inserting or
         * updating their data
         */

        $this->oDb->where('user_id', $user_id);
        $aExisting = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->result();
        $aExists   = [];

        foreach ($aExisting as $existing) {
            $aExists[$existing->provider] = $existing->id;
        }

        // --------------------------------------------------------------------------

        //  Save data
        $this->oDb->trans_begin();

        $oNow = Factory::factory('DateTime');

        foreach ($_save as $provider => $keys) {

            if (isset($aExists[$provider])) {

                //  Update
                $aData = [
                    'identifier'   => $_identifiers[$provider],
                    'session_data' => serialize($keys),
                    'modified'     => $oNow->format('Y-m-d H:i{s'),
                ];

                $this->oDb->set($aData);
                $this->oDb->where('id', $aExists[$provider]);
                $this->oDb->update(NAILS_DB_PREFIX . 'user_social');

            } else {

                //  Insert
                $aData = [
                    'user_id'      => (int) $user_id,
                    'provider'     => $provider,
                    'identifier'   => $_identifiers[$provider],
                    'session_data' => serialize($keys),
                    'created'      => $oNow->format('Y-m-d H:i:s'),
                    'modified'     => $oNow->format('Y-m-d H:i:s'),
                ];

                $this->oDb->set($aData);
                $this->oDb->insert(NAILS_DB_PREFIX . 'user_social');
            }
        }

        // --------------------------------------------------------------------------

        if ($this->oDb->trans_status() === false) {
            $this->oDb->trans_rollback();
            return false;
        } else {
            $this->oDb->trans_commit();
            return true;
        }
    }
1267750
protected function getUserSessionId($user)
    {
        $model = $this->getUserModel();
        
        if ($user instanceof $model) {
            return array_get($this->users, $user->getKey(), false);
        } elseif ($model::find($user) !== null) {
            return array_get($this->users, $user, false);
        }
        
        return false;
    }
978313
public function initSessionByCredentials($user, $password) {
      $response = $this->request('get', 'initSession', ['auth' => [$user, $password]]);
      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;
   }
258031
public function setSaveHandler()
    {
        session_module_name( 'user' );
        session_set_save_handler(
            array( $this, 'open' ),
            array( $this, 'close' ),
            array( $this, 'read' ),
            array( $this, 'write' ),
            array( $this, 'destroy' ),
            array( $this, 'gc' )
            );
        return true;
    }
1046367
protected function verifiedEmail($user)
    {
        $this->guard()->login($user);

        if(!$user->verified) {
            $user->forceFill([
                'verified' => true
            ])->save();
            return true;
        }

        return false;
    }
467138
public function persist($user): void
    {
        $this->om->persist($user);
        $this->om->flush();
    }
963543
public function chown($user) {

		if(false !== $this -> file -> getExists()) {
			return @chown($this -> file -> getBasepath(), $user);
		}

		return false;
	}
562577
public static function setUserInfo($user)
    {
        if (!empty($user)) {
            \Session::put('user.id', array_get($user, 'id'));
            \Session::put('user.name', array_get($user, 'name'));
            \Session::put('user.username', array_get($user, 'username'));
            \Session::put('user.display_name', array_get($user, 'name'));
            \Session::put('user.first_name', array_get($user, 'first_name'));
            \Session::put('user.last_name', array_get($user, 'last_name'));
            \Session::put('user.email', array_get($user, 'email'));
            \Session::put('user.is_sys_admin', array_get($user, 'is_sys_admin'));
            \Session::put('user.last_login_date', array_get($user, 'last_login_date'));
            \Session::put('user.ldap_username', array_get($user, 'ldap_username'));

            return true;
        }

        return false;
    }