Persists a user as currentUser to localStorage, and into the singleton.
@private
3338
function(user) {
        var promise;
        if (AV.User._currentUser !== user) {
          promise = AV.User.logOut();
        } else {
          promise = Promise.resolve();
        }
        return promise.then(function() {
          user._isCurrentUser = true;
          AV.User._currentUser = user;

          var json = user._toFullJSON();
          json._id = user.id;
          json._sessionToken = user._sessionToken;
          return AV.localStorage
            .setItemAsync(
              AV._getAVPath(AV.User._CURRENT_USER_KEY),
              JSON.stringify(json)
            )
            .then(function() {
              AV.User._currentUserMatchesDisk = true;
              return AV._refreshSubscriptionId();
            });
        });
      }
563049
function Store() {
	this.cache = new LocalStash(30);
	this.ttl = getTTL();

	this._forward = function () {
		logger.error('No forwarder defined');
	};

	logger.verbose('Messages will expire after', this.ttl, 'seconds.');
}
983510
function load() {
      var key, data, value, pos = 0;

      items = {};

      // localStorage can be disabled on WebKit/Gecko so make a dummy storage
      if (!hasOldIEDataSupport) {
        return;
      }

      function next(end) {
        var value, nextPos;

        nextPos = end !== undefined ? pos + end : data.indexOf(',', pos);
        if (nextPos === -1 || nextPos > data.length) {
          return null;
        }

        value = data.substring(pos, nextPos);
        pos = nextPos + 1;

        return value;
      }

      storageElm.load(userDataKey);
      data = storageElm.getAttribute(userDataKey) || '';

      do {
        var offset = next();
        if (offset === null) {
          break;
        }

        key = next(parseInt(offset, 32) || 0);
        if (key !== null) {
          offset = next();
          if (offset === null) {
            break;
          }

          value = next(parseInt(offset, 32) || 0);

          if (key) {
            items[key] = value;
          }
        }
      } while (key !== null);

      updateKeys();
    }
895359
def createSessionForKey(self, key, user):
        
        PersistentSession(
            store=self.store,
            sessionKey=key,
            authenticatedAs=user)
65146
function() {
        var user = userStore.getUser();
        if (user) {
          $rootScope.user = user;
          authLogger.log('AuthService.withUser()', user);
          return $q.when(user);
        } else {
          authLogger.log('AuthService.withUser(), calling startLogin()');
          return this.startLogin();
        }
      }
669910
function() {
        if (AV._config.disableCurrentUser) {
          console.warn(
            'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'
          );
          return Promise.resolve(null);
        }

        if (AV.User._currentUser) {
          return Promise.resolve(AV.User._currentUser);
        }

        if (AV.User._currentUserMatchesDisk) {
          return Promise.resolve(AV.User._currentUser);
        }

        return AV.localStorage
          .getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))
          .then(function(userData) {
            if (!userData) {
              return null;
            }

            // Load the user from local storage.
            AV.User._currentUserMatchesDisk = true;

            AV.User._currentUser = AV.Object._create('_User');
            AV.User._currentUser._isCurrentUser = true;

            var json = JSON.parse(userData);
            AV.User._currentUser.id = json._id;
            delete json._id;
            AV.User._currentUser._sessionToken = json._sessionToken;
            delete json._sessionToken;
            AV.User._currentUser._finishFetch(json);
            //AV.User._currentUser.set(json);

            AV.User._currentUser._synchronizeAllAuthData();
            AV.User._currentUser._refreshCache();
            AV.User._currentUser._opSetQueue = [{}];
            return AV.User._currentUser;
          });
      }
735592
function(){
      if(window.localStorage){
        localStorage.clear();
      } else {
        var _splice, cookies;
        // Read for session cookie
        document.cookie = 'cloudmineTodoSession=none; expires=' + new Date(0).toUTCString() + '; path=/';
      }

      // Reset everything
      $('#todo').empty().hide();
      $('#todo_header, #new').hide();
      $('#login, #or, #register_button').show();
      $('#login_button').val('Login').show();
      $('#register_button').val('Register').show();
      $('#login_email, #login_password').val('');
      $('#login_email').focus();
      $('#priority_buttons').html('Priority:');
    }
279756
function ClientStorage(driver) {
  this._data = {};
  if (navigator.cookieEnabled) {
    this.cookies = new __Cookies(document.cookie);
  } else {
    this.cookies = false;
  }

  switch (driver) {
  case 'localStorage':
    if (this.LSSupport) {
      this.ls = window.localStorage || localStorage;
    } else {
      console.warn('ClientStorage is set to "localStorage", but it is not supported on this browser');
    }
    break;
  case 'cookies':
    if (this.cookies) {
      this.LSSupport = false;
      this.ls        = null;
    } else {
      console.warn('ClientStorage is set to "cookies", but Cookies is disabled on this browser');
    }
    break;
  case 'js':
    this.cookies   = false;
    this.LSSupport = false;
    this.ls        = null;
    break;
  default:
    if (this.LSSupport) {
      this.ls = window.localStorage || localStorage;
    } else {
      this.ls = null;
    }
    break;
  }
}
1232250
function session() {
  return async function passportSession(ctx, next) {
    const req = ctx.req;
    let sessionUser;
    if (req._passport.session) {
      sessionUser = req._passport.session.user;
    }

    if (sessionUser || sessionUser === 0) {
      const user = await ctx.app.passport.deserializeUser(ctx, sessionUser);
      if (!user) {
        req._passport.session.user = undefined;
      } else {
        req[ctx.app.passport._userProperty] = user;
      }
    }

    return next();
  };
}
17433
public void setCurrentUser( BackendlessUser user )
  {
    if( currentUser == null )
      currentUser = user;
    else
      currentUser.setProperties( user.getProperties() );
  }
335479
function(persist) {
          /**
          * is Persistant or not
          * @property {boolean} isPersisted Persistant property
          * @memberof AbstractLocalStorage
          */
          this.isPersisted = persist;

          this.myStore = null;
          /**
          * Is storage supported
          * @method isSupported
          * @memberof AbstractLocalStorage
          * @returns {boolean} Returns true if supported
          */
          this.isSupported = function() {
            return (typeof (Storage) !== "undefined");
          };

          // true = localStorage, false = sessionStorage
          if (this.isSupported()) {
            //logger.debug("AUGMENTED: localStorage exists");

            if (this.isPersisted) {
              this.myStore = localStorage;
            } else {
              this.myStore = sessionStorage;
            }
          } else {
            logger.warn("AUGMENTED: No localStorage.");
          }

          /**
          * Gets an item from storage
          * @method getItem
          * @memberof AbstractLocalStorage
          * @param {string} key The key in storage
          * @returns {object} Returns object from storage
          */
          this.getItem = function(itemKey) {
            var item = this.myStore.getItem(itemKey);
            if (item) {
              return JSON.parse(item);
            }
            return null;
          };

          /**
          * Sets an item to storage
          * @method setItem
          * @memberof AbstractLocalStorage
          * @param {string} key The key in storage
          * @param {object} object The data to set
          */
          this.setItem = function(itemKey, object) {
            this.myStore.setItem(itemKey, JSON.stringify(object));
          };

          /**
          * Removes an item from storage
          * @method removeItem
          * @memberof AbstractLocalStorage
          * @param {string} key The key in storage
          */
          this.removeItem = function(itemKey) {
            this.myStore.removeItem(itemKey);
          };

          /**
          * Clears storage - <b>Warning: Destructive in non-namespaced instances!</b>
          * @method clear
          * @memberof AbstractLocalStorage
          */
          this.clear = function() {
            this.myStore.clear();
          };

          /**
          * Gets the key from storage for index
          * @method key
          * @memberof AbstractLocalStorage
          * @param {number} i The index in storage
          * @returns {string} Returns the key from storage
          */
          this.key = function(i) {
            return this.myStore.key(i);
          };

          /**
          * The length of storage by keys
          * @method length
          * @memberof AbstractLocalStorage
          * @returns {number} Returns the length of storage by keys
          */
          this.length = function() {
            return this.myStore.length;
          };
        }
353281
function Persist(cacheFile, keys, log) {
  var pdata = (cacheFile) ? JSON.parse(fs.readFileSync(cacheFile, 'utf8')) : {}
    , guid = makeGuid(keys);

  pdata[guid] = pdata[guid] || {};

  // this is the only member that needs access to the full object and the file
  this.save = function () {
    if (cacheFile) {
      fs.writeFileSync(cacheFile, JSON.stringify(pdata));
    }
  };

  // members need only know their config object
  this.cfg = pdata[guid];
  this.cfg.opts = this.cfg.opts || {};

  // was a logger passed down?
  this.log = (type.isFunction(log)) ? log : noop;
}
148475
function setUserData(userData) {

   let u = getUserData();
   if (u.coreSessionToken && userData.coreSessionToken) {
      // only store the newer one 
      let coreSessionToken = null;
      if (u.coreSessionToken.timestamp < userData.coreSessionToken.timestamp) {
         coreSessionToken = userData.coreSessionToken;
      }
      else {
         coreSessionToken = u.coreSessionToken;
      }
      userData.coreSessionToken = coreSessionToken;
   }
   
   localStorage.setItem(LOCAL_STORAGE_ID, JSON.stringify(userData));
}
1019646
def persist(self, storageLevel):
        
        if not isinstance(storageLevel, StorageLevel):
            raise TypeError("`storageLevel` should be a StorageLevel, got %s" % type(storageLevel))
        javaStorageLevel = self._java_matrix_wrapper._sc._getJavaStorageLevel(storageLevel)
        self._java_matrix_wrapper.call("persist", javaStorageLevel)
        return self
502541
function(properties) {
  if (this instanceof User) {
    for (var property in (properties || {})) {
      if (Array.prototype.hasOwnProperty.call(properties, property)) {
        this[property] = properties[property];
      }
    }
  }
  else {
   return(new User(properties));
  }
}
1310589
function storageInitialize() {
    var sessionStorage;
    /**
     * sessionStorage throws error when cookies are disabled
     * Chrome content settings when running the site in a Facebook IFrame.
     * see: https://github.com/devote/HTML5-History-API/issues/34
     * and: http://stackoverflow.com/a/12976988/669360
     */
    try {
      sessionStorage = global['sessionStorage'];
      sessionStorage.setItem(sessionStorageKey + 't', '1');
      sessionStorage.removeItem(sessionStorageKey + 't');
    } catch(_e_) {
      sessionStorage = {
        getItem: function(key) {
          var cookie = document.cookie.split(key + "=");
          return cookie.length > 1 && cookie.pop().split(";").shift() || 'null';
        },
        setItem: function(key, value) {
          var state = {};
          // insert one current element to cookie
          if (state[windowLocation.href] = historyObject.state) {
            document.cookie = key + '=' + JSON.stringify(state);
          }
        }
      }
    }

    try {
      // get cache from the storage in browser
      stateStorage = JSON.parse(sessionStorage.getItem(sessionStorageKey)) || {};
    } catch(_e_) {
      stateStorage = {};
    }

    // hang up the event handler to event unload page
    addEvent(eventNamePrefix + 'unload', function() {
      // save current state's object
      sessionStorage.setItem(sessionStorageKey, JSON.stringify(stateStorage));
    }, false);
  }
586580
function() {
      if (Parse.User._currentUser !== null) {
        Parse.User._currentUser._logOutWithAll();
        Parse.User._currentUser._isCurrentUser = false;
      }
      Parse.User._currentUserMatchesDisk = true;
      Parse.User._currentUser = null;
      Parse.localStorage.removeItem(
          Parse._getParsePath(Parse.User._CURRENT_USER_KEY));
    }